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 | * a new instance |
||
42 | * |
||
43 | * @param string $data |
||
44 | */ |
||
45 | 754 | public function __construct($data = null) |
|
51 | |||
52 | /** |
||
53 | * sanitize the submitted data |
||
54 | * |
||
55 | * @param string $str |
||
56 | * |
||
57 | * @throws InvalidArgumentException If reserved characters are used |
||
58 | * |
||
59 | * @return array |
||
60 | */ |
||
61 | 607 | protected function validate($str) |
|
70 | |||
71 | /** |
||
72 | * return a new Query instance from an Array or a traversable object |
||
73 | * |
||
74 | * @param \Traversable|array $data |
||
75 | * |
||
76 | * @return static |
||
77 | */ |
||
78 | 102 | public static function createFromArray($data) |
|
88 | |||
89 | /** |
||
90 | * @inheritdoc |
||
91 | */ |
||
92 | 2 | public function __debugInfo() |
|
96 | |||
97 | /** |
||
98 | * @inheritdoc |
||
99 | */ |
||
100 | 12 | public static function __set_state(array $properties) |
|
104 | |||
105 | /** |
||
106 | * Returns the instance string representation; If the |
||
107 | * instance is not defined an empty string is returned |
||
108 | * |
||
109 | * @return string |
||
110 | */ |
||
111 | 661 | public function __toString() |
|
115 | |||
116 | /** |
||
117 | * Returns the instance string representation |
||
118 | * with its optional URI delimiters |
||
119 | * |
||
120 | * @return string |
||
121 | */ |
||
122 | 611 | public function getUriComponent() |
|
131 | |||
132 | /** |
||
133 | * Retrieves a single query parameter. |
||
134 | * |
||
135 | * Retrieves a single query parameter. If the parameter has not been set, |
||
136 | * returns the default value provided. |
||
137 | * |
||
138 | * @param string $offset the parameter name |
||
139 | * @param mixed $default Default value to return if the parameter does not exist. |
||
140 | * |
||
141 | * @return mixed |
||
142 | */ |
||
143 | 9 | public function getValue($offset, $default = null) |
|
152 | |||
153 | /** |
||
154 | * Returns an instance merge with the specified query |
||
155 | * |
||
156 | * This method MUST retain the state of the current instance, and return |
||
157 | * an instance that contains the modified query |
||
158 | * |
||
159 | * @param Query|string $query the data to be merged query can be |
||
160 | * - another Interfaces\Query object |
||
161 | * - a string or a Stringable object |
||
162 | * |
||
163 | * @return static |
||
164 | */ |
||
165 | 24 | public function merge($query) |
|
177 | |||
178 | /** |
||
179 | * Sort the query string by offset, maintaining offset to data correlations. |
||
180 | * |
||
181 | * This method MUST retain the state of the current instance, and return |
||
182 | * an instance that contains the modified query |
||
183 | * |
||
184 | * @param callable|int $sort a PHP sort flag constant or a comparaison function |
||
185 | * which must return an integer less than, equal to, |
||
186 | * or greater than zero if the first argument is |
||
187 | * considered to be respectively less than, equal to, |
||
188 | * or greater than the second. |
||
189 | * |
||
190 | * @return static |
||
191 | */ |
||
192 | 45 | public function ksort($sort = SORT_REGULAR) |
|
203 | |||
204 | /** |
||
205 | * Return a new instance when needed |
||
206 | * |
||
207 | * @param array $data |
||
208 | * |
||
209 | * @return static |
||
210 | */ |
||
211 | 42 | protected function newCollectionInstance(array $data) |
|
219 | } |
||
220 |