@@ -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; |
@@ -23,8 +23,8 @@ discard block |
||
| 23 | 23 | /** |
| 24 | 24 | * Reset the internal arrays to default values. |
| 25 | 25 | */ |
| 26 | - public static function reset_all_custom_arrays() |
|
| 27 | - {
|
|
| 26 | + public static function reset_all_custom_arrays() |
|
| 27 | + { |
|
| 28 | 28 | self::$CUSTOM_POST = null; |
| 29 | 29 | self::$CUSTOM_GET = null; |
| 30 | 30 | self::$CUSTOM_COOKIE = null; |
@@ -38,8 +38,8 @@ discard block |
||
| 38 | 38 | * @param mixed $default_value Optional. If the $key cannot be found the value to return. Default null. |
| 39 | 39 | * @return mixed The value of the HTTP POST for the given $key or the $default. |
| 40 | 40 | */ |
| 41 | - public static function get_post_value( $key, $default_value = '' ) |
|
| 42 | - {
|
|
| 41 | + public static function get_post_value( $key, $default_value = '' ) |
|
| 42 | + { |
|
| 43 | 43 | return self::get_request_value( 'POST', $key, $default_value ); |
| 44 | 44 | } |
| 45 | 45 | |
@@ -49,8 +49,8 @@ discard block |
||
| 49 | 49 | * @param mixed $default_value Optional. If the $key cannot be found the value to return. Default null. |
| 50 | 50 | * @return mixed The value of the HTTP GET for the given $key or the $default. |
| 51 | 51 | */ |
| 52 | - public static function get_get_value( $key, $default_value = '' ) |
|
| 53 | - {
|
|
| 52 | + public static function get_get_value( $key, $default_value = '' ) |
|
| 53 | + { |
|
| 54 | 54 | return self::get_request_value( 'GET', $key, $default_value ); |
| 55 | 55 | } |
| 56 | 56 | |
@@ -60,8 +60,8 @@ discard block |
||
| 60 | 60 | * @param mixed $default_value Optional. If the $key cannot be found the value to return. Default null. |
| 61 | 61 | * @return mixed The value of the HTTP COOKIE for the given $key or the $default. |
| 62 | 62 | */ |
| 63 | - public static function get_cookie_value( $key, $default_value = '' ) |
|
| 64 | - {
|
|
| 63 | + public static function get_cookie_value( $key, $default_value = '' ) |
|
| 64 | + { |
|
| 65 | 65 | return self::get_request_value( 'COOKIE', $key, $default_value ); |
| 66 | 66 | } |
| 67 | 67 | |
@@ -71,8 +71,8 @@ discard block |
||
| 71 | 71 | * @param mixed $default_value Optional. If the $key cannot be found the value to return. Default null. |
| 72 | 72 | * @return mixed The value of the HTTP SERVER for the given $key or the $default. |
| 73 | 73 | */ |
| 74 | - public static function get_server_value( $key, $default_value = '' ) |
|
| 75 | - {
|
|
| 74 | + public static function get_server_value( $key, $default_value = '' ) |
|
| 75 | + { |
|
| 76 | 76 | return self::get_request_value( 'SERVER', $key, $default_value ); |
| 77 | 77 | } |
| 78 | 78 | |
@@ -82,8 +82,8 @@ discard block |
||
| 82 | 82 | * @param mixed $default_value Optional. If the $key cannot be found the value to return. Default null. |
| 83 | 83 | * @return mixed The value of the SESSION for the given $key or the $default. |
| 84 | 84 | */ |
| 85 | - public static function get_session_value( $key, $default_value = '' ) |
|
| 86 | - {
|
|
| 85 | + public static function get_session_value( $key, $default_value = '' ) |
|
| 86 | + { |
|
| 87 | 87 | return self::get_request_value( 'SESSION', $key, $default_value ); |
| 88 | 88 | } |
| 89 | 89 | |
@@ -95,13 +95,13 @@ discard block |
||
| 95 | 95 | * @param mixed $default_value Optional. If the $key cannot be found the value to return. Default null. |
| 96 | 96 | * @return mixed The value of the source for the given $key or the $default. |
| 97 | 97 | */ |
| 98 | - public static function get_value_multiple_sources( $key, array $sources, $default_value = null ) |
|
| 99 | - {
|
|
| 100 | - foreach( $sources as $source ) |
|
| 101 | - {
|
|
| 98 | + public static function get_value_multiple_sources( $key, array $sources, $default_value = null ) |
|
| 99 | + { |
|
| 100 | + foreach( $sources as $source ) |
|
| 101 | + { |
|
| 102 | 102 | $value = self::get_request_value( $source, $key, null ); |
| 103 | - if( null !== $value ) |
|
| 104 | - {
|
|
| 103 | + if( null !== $value ) |
|
| 104 | + { |
|
| 105 | 105 | return $value; |
| 106 | 106 | } |
| 107 | 107 | } |
@@ -115,8 +115,8 @@ discard block |
||
| 115 | 115 | * @param integer|mixed $default_value Optional. If the $key cannot be found the value to return. Default null. |
| 116 | 116 | * @return integer|mixed The value of the HTTP POST for the given $key or the $default. |
| 117 | 117 | */ |
| 118 | - public static function get_post_value_int( $key, $default_value = null ) |
|
| 119 | - {
|
|
| 118 | + public static function get_post_value_int( $key, $default_value = null ) |
|
| 119 | + { |
|
| 120 | 120 | return self::get_request_value_int( 'POST', $key, $default_value ); |
| 121 | 121 | } |
| 122 | 122 | |
@@ -126,8 +126,8 @@ discard block |
||
| 126 | 126 | * @param integer|mixed $default_value Optional. If the $key cannot be found the value to return. Default null. |
| 127 | 127 | * @return integer|mixed The value of the HTTP GET for the given $key or the $default. |
| 128 | 128 | */ |
| 129 | - public static function get_get_value_int( $key, $default_value = null ) |
|
| 130 | - {
|
|
| 129 | + public static function get_get_value_int( $key, $default_value = null ) |
|
| 130 | + { |
|
| 131 | 131 | return self::get_request_value_int( 'GET', $key, $default_value ); |
| 132 | 132 | } |
| 133 | 133 | |
@@ -137,8 +137,8 @@ discard block |
||
| 137 | 137 | * @param integer|mixed $default_value Optional. If the $key cannot be found the value to return. Default null. |
| 138 | 138 | * @return integer|mixed The value of the HTTP COOKIE for the given $key or the $default. |
| 139 | 139 | */ |
| 140 | - public static function get_cookie_value_int( $key, $default_value = null ) |
|
| 141 | - {
|
|
| 140 | + public static function get_cookie_value_int( $key, $default_value = null ) |
|
| 141 | + { |
|
| 142 | 142 | return self::get_request_value_int( 'COOKIE', $key, $default_value ); |
| 143 | 143 | } |
| 144 | 144 | |
@@ -148,8 +148,8 @@ discard block |
||
| 148 | 148 | * @param integer|mixed $default_value Optional. If the $key cannot be found the value to return. Default null. |
| 149 | 149 | * @return integer|mixed The value of the HTTP SERVER for the given $key or the $default. |
| 150 | 150 | */ |
| 151 | - public static function get_server_value_int( $key, $default_value = null ) |
|
| 152 | - {
|
|
| 151 | + public static function get_server_value_int( $key, $default_value = null ) |
|
| 152 | + { |
|
| 153 | 153 | return self::get_request_value_int( 'SERVER', $key, $default_value ); |
| 154 | 154 | } |
| 155 | 155 | |
@@ -159,8 +159,8 @@ discard block |
||
| 159 | 159 | * @param integer|mixed $default_value Optional. If the $key cannot be found the value to return. Default null. |
| 160 | 160 | * @return integer|mixed The value of the SESSION for the given $key or the $default. |
| 161 | 161 | */ |
| 162 | - public static function get_session_value_int( $key, $default_value = null ) |
|
| 163 | - {
|
|
| 162 | + public static function get_session_value_int( $key, $default_value = null ) |
|
| 163 | + { |
|
| 164 | 164 | return self::get_request_value_int( 'SESSION', $key, $default_value ); |
| 165 | 165 | } |
| 166 | 166 | |
@@ -171,11 +171,11 @@ discard block |
||
| 171 | 171 | * @param integer|mixed $default_value Optional. If the $key cannot be found the value to return. Default null. |
| 172 | 172 | * @return integer|mixed The value of the request method for the given $key or the $default. |
| 173 | 173 | */ |
| 174 | - public static function get_request_value_int( $request_method, $key, $default_value = null ) |
|
| 175 | - {
|
|
| 174 | + public static function get_request_value_int( $request_method, $key, $default_value = null ) |
|
| 175 | + { |
|
| 176 | 176 | $value = self::get_request_value( $request_method, $key, null ); |
| 177 | - if( self::is_integer_like( $value ) ) |
|
| 178 | - {
|
|
| 177 | + if( self::is_integer_like( $value ) ) |
|
| 178 | + { |
|
| 179 | 179 | return (int)$value; |
| 180 | 180 | } |
| 181 | 181 | |
@@ -189,19 +189,19 @@ discard block |
||
| 189 | 189 | * @param integer|mixed $default_value Optional. If the $key cannot be found the value to return. Default null. |
| 190 | 190 | * @return integer|mixed The value of the request method for the given $key or the $default. |
| 191 | 191 | */ |
| 192 | - public static function get_request_value( $request_method, $key, $default_value = null ) |
|
| 193 | - {
|
|
| 192 | + public static function get_request_value( $request_method, $key, $default_value = null ) |
|
| 193 | + { |
|
| 194 | 194 | $request_obj = self::get_request_object( $request_method ); |
| 195 | 195 | |
| 196 | - if( null === $request_obj || ! is_array( $request_obj ) || ! array_key_exists( $key, $request_obj ) ) |
|
| 197 | - {
|
|
| 196 | + if( null === $request_obj || ! is_array( $request_obj ) || ! array_key_exists( $key, $request_obj ) ) |
|
| 197 | + { |
|
| 198 | 198 | return $default_value; |
| 199 | 199 | } |
| 200 | 200 | |
| 201 | 201 | $ret = $request_obj[ $key ]; |
| 202 | 202 | |
| 203 | - if( is_string( $ret ) ) |
|
| 204 | - {
|
|
| 203 | + if( is_string( $ret ) ) |
|
| 204 | + { |
|
| 205 | 205 | $ret = trim( $ret ); |
| 206 | 206 | } |
| 207 | 207 | |
@@ -214,41 +214,41 @@ discard block |
||
| 214 | 214 | * @param string The server method to use, one of GET, POST, SERVER or COOKIE. |
| 215 | 215 | * @return array|null The requested array or null. |
| 216 | 216 | */ |
| 217 | - public static function get_request_object( $request_method ) |
|
| 218 | - {
|
|
| 219 | - switch( $request_method ) |
|
| 220 | - {
|
|
| 217 | + public static function get_request_object( $request_method ) |
|
| 218 | + { |
|
| 219 | + switch( $request_method ) |
|
| 220 | + { |
|
| 221 | 221 | case 'GET': |
| 222 | - if( is_array( self::$CUSTOM_GET ) ) |
|
| 223 | - {
|
|
| 222 | + if( is_array( self::$CUSTOM_GET ) ) |
|
| 223 | + { |
|
| 224 | 224 | return self::$CUSTOM_GET; |
| 225 | 225 | } |
| 226 | 226 | return ( isset( $_GET ) && is_array( $_GET ) && count( $_GET ) > 0 ? $_GET : null ); |
| 227 | 227 | |
| 228 | 228 | case 'POST': |
| 229 | - if( is_array( self::$CUSTOM_POST ) ) |
|
| 230 | - {
|
|
| 229 | + if( is_array( self::$CUSTOM_POST ) ) |
|
| 230 | + { |
|
| 231 | 231 | return self::$CUSTOM_POST; |
| 232 | 232 | } |
| 233 | 233 | return ( isset( $_POST ) && is_array( $_POST ) && count( $_POST ) > 0 ? $_POST : null ); |
| 234 | 234 | |
| 235 | 235 | case 'COOKIE': |
| 236 | - if( is_array( self::$CUSTOM_COOKIE ) ) |
|
| 237 | - {
|
|
| 236 | + if( is_array( self::$CUSTOM_COOKIE ) ) |
|
| 237 | + { |
|
| 238 | 238 | return self::$CUSTOM_COOKIE; |
| 239 | 239 | } |
| 240 | 240 | return ( isset( $_COOKIE ) && is_array( $_COOKIE ) && count( $_COOKIE ) > 0 ? $_COOKIE : null ); |
| 241 | 241 | |
| 242 | 242 | case 'SERVER': |
| 243 | - if( is_array( self::$CUSTOM_SERVER ) ) |
|
| 244 | - {
|
|
| 243 | + if( is_array( self::$CUSTOM_SERVER ) ) |
|
| 244 | + { |
|
| 245 | 245 | return self::$CUSTOM_SERVER; |
| 246 | 246 | } |
| 247 | 247 | return ( isset( $_SERVER ) && is_array( $_SERVER ) && count( $_SERVER ) > 0 ? $_SERVER : null ); |
| 248 | 248 | |
| 249 | 249 | case 'SESSION': |
| 250 | - if( is_array( self::$CUSTOM_SESSION ) ) |
|
| 251 | - {
|
|
| 250 | + if( is_array( self::$CUSTOM_SESSION ) ) |
|
| 251 | + { |
|
| 252 | 252 | return self::$CUSTOM_SESSION; |
| 253 | 253 | } |
| 254 | 254 | return ( isset( $_SESSION ) && is_array( $_SESSION ) && count( $_SESSION ) > 0 ? $_SESSION : null ); |
@@ -264,8 +264,8 @@ discard block |
||
| 264 | 264 | * @param string $method The server method to test for. Generally one of GET, POST, HEAD, PUT, DELETE. |
| 265 | 265 | * @return boolean Returns true if the REQUEST_METHOD server variable is set to the supplied $method, otherwise false. |
| 266 | 266 | */ |
| 267 | - public static function is_request_method( $method ) |
|
| 268 | - {
|
|
| 267 | + public static function is_request_method( $method ) |
|
| 268 | + { |
|
| 269 | 269 | return $method === self::get_server_value( 'REQUEST_METHOD' ); |
| 270 | 270 | } |
| 271 | 271 | |
@@ -279,8 +279,8 @@ discard block |
||
| 279 | 279 | * |
| 280 | 280 | * @return boolean Returns true if the REQUEST_METHOD server variable is set to POST, otherwise false. |
| 281 | 281 | */ |
| 282 | - public static function is_post( ) |
|
| 283 | - {
|
|
| 282 | + public static function is_post( ) |
|
| 283 | + { |
|
| 284 | 284 | return self::is_request_method( 'POST' ); |
| 285 | 285 | } |
| 286 | 286 | |
@@ -292,8 +292,8 @@ discard block |
||
| 292 | 292 | * @param mixed $input The value to test. |
| 293 | 293 | * @return boolean True if $input is an integer or a string that contains only digits possibly starting with a dash. |
| 294 | 294 | */ |
| 295 | - public static function is_integer_like( $input ) |
|
| 296 | - {
|
|
| 295 | + public static function is_integer_like( $input ) |
|
| 296 | + { |
|
| 297 | 297 | return |
| 298 | 298 | is_int( $input ) |
| 299 | 299 | || |