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 | 484 | 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 | 386 | 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 | 60 | public static function createFromArray($data) |
|
88 | |||
89 | /** |
||
90 | * Returns the instance string representation; If the |
||
91 | * instance is not defined an empty string is returned |
||
92 | 422 | * |
|
93 | * @return string |
||
94 | 422 | */ |
|
95 | public function __toString() |
||
99 | |||
100 | 390 | /** |
|
101 | * Returns the instance string representation |
||
102 | 390 | * with its optional URI delimiters |
|
103 | 390 | * |
|
104 | 286 | * @return string |
|
105 | 286 | */ |
|
106 | public function getUriComponent() |
||
115 | 6 | ||
116 | 6 | /** |
|
117 | 2 | * Retrieves a single query parameter. |
|
118 | * |
||
119 | * Retrieves a single query parameter. If the parameter has not been set, |
||
120 | 4 | * returns the default value provided. |
|
121 | * |
||
122 | * @param string $offset the parameter name |
||
123 | * @param mixed $default Default value to return if the parameter does not exist. |
||
124 | * |
||
125 | * @return mixed |
||
126 | 16 | */ |
|
127 | public function getValue($offset, $default = null) |
||
128 | 16 | { |
|
129 | 4 | $offset = rawurldecode($offset); |
|
130 | 4 | if (isset($this->data[$offset])) { |
|
131 | return $this->data[$offset]; |
||
132 | 16 | } |
|
133 | 2 | ||
134 | return $default; |
||
135 | } |
||
136 | 14 | ||
137 | /** |
||
138 | * Returns an instance merge with the specified query |
||
139 | * |
||
140 | * This method MUST retain the state of the current instance, and return |
||
141 | * an instance that contains the modified query |
||
142 | 28 | * |
|
143 | * @param Query|string $query the data to be merged query can be |
||
144 | 28 | * - another Interfaces\Query object |
|
145 | 28 | * - a string or a Stringable object |
|
146 | 28 | * |
|
147 | 28 | * @return static |
|
148 | 20 | */ |
|
149 | public function merge($query) |
||
161 | 28 | ||
162 | /** |
||
163 | 28 | * Sort the query string by offset, maintaining offset to data correlations. |
|
164 | 10 | * |
|
165 | * This method MUST retain the state of the current instance, and return |
||
166 | * an instance that contains the modified query |
||
167 | 18 | * |
|
168 | * @param callable|int $sort a PHP sort flag constant or a comparaison function |
||
169 | * which must return an integer less than, equal to, |
||
170 | * or greater than zero if the first argument is |
||
171 | * considered to be respectively less than, equal to, |
||
172 | * or greater than the second. |
||
173 | * |
||
174 | * @return static |
||
175 | */ |
||
176 | public function ksort($sort = SORT_REGULAR) |
||
187 | |||
188 | /** |
||
189 | * Return a new instance when needed |
||
190 | * |
||
191 | * @param array $data |
||
192 | * |
||
193 | * @return static |
||
194 | */ |
||
195 | protected function newCollectionInstance(array $data) |
||
203 | |||
204 | /** |
||
205 | * @inheritdoc |
||
206 | */ |
||
207 | public static function __set_state(array $properties) |
||
211 | } |
||
212 |