PluginProbe ʕ •ᴥ•ʔ
VikAppointments Services Booking Calendar / 1.2.20
VikAppointments Services Booking Calendar v1.2.20
1.2.21 1.2.20 trunk 1.2.17 1.2.18 1.2.19
vikappointments / site / helpers / libraries / cron / formfieldconstraints.php
vikappointments / site / helpers / libraries / cron Last commit date
overrides 1 month ago core.php 1 month ago dispatcher.php 1 month ago formbuilder.php 1 month ago formfield.php 1 month ago formfieldconstraints.php 1 month ago index.html 1 month ago job.php 1 month ago response.php 1 month ago
formfieldconstraints.php
133 lines
1 <?php
2 /**
3 * @package VikAppointments
4 * @subpackage core
5 * @author E4J s.r.l.
6 * @copyright Copyright (C) 2021 E4J s.r.l. All Rights Reserved.
7 * @license http://www.gnu.org/licenses/gpl-2.0.html GNU/GPL
8 * @link https://vikwp.com
9 */
10
11 // No direct access
12 defined('ABSPATH') or die('No script kiddies please!');
13
14 /**
15 * Class used to wrap all the constraints (attributes and properties) of an input field.
16 *
17 * @since 1.5
18 * @since 1.7 Renamed from CronFormFieldConstraints.
19 */
20 class VAPCronFormFieldConstraints implements IteratorAggregate
21 {
22 /**
23 * The list containing all the attributes of the field.
24 *
25 * @var array
26 */
27 private $attributes;
28
29 /**
30 * The construct of the cron form field constraints to
31 * initialize the required parameters of this object.
32 *
33 * @param array $attributes The field attributes.
34 *
35 * @uses setAttributes()
36 */
37 public function __construct(array $attributes = array())
38 {
39 $this->setAttributes($attributes);
40 }
41
42 /**
43 * Set all the attributes in the list.
44 *
45 * @param array $attributes The attributes to restrict a field.
46 * The key of a row will be used as attribute
47 * and the content will be used as value.
48 *
49 * @return self Returns this object to support chaining.
50 */
51 public function setAttributes($attributes)
52 {
53 if (is_array($attributes) && count(array_keys($attributes)) > 0)
54 {
55 $this->attributes = $attributes;
56 }
57 }
58
59 /**
60 * Returns the associative array containing all the attributes of this object.
61 *
62 * @return array The array containing the attributes.
63 */
64 public function getAttributes()
65 {
66 return $this->attributes;
67 }
68
69 /**
70 * Insert a new attribute in the constraints list.
71 *
72 * @param string $key The standard name of the attribute.
73 * @param string $val An acceptable value of the attribute.
74 * @param string $separator The separator to use if the setting
75 * is not empty. Null to overwrite always.
76 *
77 *
78 * @return self Returns this object to support chaining.
79 */
80 public function add($key, $val, $separator = null)
81 {
82 if ($separator === null || empty($this->attributes[$key]))
83 {
84 $this->attributes[$key] = $val;
85 }
86 else
87 {
88 $this->attributes[$key] .= $separator . $val;
89 }
90
91 return $this;
92 }
93
94 /**
95 * Returns the value of the specified attribute.
96 * Returns the default value if the attribute doesn't exist.
97 *
98 * @param string $key The standard name of the attribute.
99 * @param mixed $def The default value to use.
100 *
101 * @return mixed The value of the attribute.
102 */
103 public function get($key, $def = false)
104 {
105 if (array_key_exists($key, $this->attributes))
106 {
107 return $this->attributes[$key];
108 }
109
110 return $def;
111 }
112
113 /**
114 * Creates an array iterator for ease of use.
115 *
116 * @return ArrayIterator
117 *
118 * @since 1.7
119 */
120 #[ReturnTypeWillChange]
121 public function getIterator()
122 {
123 return new ArrayIterator($this->getAttributes());
124 }
125 }
126
127 /**
128 * Register a class alias for backward compatibility.
129 *
130 * @deprecated 1.8
131 */
132 class_alias('VAPCronFormFieldConstraints', 'CronFormFieldConstraints');
133