@@ -155,6 +155,10 @@ |
||
155 | 155 | return self::get_request_value_int( 'SERVER', $key, $default_value ); |
156 | 156 | } |
157 | 157 | |
158 | + /** |
|
159 | + * @param string $request_method |
|
160 | + * @param string $key |
|
161 | + */ |
|
158 | 162 | public static function get_request_value_int( $request_method, $key, $default_value = null ) |
159 | 163 | { |
160 | 164 | $value = self::get_request_value( $request_method, $key, null ); |
@@ -8,7 +8,7 @@ discard block |
||
8 | 8 | |
9 | 9 | namespace Vendi\Shared; |
10 | 10 | |
11 | -if( class_exists( '\Vendi\Shared\utils' ) ) |
|
11 | +if (class_exists('\Vendi\Shared\utils')) |
|
12 | 12 | { |
13 | 13 | return; |
14 | 14 | } |
@@ -73,9 +73,9 @@ discard block |
||
73 | 73 | * @param integer|mixed $default_value Optional. If the $key cannot be found the value to return. Default null. |
74 | 74 | * @return integer|mixed The value of the HTTP POST for the given $key or the $default. |
75 | 75 | */ |
76 | - public static function get_post_value( $key, $default_value = '' ) |
|
76 | + public static function get_post_value($key, $default_value = '') |
|
77 | 77 | { |
78 | - return self::get_request_value( 'POST', $key, $default_value ); |
|
78 | + return self::get_request_value('POST', $key, $default_value); |
|
79 | 79 | } |
80 | 80 | |
81 | 81 | /** |
@@ -84,9 +84,9 @@ discard block |
||
84 | 84 | * @param integer|mixed $default_value Optional. If the $key cannot be found the value to return. Default null. |
85 | 85 | * @return integer|mixed The value of the HTTP GET for the given $key or the $default. |
86 | 86 | */ |
87 | - public static function get_get_value( $key, $default_value = '' ) |
|
87 | + public static function get_get_value($key, $default_value = '') |
|
88 | 88 | { |
89 | - return self::get_request_value( 'GET', $key, $default_value ); |
|
89 | + return self::get_request_value('GET', $key, $default_value); |
|
90 | 90 | } |
91 | 91 | |
92 | 92 | /** |
@@ -95,9 +95,9 @@ discard block |
||
95 | 95 | * @param integer|mixed $default_value Optional. If the $key cannot be found the value to return. Default null. |
96 | 96 | * @return integer|mixed The value of the HTTP COOKIE for the given $key or the $default. |
97 | 97 | */ |
98 | - public static function get_cookie_value( $key, $default_value = '' ) |
|
98 | + public static function get_cookie_value($key, $default_value = '') |
|
99 | 99 | { |
100 | - return self::get_request_value( 'COOKIE', $key, $default_value ); |
|
100 | + return self::get_request_value('COOKIE', $key, $default_value); |
|
101 | 101 | } |
102 | 102 | |
103 | 103 | /** |
@@ -106,9 +106,9 @@ discard block |
||
106 | 106 | * @param integer|mixed $default_value Optional. If the $key cannot be found the value to return. Default null. |
107 | 107 | * @return integer|mixed The value of the HTTP SERVER for the given $key or the $default. |
108 | 108 | */ |
109 | - public static function get_server_value( $key, $default_value = '' ) |
|
109 | + public static function get_server_value($key, $default_value = '') |
|
110 | 110 | { |
111 | - return self::get_request_value( 'SERVER', $key, $default_value ); |
|
111 | + return self::get_request_value('SERVER', $key, $default_value); |
|
112 | 112 | } |
113 | 113 | |
114 | 114 | /** |
@@ -117,9 +117,9 @@ discard block |
||
117 | 117 | * @param integer|mixed $default_value Optional. If the $key cannot be found the value to return. Default null. |
118 | 118 | * @return integer|mixed The value of the HTTP POST for the given $key or the $default. |
119 | 119 | */ |
120 | - public static function get_post_value_int( $key, $default_value = null ) |
|
120 | + public static function get_post_value_int($key, $default_value = null) |
|
121 | 121 | { |
122 | - return self::get_request_value_int( 'POST', $key, $default_value ); |
|
122 | + return self::get_request_value_int('POST', $key, $default_value); |
|
123 | 123 | } |
124 | 124 | |
125 | 125 | /** |
@@ -128,9 +128,9 @@ discard block |
||
128 | 128 | * @param integer|mixed $default_value Optional. If the $key cannot be found the value to return. Default null. |
129 | 129 | * @return integer|mixed The value of the HTTP GET for the given $key or the $default. |
130 | 130 | */ |
131 | - public static function get_get_value_int( $key, $default_value = null ) |
|
131 | + public static function get_get_value_int($key, $default_value = null) |
|
132 | 132 | { |
133 | - return self::get_request_value_int( 'GET', $key, $default_value ); |
|
133 | + return self::get_request_value_int('GET', $key, $default_value); |
|
134 | 134 | } |
135 | 135 | |
136 | 136 | /** |
@@ -139,9 +139,9 @@ discard block |
||
139 | 139 | * @param integer|mixed $default_value Optional. If the $key cannot be found the value to return. Default null. |
140 | 140 | * @return integer|mixed The value of the HTTP COOKIE for the given $key or the $default. |
141 | 141 | */ |
142 | - public static function get_cookie_value_int( $key, $default_value = null ) |
|
142 | + public static function get_cookie_value_int($key, $default_value = null) |
|
143 | 143 | { |
144 | - return self::get_request_value_int( 'COOKIE', $key, $default_value ); |
|
144 | + return self::get_request_value_int('COOKIE', $key, $default_value); |
|
145 | 145 | } |
146 | 146 | |
147 | 147 | /** |
@@ -150,73 +150,73 @@ discard block |
||
150 | 150 | * @param integer|mixed $default_value Optional. If the $key cannot be found the value to return. Default null. |
151 | 151 | * @return integer|mixed The value of the HTTP SERVER for the given $key or the $default. |
152 | 152 | */ |
153 | - public static function get_server_value_int( $key, $default_value = null ) |
|
153 | + public static function get_server_value_int($key, $default_value = null) |
|
154 | 154 | { |
155 | - return self::get_request_value_int( 'SERVER', $key, $default_value ); |
|
155 | + return self::get_request_value_int('SERVER', $key, $default_value); |
|
156 | 156 | } |
157 | 157 | |
158 | - public static function get_request_value_int( $request_method, $key, $default_value = null ) |
|
158 | + public static function get_request_value_int($request_method, $key, $default_value = null) |
|
159 | 159 | { |
160 | - $value = self::get_request_value( $request_method, $key, null ); |
|
161 | - if( self::is_integer_like( $value ) ) |
|
160 | + $value = self::get_request_value($request_method, $key, null); |
|
161 | + if (self::is_integer_like($value)) |
|
162 | 162 | { |
163 | - return (int)$value; |
|
163 | + return (int) $value; |
|
164 | 164 | } |
165 | 165 | |
166 | 166 | return $default_value; |
167 | 167 | } |
168 | 168 | |
169 | - public static function get_request_value( $request_method, $key, $default_value = null ) |
|
169 | + public static function get_request_value($request_method, $key, $default_value = null) |
|
170 | 170 | { |
171 | - $request_obj = self::get_request_object( $request_method ); |
|
171 | + $request_obj = self::get_request_object($request_method); |
|
172 | 172 | |
173 | - if( null === $request_obj || ! is_array( $request_obj ) || ! array_key_exists( $key, $request_obj ) ) |
|
173 | + if (null === $request_obj || !is_array($request_obj) || !array_key_exists($key, $request_obj)) |
|
174 | 174 | { |
175 | 175 | return $default_value; |
176 | 176 | } |
177 | 177 | |
178 | - $ret = $request_obj[ $key ]; |
|
178 | + $ret = $request_obj[$key]; |
|
179 | 179 | |
180 | - if( is_string( $ret ) ) |
|
180 | + if (is_string($ret)) |
|
181 | 181 | { |
182 | - $ret = trim( $ret ); |
|
182 | + $ret = trim($ret); |
|
183 | 183 | } |
184 | 184 | |
185 | 185 | return $ret; |
186 | 186 | } |
187 | 187 | |
188 | - public static function get_request_object( $request_method ) |
|
188 | + public static function get_request_object($request_method) |
|
189 | 189 | { |
190 | 190 | $obj = null; |
191 | - switch( $request_method ) |
|
191 | + switch ($request_method) |
|
192 | 192 | { |
193 | 193 | case 'GET': |
194 | - if( is_array( self::$CUSTOM_GET ) ) |
|
194 | + if (is_array(self::$CUSTOM_GET)) |
|
195 | 195 | { |
196 | 196 | return self::$CUSTOM_GET; |
197 | 197 | } |
198 | - return ( isset( $_GET ) && is_array( $_GET ) && count( $_GET ) > 0 ? $_GET : null ); |
|
198 | + return (isset($_GET) && is_array($_GET) && count($_GET) > 0 ? $_GET : null); |
|
199 | 199 | |
200 | 200 | case 'POST': |
201 | - if( is_array( self::$CUSTOM_POST ) ) |
|
201 | + if (is_array(self::$CUSTOM_POST)) |
|
202 | 202 | { |
203 | 203 | return self::$CUSTOM_POST; |
204 | 204 | } |
205 | - return ( isset( $_POST ) && is_array( $_POST ) && count( $_POST ) > 0 ? $_POST : null ); |
|
205 | + return (isset($_POST) && is_array($_POST) && count($_POST) > 0 ? $_POST : null); |
|
206 | 206 | |
207 | 207 | case 'COOKIE': |
208 | - if( is_array( self::$CUSTOM_COOKIE ) ) |
|
208 | + if (is_array(self::$CUSTOM_COOKIE)) |
|
209 | 209 | { |
210 | 210 | return self::$CUSTOM_COOKIE; |
211 | 211 | } |
212 | - return ( isset( $_COOKIE ) && is_array( $_COOKIE ) && count( $_COOKIE ) > 0 ? $_COOKIE : null ); |
|
212 | + return (isset($_COOKIE) && is_array($_COOKIE) && count($_COOKIE) > 0 ? $_COOKIE : null); |
|
213 | 213 | |
214 | 214 | case 'SERVER': |
215 | - if( is_array( self::$CUSTOM_SERVER ) ) |
|
215 | + if (is_array(self::$CUSTOM_SERVER)) |
|
216 | 216 | { |
217 | 217 | return self::$CUSTOM_SERVER; |
218 | 218 | } |
219 | - return ( isset( $_SERVER ) && is_array( $_SERVER ) && count( $_SERVER ) > 0 ? $_SERVER : null ); |
|
219 | + return (isset($_SERVER) && is_array($_SERVER) && count($_SERVER) > 0 ? $_SERVER : null); |
|
220 | 220 | |
221 | 221 | default: |
222 | 222 | return null; |
@@ -229,9 +229,9 @@ discard block |
||
229 | 229 | * @param string $method The server method to test for. Generally one of GET, POST, HEAD, PUT, DELETE. |
230 | 230 | * @return boolean Returns true if the REQUEST_METHOD server variable is set to the supplied $method, otherwise false. |
231 | 231 | */ |
232 | - public static function is_request_method( $method ) |
|
232 | + public static function is_request_method($method) |
|
233 | 233 | { |
234 | - return $method === self::get_server_value( 'REQUEST_METHOD' ); |
|
234 | + return $method === self::get_server_value('REQUEST_METHOD'); |
|
235 | 235 | } |
236 | 236 | |
237 | 237 | /** |
@@ -246,7 +246,7 @@ discard block |
||
246 | 246 | */ |
247 | 247 | public static function is_post( ) |
248 | 248 | { |
249 | - return self::is_request_method( 'POST' ); |
|
249 | + return self::is_request_method('POST'); |
|
250 | 250 | } |
251 | 251 | |
252 | 252 | /** |
@@ -257,28 +257,28 @@ discard block |
||
257 | 257 | * @param mixed $input The value to test. |
258 | 258 | * @return boolean True if $input is an integer or a string that contains only digits possibly starting with a dash. |
259 | 259 | */ |
260 | - public static function is_integer_like( $input ) |
|
260 | + public static function is_integer_like($input) |
|
261 | 261 | { |
262 | 262 | return |
263 | - is_int( $input ) |
|
263 | + is_int($input) |
|
264 | 264 | || |
265 | 265 | ( |
266 | - is_string( $input ) |
|
266 | + is_string($input) |
|
267 | 267 | && |
268 | - preg_match( '/^-?([0-9])+$/', $input ) |
|
268 | + preg_match('/^-?([0-9])+$/', $input) |
|
269 | 269 | ); |
270 | 270 | } |
271 | 271 | |
272 | 272 | public static function get_all_headers() |
273 | 273 | { |
274 | 274 | $headers = array(); |
275 | - foreach( array( '_SERVER', '_GET', '_POST', '_COOKIE', '_ENV' ) as $key ) |
|
275 | + foreach (array('_SERVER', '_GET', '_POST', '_COOKIE', '_ENV') as $key) |
|
276 | 276 | { |
277 | - if( array_key_exists( $key, $GLOBALS ) ) |
|
277 | + if (array_key_exists($key, $GLOBALS)) |
|
278 | 278 | { |
279 | 279 | |
280 | 280 | } |
281 | - $headers[ $key ] = $GLOBALS[ $key ]; |
|
281 | + $headers[$key] = $GLOBALS[$key]; |
|
282 | 282 | } |
283 | 283 | return $headers; |
284 | 284 | } |
@@ -291,17 +291,17 @@ discard block |
||
291 | 291 | * @param array $parsed_url An array created by urlpieces. |
292 | 292 | * @return string A URL string. |
293 | 293 | */ |
294 | - public static function unparse_url( $parsed_url ) { |
|
294 | + public static function unparse_url($parsed_url) { |
|
295 | 295 | //I don't know what you gave me so you can just have it back |
296 | - if( ! is_array( $parsed_url ) ) { |
|
296 | + if (!is_array($parsed_url)) { |
|
297 | 297 | return $parsed_url; |
298 | 298 | } |
299 | - $scheme = isset( $parsed_url['scheme']) ? $parsed_url['scheme'] . '://' : ''; |
|
300 | - $host = isset( $parsed_url['host'] ) ? $parsed_url['host'] : ''; |
|
301 | - $port = isset( $parsed_url['port'] ) ? ':' . $parsed_url['port'] : ''; |
|
302 | - $path = isset( $parsed_url['path'] ) ? $parsed_url['path'] : ''; |
|
303 | - $query = isset( $parsed_url['query'] ) ? '?' . $parsed_url['query'] : ''; |
|
304 | - $fragment = isset( $parsed_url['fragment'] ) ? '#' . $parsed_url['fragment'] : ''; |
|
299 | + $scheme = isset($parsed_url['scheme']) ? $parsed_url['scheme'].'://' : ''; |
|
300 | + $host = isset($parsed_url['host']) ? $parsed_url['host'] : ''; |
|
301 | + $port = isset($parsed_url['port']) ? ':'.$parsed_url['port'] : ''; |
|
302 | + $path = isset($parsed_url['path']) ? $parsed_url['path'] : ''; |
|
303 | + $query = isset($parsed_url['query']) ? '?'.$parsed_url['query'] : ''; |
|
304 | + $fragment = isset($parsed_url['fragment']) ? '#'.$parsed_url['fragment'] : ''; |
|
305 | 305 | |
306 | 306 | //NOTE: user and pass were explicitly removed. |
307 | 307 |