@@ -26,19 +26,19 @@ discard block |
||
26 | 26 | */ |
27 | 27 | trait Traits_Optionable |
28 | 28 | { |
29 | - /** |
|
30 | - * @var array |
|
31 | - */ |
|
29 | + /** |
|
30 | + * @var array |
|
31 | + */ |
|
32 | 32 | protected $options; |
33 | 33 | |
34 | - /** |
|
35 | - * Sets an option to the specified value. This can be any |
|
36 | - * kind of variable type, including objects, as needed. |
|
37 | - * |
|
38 | - * @param string $name |
|
39 | - * @param mixed $default |
|
40 | - * @return mixed |
|
41 | - */ |
|
34 | + /** |
|
35 | + * Sets an option to the specified value. This can be any |
|
36 | + * kind of variable type, including objects, as needed. |
|
37 | + * |
|
38 | + * @param string $name |
|
39 | + * @param mixed $default |
|
40 | + * @return mixed |
|
41 | + */ |
|
42 | 42 | public function setOption(string $name, $value) : Interface_Optionable |
43 | 43 | { |
44 | 44 | if(!isset($this->options)) { |
@@ -49,13 +49,13 @@ discard block |
||
49 | 49 | return $this; |
50 | 50 | } |
51 | 51 | |
52 | - /** |
|
53 | - * Sets a collection of options at once, from an |
|
54 | - * associative array. |
|
55 | - * |
|
56 | - * @param array $options |
|
57 | - * @return Interface_Optionable |
|
58 | - */ |
|
52 | + /** |
|
53 | + * Sets a collection of options at once, from an |
|
54 | + * associative array. |
|
55 | + * |
|
56 | + * @param array $options |
|
57 | + * @return Interface_Optionable |
|
58 | + */ |
|
59 | 59 | public function setOptions(array $options) : Interface_Optionable |
60 | 60 | { |
61 | 61 | foreach($options as $name => $value) { |
@@ -65,16 +65,16 @@ discard block |
||
65 | 65 | return $this; |
66 | 66 | } |
67 | 67 | |
68 | - /** |
|
69 | - * Retrieves an option's value. |
|
70 | - * |
|
71 | - * NOTE: Use the specialized type getters to ensure an option |
|
72 | - * contains the expected type (for ex. getArrayOption()). |
|
73 | - * |
|
74 | - * @param string $name |
|
75 | - * @param mixed $default The default value to return if the option does not exist. |
|
76 | - * @return mixed |
|
77 | - */ |
|
68 | + /** |
|
69 | + * Retrieves an option's value. |
|
70 | + * |
|
71 | + * NOTE: Use the specialized type getters to ensure an option |
|
72 | + * contains the expected type (for ex. getArrayOption()). |
|
73 | + * |
|
74 | + * @param string $name |
|
75 | + * @param mixed $default The default value to return if the option does not exist. |
|
76 | + * @return mixed |
|
77 | + */ |
|
78 | 78 | public function getOption(string $name, $default=null) |
79 | 79 | { |
80 | 80 | if(!isset($this->options)) { |
@@ -88,16 +88,16 @@ discard block |
||
88 | 88 | return $default; |
89 | 89 | } |
90 | 90 | |
91 | - /** |
|
92 | - * Enforces that the option value is a string. Numbers are converted |
|
93 | - * to string, strings are passed through, and all other types will |
|
94 | - * return the default value. The default value is also returned if |
|
95 | - * the string is empty. |
|
96 | - * |
|
97 | - * @param string $name |
|
98 | - * @param string $default Used if the option does not exist, is invalid, or empty. |
|
99 | - * @return string |
|
100 | - */ |
|
91 | + /** |
|
92 | + * Enforces that the option value is a string. Numbers are converted |
|
93 | + * to string, strings are passed through, and all other types will |
|
94 | + * return the default value. The default value is also returned if |
|
95 | + * the string is empty. |
|
96 | + * |
|
97 | + * @param string $name |
|
98 | + * @param string $default Used if the option does not exist, is invalid, or empty. |
|
99 | + * @return string |
|
100 | + */ |
|
101 | 101 | public function getStringOption(string $name, string $default='') : string |
102 | 102 | { |
103 | 103 | $value = $this->getOption($name, false); |
@@ -109,15 +109,15 @@ discard block |
||
109 | 109 | return $default; |
110 | 110 | } |
111 | 111 | |
112 | - /** |
|
113 | - * Treats the option value as a boolean value: will return |
|
114 | - * true if the value actually is a boolean true. |
|
115 | - * |
|
116 | - * NOTE: boolean string representations are not accepted. |
|
117 | - * |
|
118 | - * @param string $name |
|
119 | - * @return bool |
|
120 | - */ |
|
112 | + /** |
|
113 | + * Treats the option value as a boolean value: will return |
|
114 | + * true if the value actually is a boolean true. |
|
115 | + * |
|
116 | + * NOTE: boolean string representations are not accepted. |
|
117 | + * |
|
118 | + * @param string $name |
|
119 | + * @return bool |
|
120 | + */ |
|
121 | 121 | public function getBoolOption(string $name, bool $default=false) : bool |
122 | 122 | { |
123 | 123 | if($this->getOption($name) === true) { |
@@ -127,15 +127,15 @@ discard block |
||
127 | 127 | return $default; |
128 | 128 | } |
129 | 129 | |
130 | - /** |
|
131 | - * Treats the option value as an integer value: will return |
|
132 | - * valid integer values (also from integer strings), or the |
|
133 | - * default value otherwise. |
|
134 | - * |
|
135 | - * @param string $name |
|
136 | - * @param int $default |
|
137 | - * @return int |
|
138 | - */ |
|
130 | + /** |
|
131 | + * Treats the option value as an integer value: will return |
|
132 | + * valid integer values (also from integer strings), or the |
|
133 | + * default value otherwise. |
|
134 | + * |
|
135 | + * @param string $name |
|
136 | + * @param int $default |
|
137 | + * @return int |
|
138 | + */ |
|
139 | 139 | public function getIntOption(string $name, int $default=0) : int |
140 | 140 | { |
141 | 141 | $value = $this->getOption($name); |
@@ -146,14 +146,14 @@ discard block |
||
146 | 146 | return $default; |
147 | 147 | } |
148 | 148 | |
149 | - /** |
|
150 | - * Treats an option as an array, and returns its value |
|
151 | - * only if it contains an array - otherwise, an empty |
|
152 | - * array is returned. |
|
153 | - * |
|
154 | - * @param string $name |
|
155 | - * @return array |
|
156 | - */ |
|
149 | + /** |
|
150 | + * Treats an option as an array, and returns its value |
|
151 | + * only if it contains an array - otherwise, an empty |
|
152 | + * array is returned. |
|
153 | + * |
|
154 | + * @param string $name |
|
155 | + * @return array |
|
156 | + */ |
|
157 | 157 | public function getArrayOption(string $name) : array |
158 | 158 | { |
159 | 159 | $val = $this->getOption($name); |
@@ -164,13 +164,13 @@ discard block |
||
164 | 164 | return array(); |
165 | 165 | } |
166 | 166 | |
167 | - /** |
|
168 | - * Checks whether the specified option exists - even |
|
169 | - * if it has a NULL value. |
|
170 | - * |
|
171 | - * @param string $name |
|
172 | - * @return bool |
|
173 | - */ |
|
167 | + /** |
|
168 | + * Checks whether the specified option exists - even |
|
169 | + * if it has a NULL value. |
|
170 | + * |
|
171 | + * @param string $name |
|
172 | + * @return bool |
|
173 | + */ |
|
174 | 174 | public function hasOption(string $name) : bool |
175 | 175 | { |
176 | 176 | if(!isset($this->options)) { |
@@ -180,10 +180,10 @@ discard block |
||
180 | 180 | return array_key_exists($name, $this->options); |
181 | 181 | } |
182 | 182 | |
183 | - /** |
|
184 | - * Returns all options in one associative array. |
|
185 | - * @return array |
|
186 | - */ |
|
183 | + /** |
|
184 | + * Returns all options in one associative array. |
|
185 | + * @return array |
|
186 | + */ |
|
187 | 187 | public function getOptions() : array |
188 | 188 | { |
189 | 189 | if(!isset($this->options)) { |
@@ -193,13 +193,13 @@ discard block |
||
193 | 193 | return $this->options; |
194 | 194 | } |
195 | 195 | |
196 | - /** |
|
197 | - * Checks whether the option's value is the one specified. |
|
198 | - * |
|
199 | - * @param string $name |
|
200 | - * @param mixed $value |
|
201 | - * @return bool |
|
202 | - */ |
|
196 | + /** |
|
197 | + * Checks whether the option's value is the one specified. |
|
198 | + * |
|
199 | + * @param string $name |
|
200 | + * @param mixed $value |
|
201 | + * @return bool |
|
202 | + */ |
|
203 | 203 | public function isOption(string $name, $value) : bool |
204 | 204 | { |
205 | 205 | return $this->getOption($name) === $value; |