@@ -8,8 +8,8 @@ discard block |
||
8 | 8 | |
9 | 9 | namespace Vendi\Shared; |
10 | 10 | |
11 | -class utils |
|
12 | -{ |
|
11 | +class utils |
|
12 | +{ |
|
13 | 13 | public static $CUSTOM_POST = null; |
14 | 14 | |
15 | 15 | public static $CUSTOM_GET = null; |
@@ -21,8 +21,8 @@ discard block |
||
21 | 21 | /** |
22 | 22 | * Reset the internal arrays to default values. |
23 | 23 | */ |
24 | - public static function reset_all_custom_arrays() |
|
25 | - { |
|
24 | + public static function reset_all_custom_arrays() |
|
25 | + { |
|
26 | 26 | self::$CUSTOM_POST = null; |
27 | 27 | self::$CUSTOM_GET = null; |
28 | 28 | self::$CUSTOM_COOKIE = null; |
@@ -35,8 +35,8 @@ discard block |
||
35 | 35 | * @param mixed $default_value Optional. If the $key cannot be found the value to return. Default null. |
36 | 36 | * @return mixed The value of the HTTP POST for the given $key or the $default. |
37 | 37 | */ |
38 | - public static function get_post_value( $key, $default_value = '' ) |
|
39 | - { |
|
38 | + public static function get_post_value( $key, $default_value = '' ) |
|
39 | + { |
|
40 | 40 | return self::get_request_value( 'POST', $key, $default_value ); |
41 | 41 | } |
42 | 42 | |
@@ -46,8 +46,8 @@ discard block |
||
46 | 46 | * @param mixed $default_value Optional. If the $key cannot be found the value to return. Default null. |
47 | 47 | * @return mixed The value of the HTTP GET for the given $key or the $default. |
48 | 48 | */ |
49 | - public static function get_get_value( $key, $default_value = '' ) |
|
50 | - { |
|
49 | + public static function get_get_value( $key, $default_value = '' ) |
|
50 | + { |
|
51 | 51 | return self::get_request_value( 'GET', $key, $default_value ); |
52 | 52 | } |
53 | 53 | |
@@ -57,8 +57,8 @@ discard block |
||
57 | 57 | * @param mixed $default_value Optional. If the $key cannot be found the value to return. Default null. |
58 | 58 | * @return mixed The value of the HTTP COOKIE for the given $key or the $default. |
59 | 59 | */ |
60 | - public static function get_cookie_value( $key, $default_value = '' ) |
|
61 | - { |
|
60 | + public static function get_cookie_value( $key, $default_value = '' ) |
|
61 | + { |
|
62 | 62 | return self::get_request_value( 'COOKIE', $key, $default_value ); |
63 | 63 | } |
64 | 64 | |
@@ -68,8 +68,8 @@ discard block |
||
68 | 68 | * @param mixed $default_value Optional. If the $key cannot be found the value to return. Default null. |
69 | 69 | * @return mixed The value of the HTTP SERVER for the given $key or the $default. |
70 | 70 | */ |
71 | - public static function get_server_value( $key, $default_value = '' ) |
|
72 | - { |
|
71 | + public static function get_server_value( $key, $default_value = '' ) |
|
72 | + { |
|
73 | 73 | return self::get_request_value( 'SERVER', $key, $default_value ); |
74 | 74 | } |
75 | 75 | |
@@ -81,13 +81,13 @@ discard block |
||
81 | 81 | * @param mixed $default_value Optional. If the $key cannot be found the value to return. Default null. |
82 | 82 | * @return mixed The value of the source for the given $key or the $default. |
83 | 83 | */ |
84 | - public static function get_value_multiple_sources( $key, array $sources, $default_value = null ) |
|
85 | - { |
|
86 | - foreach( $sources as $source ) |
|
87 | - { |
|
84 | + public static function get_value_multiple_sources( $key, array $sources, $default_value = null ) |
|
85 | + { |
|
86 | + foreach( $sources as $source ) |
|
87 | + { |
|
88 | 88 | $value = self::get_request_value( $source, $key, null ); |
89 | - if( null !== $value ) |
|
90 | - { |
|
89 | + if( null !== $value ) |
|
90 | + { |
|
91 | 91 | return $value; |
92 | 92 | } |
93 | 93 | } |
@@ -101,8 +101,8 @@ discard block |
||
101 | 101 | * @param integer|mixed $default_value Optional. If the $key cannot be found the value to return. Default null. |
102 | 102 | * @return integer|mixed The value of the HTTP POST for the given $key or the $default. |
103 | 103 | */ |
104 | - public static function get_post_value_int( $key, $default_value = null ) |
|
105 | - { |
|
104 | + public static function get_post_value_int( $key, $default_value = null ) |
|
105 | + { |
|
106 | 106 | return self::get_request_value_int( 'POST', $key, $default_value ); |
107 | 107 | } |
108 | 108 | |
@@ -112,8 +112,8 @@ discard block |
||
112 | 112 | * @param integer|mixed $default_value Optional. If the $key cannot be found the value to return. Default null. |
113 | 113 | * @return integer|mixed The value of the HTTP GET for the given $key or the $default. |
114 | 114 | */ |
115 | - public static function get_get_value_int( $key, $default_value = null ) |
|
116 | - { |
|
115 | + public static function get_get_value_int( $key, $default_value = null ) |
|
116 | + { |
|
117 | 117 | return self::get_request_value_int( 'GET', $key, $default_value ); |
118 | 118 | } |
119 | 119 | |
@@ -123,8 +123,8 @@ discard block |
||
123 | 123 | * @param integer|mixed $default_value Optional. If the $key cannot be found the value to return. Default null. |
124 | 124 | * @return integer|mixed The value of the HTTP COOKIE for the given $key or the $default. |
125 | 125 | */ |
126 | - public static function get_cookie_value_int( $key, $default_value = null ) |
|
127 | - { |
|
126 | + public static function get_cookie_value_int( $key, $default_value = null ) |
|
127 | + { |
|
128 | 128 | return self::get_request_value_int( 'COOKIE', $key, $default_value ); |
129 | 129 | } |
130 | 130 | |
@@ -134,8 +134,8 @@ discard block |
||
134 | 134 | * @param integer|mixed $default_value Optional. If the $key cannot be found the value to return. Default null. |
135 | 135 | * @return integer|mixed The value of the HTTP SERVER for the given $key or the $default. |
136 | 136 | */ |
137 | - public static function get_server_value_int( $key, $default_value = null ) |
|
138 | - { |
|
137 | + public static function get_server_value_int( $key, $default_value = null ) |
|
138 | + { |
|
139 | 139 | return self::get_request_value_int( 'SERVER', $key, $default_value ); |
140 | 140 | } |
141 | 141 | |
@@ -146,11 +146,11 @@ discard block |
||
146 | 146 | * @param integer|mixed $default_value Optional. If the $key cannot be found the value to return. Default null. |
147 | 147 | * @return integer|mixed The value of the request method for the given $key or the $default. |
148 | 148 | */ |
149 | - public static function get_request_value_int( $request_method, $key, $default_value = null ) |
|
150 | - { |
|
149 | + public static function get_request_value_int( $request_method, $key, $default_value = null ) |
|
150 | + { |
|
151 | 151 | $value = self::get_request_value( $request_method, $key, null ); |
152 | - if( self::is_integer_like( $value ) ) |
|
153 | - { |
|
152 | + if( self::is_integer_like( $value ) ) |
|
153 | + { |
|
154 | 154 | return (int)$value; |
155 | 155 | } |
156 | 156 | |
@@ -164,19 +164,19 @@ discard block |
||
164 | 164 | * @param integer|mixed $default_value Optional. If the $key cannot be found the value to return. Default null. |
165 | 165 | * @return integer|mixed The value of the request method for the given $key or the $default. |
166 | 166 | */ |
167 | - public static function get_request_value( $request_method, $key, $default_value = null ) |
|
168 | - { |
|
167 | + public static function get_request_value( $request_method, $key, $default_value = null ) |
|
168 | + { |
|
169 | 169 | $request_obj = self::get_request_object( $request_method ); |
170 | 170 | |
171 | - if( null === $request_obj || ! is_array( $request_obj ) || ! array_key_exists( $key, $request_obj ) ) |
|
172 | - { |
|
171 | + if( null === $request_obj || ! is_array( $request_obj ) || ! array_key_exists( $key, $request_obj ) ) |
|
172 | + { |
|
173 | 173 | return $default_value; |
174 | 174 | } |
175 | 175 | |
176 | 176 | $ret = $request_obj[ $key ]; |
177 | 177 | |
178 | - if( is_string( $ret ) ) |
|
179 | - { |
|
178 | + if( is_string( $ret ) ) |
|
179 | + { |
|
180 | 180 | $ret = trim( $ret ); |
181 | 181 | } |
182 | 182 | |
@@ -189,34 +189,34 @@ discard block |
||
189 | 189 | * @param string The server method to use, one of GET, POST, SERVER or COOKIE. |
190 | 190 | * @return array|null The requested array or null. |
191 | 191 | */ |
192 | - public static function get_request_object( $request_method ) |
|
193 | - { |
|
194 | - switch( $request_method ) |
|
195 | - { |
|
192 | + public static function get_request_object( $request_method ) |
|
193 | + { |
|
194 | + switch( $request_method ) |
|
195 | + { |
|
196 | 196 | case 'GET': |
197 | - if( is_array( self::$CUSTOM_GET ) ) |
|
198 | - { |
|
197 | + if( is_array( self::$CUSTOM_GET ) ) |
|
198 | + { |
|
199 | 199 | return self::$CUSTOM_GET; |
200 | 200 | } |
201 | 201 | return ( isset( $_GET ) && is_array( $_GET ) && count( $_GET ) > 0 ? $_GET : null ); |
202 | 202 | |
203 | 203 | case 'POST': |
204 | - if( is_array( self::$CUSTOM_POST ) ) |
|
205 | - { |
|
204 | + if( is_array( self::$CUSTOM_POST ) ) |
|
205 | + { |
|
206 | 206 | return self::$CUSTOM_POST; |
207 | 207 | } |
208 | 208 | return ( isset( $_POST ) && is_array( $_POST ) && count( $_POST ) > 0 ? $_POST : null ); |
209 | 209 | |
210 | 210 | case 'COOKIE': |
211 | - if( is_array( self::$CUSTOM_COOKIE ) ) |
|
212 | - { |
|
211 | + if( is_array( self::$CUSTOM_COOKIE ) ) |
|
212 | + { |
|
213 | 213 | return self::$CUSTOM_COOKIE; |
214 | 214 | } |
215 | 215 | return ( isset( $_COOKIE ) && is_array( $_COOKIE ) && count( $_COOKIE ) > 0 ? $_COOKIE : null ); |
216 | 216 | |
217 | 217 | case 'SERVER': |
218 | - if( is_array( self::$CUSTOM_SERVER ) ) |
|
219 | - { |
|
218 | + if( is_array( self::$CUSTOM_SERVER ) ) |
|
219 | + { |
|
220 | 220 | return self::$CUSTOM_SERVER; |
221 | 221 | } |
222 | 222 | return ( isset( $_SERVER ) && is_array( $_SERVER ) && count( $_SERVER ) > 0 ? $_SERVER : null ); |
@@ -232,8 +232,8 @@ discard block |
||
232 | 232 | * @param string $method The server method to test for. Generally one of GET, POST, HEAD, PUT, DELETE. |
233 | 233 | * @return boolean Returns true if the REQUEST_METHOD server variable is set to the supplied $method, otherwise false. |
234 | 234 | */ |
235 | - public static function is_request_method( $method ) |
|
236 | - { |
|
235 | + public static function is_request_method( $method ) |
|
236 | + { |
|
237 | 237 | return $method === self::get_server_value( 'REQUEST_METHOD' ); |
238 | 238 | } |
239 | 239 | |
@@ -247,8 +247,8 @@ discard block |
||
247 | 247 | * |
248 | 248 | * @return boolean Returns true if the REQUEST_METHOD server variable is set to POST, otherwise false. |
249 | 249 | */ |
250 | - public static function is_post( ) |
|
251 | - { |
|
250 | + public static function is_post( ) |
|
251 | + { |
|
252 | 252 | return self::is_request_method( 'POST' ); |
253 | 253 | } |
254 | 254 | |
@@ -260,8 +260,8 @@ discard block |
||
260 | 260 | * @param mixed $input The value to test. |
261 | 261 | * @return boolean True if $input is an integer or a string that contains only digits possibly starting with a dash. |
262 | 262 | */ |
263 | - public static function is_integer_like( $input ) |
|
264 | - { |
|
263 | + public static function is_integer_like( $input ) |
|
264 | + { |
|
265 | 265 | return |
266 | 266 | is_int( $input ) |
267 | 267 | || |