1 | <?php |
||
27 | class Query implements QueryInterface |
||
28 | { |
||
29 | use ImmutableComponentTrait; |
||
30 | |||
31 | use ImmutableCollectionTrait; |
||
32 | |||
33 | /** |
||
34 | * Key/pair separator character |
||
35 | * |
||
36 | * @var string |
||
37 | */ |
||
38 | protected static $separator = '&'; |
||
39 | |||
40 | /** |
||
41 | * Preserve the delimiter |
||
42 | * |
||
43 | * @var string |
||
44 | */ |
||
45 | protected $preserveDelimiter = false; |
||
46 | |||
47 | /** |
||
48 | * a new instance |
||
49 | * |
||
50 | * @param string $data |
||
51 | */ |
||
52 | 767 | public function __construct($data = null) |
|
59 | |||
60 | /** |
||
61 | * sanitize the submitted data |
||
62 | * |
||
63 | * @param string $str |
||
64 | * |
||
65 | * @throws InvalidArgumentException If reserved characters are used |
||
66 | * |
||
67 | * @return array |
||
68 | */ |
||
69 | 611 | protected function validate($str) |
|
78 | |||
79 | /** |
||
80 | * return a new Query instance from an Array or a traversable object |
||
81 | * |
||
82 | * @param \Traversable|array $data |
||
83 | * |
||
84 | * @return static |
||
85 | */ |
||
86 | 102 | public static function createFromArray($data) |
|
97 | |||
98 | /** |
||
99 | * @inheritdoc |
||
100 | */ |
||
101 | 1 | public function __debugInfo() |
|
105 | |||
106 | /** |
||
107 | * @inheritdoc |
||
108 | */ |
||
109 | 12 | public static function __set_state(array $properties) |
|
116 | |||
117 | /** |
||
118 | * Returns the instance string representation; If the |
||
119 | * instance is not defined an empty string is returned |
||
120 | * |
||
121 | * @return string |
||
122 | */ |
||
123 | 674 | public function __toString() |
|
127 | |||
128 | /** |
||
129 | * Returns the instance string representation |
||
130 | * with its optional URI delimiters |
||
131 | * |
||
132 | * @return string |
||
133 | */ |
||
134 | 625 | public function getUriComponent() |
|
143 | |||
144 | /** |
||
145 | * Returns an instance with the specified string |
||
146 | * |
||
147 | * This method MUST retain the state of the current instance, and return |
||
148 | * an instance that contains the modified data |
||
149 | * |
||
150 | * @param string $value |
||
151 | * |
||
152 | * @return static |
||
153 | */ |
||
154 | 162 | public function modify($value) |
|
166 | |||
167 | /** |
||
168 | * Retrieves a single query parameter. |
||
169 | * |
||
170 | * Retrieves a single query parameter. If the parameter has not been set, |
||
171 | * returns the default value provided. |
||
172 | * |
||
173 | * @param string $offset the parameter name |
||
174 | * @param mixed $default Default value to return if the parameter does not exist. |
||
175 | * |
||
176 | * @return mixed |
||
177 | */ |
||
178 | 9 | public function getValue($offset, $default = null) |
|
187 | |||
188 | /** |
||
189 | * Returns an instance merge with the specified query |
||
190 | * |
||
191 | * This method MUST retain the state of the current instance, and return |
||
192 | * an instance that contains the modified query |
||
193 | * |
||
194 | * @param Query|string $query the data to be merged query can be |
||
195 | * - another Interfaces\Query object |
||
196 | * - a string or a Stringable object |
||
197 | * |
||
198 | * @return static |
||
199 | */ |
||
200 | 24 | public function merge($query) |
|
212 | |||
213 | /** |
||
214 | * Sort the query string by offset, maintaining offset to data correlations. |
||
215 | * |
||
216 | * This method MUST retain the state of the current instance, and return |
||
217 | * an instance that contains the modified query |
||
218 | * |
||
219 | * @param callable|int $sort a PHP sort flag constant or a comparaison function |
||
220 | * which must return an integer less than, equal to, |
||
221 | * or greater than zero if the first argument is |
||
222 | * considered to be respectively less than, equal to, |
||
223 | * or greater than the second. |
||
224 | * |
||
225 | * @return static |
||
226 | */ |
||
227 | 45 | public function ksort($sort = SORT_REGULAR) |
|
238 | |||
239 | /** |
||
240 | * Return a new instance when needed |
||
241 | * |
||
242 | * @param array $data |
||
243 | * |
||
244 | * @return static |
||
245 | */ |
||
246 | 42 | protected function newCollectionInstance(array $data) |
|
254 | } |
||
255 |
This check looks for assignments to scalar types that may be of the wrong type.
To ensure the code behaves as expected, it may be a good idea to add an explicit type cast.