Completed
Push — master ( c7240b...3ac908 )
by Chris
03:04 queued 51s
created
src/utils.php 1 patch
Spacing   +59 added lines, -59 removed lines patch added patch discarded remove patch
@@ -8,7 +8,7 @@  discard block
 block discarded – undo
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
 block discarded – undo
73 73
      * @param  mixed         $default_value Optional. If the $key cannot be found the value to return. Default null.
74 74
      * @return 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
 block discarded – undo
84 84
      * @param  mixed         $default_value Optional. If the $key cannot be found the value to return. Default null.
85 85
      * @return 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
 block discarded – undo
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 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
 block discarded – undo
106 106
      * @param  mixed         $default_value Optional. If the $key cannot be found the value to return. Default null.
107 107
      * @return 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
     /**
@@ -119,12 +119,12 @@  discard block
 block discarded – undo
119 119
      * @param  mixed         $default_value Optional. If the $key cannot be found the value to return. Default null.
120 120
      * @return mixed                        The value of the source for the given $key or the $default.
121 121
      */
122
-    public static function get_value_multiple_sources( $key, array $sources, $default_value = null )
122
+    public static function get_value_multiple_sources($key, array $sources, $default_value = null)
123 123
     {
124
-        foreach( $sources as $source )
124
+        foreach ($sources as $source)
125 125
         {
126
-            $value = self::get_request_value( $source, $key, null );
127
-            if( null !== $value )
126
+            $value = self::get_request_value($source, $key, null);
127
+            if (null !== $value)
128 128
             {
129 129
                 return $value;
130 130
             }
@@ -139,9 +139,9 @@  discard block
 block discarded – undo
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 POST for the given $key or the $default.
141 141
      */
142
-    public static function get_post_value_int( $key, $default_value = null )
142
+    public static function get_post_value_int($key, $default_value = null)
143 143
     {
144
-        return self::get_request_value_int( 'POST', $key, $default_value );
144
+        return self::get_request_value_int('POST', $key, $default_value);
145 145
     }
146 146
 
147 147
     /**
@@ -150,9 +150,9 @@  discard block
 block discarded – undo
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 GET for the given $key or the $default.
152 152
      */
153
-    public static function get_get_value_int( $key, $default_value = null )
153
+    public static function get_get_value_int($key, $default_value = null)
154 154
     {
155
-        return self::get_request_value_int( 'GET', $key, $default_value );
155
+        return self::get_request_value_int('GET', $key, $default_value);
156 156
     }
157 157
 
158 158
     /**
@@ -161,9 +161,9 @@  discard block
 block discarded – undo
161 161
      * @param  integer|mixed $default_value Optional. If the $key cannot be found the value to return. Default null.
162 162
      * @return integer|mixed                The value of the HTTP COOKIE for the given $key or the $default.
163 163
      */
164
-    public static function get_cookie_value_int( $key, $default_value = null )
164
+    public static function get_cookie_value_int($key, $default_value = null)
165 165
     {
166
-        return self::get_request_value_int( 'COOKIE', $key, $default_value );
166
+        return self::get_request_value_int('COOKIE', $key, $default_value);
167 167
     }
168 168
 
169 169
     /**
@@ -172,73 +172,73 @@  discard block
 block discarded – undo
172 172
      * @param  integer|mixed $default_value Optional. If the $key cannot be found the value to return. Default null.
173 173
      * @return integer|mixed                The value of the HTTP SERVER for the given $key or the $default.
174 174
      */
175
-    public static function get_server_value_int( $key, $default_value = null )
175
+    public static function get_server_value_int($key, $default_value = null)
176 176
     {
177
-        return self::get_request_value_int( 'SERVER', $key, $default_value );
177
+        return self::get_request_value_int('SERVER', $key, $default_value);
178 178
     }
179 179
 
180
-    public static function get_request_value_int( $request_method, $key, $default_value = null )
180
+    public static function get_request_value_int($request_method, $key, $default_value = null)
181 181
     {
182
-        $value = self::get_request_value( $request_method, $key, null );
183
-        if( self::is_integer_like( $value ) )
182
+        $value = self::get_request_value($request_method, $key, null);
183
+        if (self::is_integer_like($value))
184 184
         {
185
-            return (int)$value;
185
+            return (int) $value;
186 186
         }
187 187
 
188 188
         return $default_value;
189 189
     }
190 190
 
191
-    public static function get_request_value( $request_method, $key, $default_value = null )
191
+    public static function get_request_value($request_method, $key, $default_value = null)
192 192
     {
193
-        $request_obj = self::get_request_object( $request_method );
193
+        $request_obj = self::get_request_object($request_method);
194 194
 
195
-        if( null === $request_obj || ! is_array( $request_obj ) || ! array_key_exists( $key, $request_obj ) )
195
+        if (null === $request_obj || !is_array($request_obj) || !array_key_exists($key, $request_obj))
196 196
         {
197 197
             return $default_value;
198 198
         }
199 199
 
200
-        $ret = $request_obj[ $key ];
200
+        $ret = $request_obj[$key];
201 201
 
202
-        if( is_string( $ret ) )
202
+        if (is_string($ret))
203 203
         {
204
-            $ret = trim( $ret );
204
+            $ret = trim($ret);
205 205
         }
206 206
 
207 207
         return $ret;
208 208
     }
209 209
 
210
-    public static function get_request_object( $request_method )
210
+    public static function get_request_object($request_method)
211 211
     {
212 212
         $obj = null;
213
-        switch( $request_method )
213
+        switch ($request_method)
214 214
         {
215 215
             case 'GET':
216
-                if( is_array( self::$CUSTOM_GET ) )
216
+                if (is_array(self::$CUSTOM_GET))
217 217
                 {
218 218
                     return self::$CUSTOM_GET;
219 219
                 }
220
-                return ( isset( $_GET ) && is_array( $_GET ) && count( $_GET ) > 0 ? $_GET : null );
220
+                return (isset($_GET) && is_array($_GET) && count($_GET) > 0 ? $_GET : null);
221 221
 
222 222
             case 'POST':
223
-                if( is_array( self::$CUSTOM_POST ) )
223
+                if (is_array(self::$CUSTOM_POST))
224 224
                 {
225 225
                     return self::$CUSTOM_POST;
226 226
                 }
227
-                return ( isset( $_POST ) && is_array( $_POST ) && count( $_POST ) > 0 ? $_POST : null );
227
+                return (isset($_POST) && is_array($_POST) && count($_POST) > 0 ? $_POST : null);
228 228
 
229 229
             case 'COOKIE':
230
-                if( is_array( self::$CUSTOM_COOKIE ) )
230
+                if (is_array(self::$CUSTOM_COOKIE))
231 231
                 {
232 232
                     return self::$CUSTOM_COOKIE;
233 233
                 }
234
-                return ( isset( $_COOKIE ) && is_array( $_COOKIE ) && count( $_COOKIE ) > 0 ? $_COOKIE : null );
234
+                return (isset($_COOKIE) && is_array($_COOKIE) && count($_COOKIE) > 0 ? $_COOKIE : null);
235 235
 
236 236
             case 'SERVER':
237
-                if( is_array( self::$CUSTOM_SERVER ) )
237
+                if (is_array(self::$CUSTOM_SERVER))
238 238
                 {
239 239
                     return self::$CUSTOM_SERVER;
240 240
                 }
241
-                return ( isset( $_SERVER ) && is_array( $_SERVER ) && count( $_SERVER ) > 0 ? $_SERVER : null );
241
+                return (isset($_SERVER) && is_array($_SERVER) && count($_SERVER) > 0 ? $_SERVER : null);
242 242
 
243 243
             default:
244 244
                 return null;
@@ -251,9 +251,9 @@  discard block
 block discarded – undo
251 251
      * @param  string  $method The server method to test for. Generally one of GET, POST, HEAD, PUT, DELETE.
252 252
      * @return boolean         Returns true if the REQUEST_METHOD server variable is set to the supplied $method, otherwise false.
253 253
      */
254
-    public static function is_request_method( $method )
254
+    public static function is_request_method($method)
255 255
     {
256
-        return $method === self::get_server_value( 'REQUEST_METHOD' );
256
+        return $method === self::get_server_value('REQUEST_METHOD');
257 257
     }
258 258
 
259 259
     /**
@@ -268,7 +268,7 @@  discard block
 block discarded – undo
268 268
      */
269 269
     public static function is_post( )
270 270
     {
271
-        return self::is_request_method( 'POST' );
271
+        return self::is_request_method('POST');
272 272
     }
273 273
 
274 274
     /**
@@ -279,28 +279,28 @@  discard block
 block discarded – undo
279 279
      * @param  mixed  $input The value to test.
280 280
      * @return boolean       True if $input is an integer or a string that contains only digits possibly starting with a dash.
281 281
      */
282
-    public static function is_integer_like( $input )
282
+    public static function is_integer_like($input)
283 283
     {
284 284
         return
285
-                is_int( $input )
285
+                is_int($input)
286 286
                 ||
287 287
                 (
288
-                    is_string( $input )
288
+                    is_string($input)
289 289
                     &&
290
-                    preg_match( '/^-?([0-9])+$/', $input )
290
+                    preg_match('/^-?([0-9])+$/', $input)
291 291
                 );
292 292
     }
293 293
 
294 294
     public static function get_all_headers()
295 295
     {
296 296
         $headers = array();
297
-        foreach( array( '_SERVER', '_GET', '_POST', '_COOKIE', '_ENV' ) as $key )
297
+        foreach (array('_SERVER', '_GET', '_POST', '_COOKIE', '_ENV') as $key)
298 298
         {
299
-            if( array_key_exists( $key, $GLOBALS ) )
299
+            if (array_key_exists($key, $GLOBALS))
300 300
             {
301 301
 
302 302
             }
303
-            $headers[ $key ] = $GLOBALS[ $key ];
303
+            $headers[$key] = $GLOBALS[$key];
304 304
         }
305 305
         return $headers;
306 306
     }
@@ -313,17 +313,17 @@  discard block
 block discarded – undo
313 313
      * @param  array $parsed_url An array created by urlpieces.
314 314
      * @return string            A URL string.
315 315
      */
316
-    public static function unparse_url( $parsed_url ) {
316
+    public static function unparse_url($parsed_url) {
317 317
         //I don't know what you gave me so you can just have it back
318
-        if( ! is_array( $parsed_url ) ) {
318
+        if (!is_array($parsed_url)) {
319 319
             return $parsed_url;
320 320
         }
321
-        $scheme   = isset( $parsed_url['scheme'])    ?       $parsed_url['scheme'] . '://' : '';
322
-        $host     = isset( $parsed_url['host'] )     ?       $parsed_url['host']           : '';
323
-        $port     = isset( $parsed_url['port'] )     ? ':' . $parsed_url['port']           : '';
324
-        $path     = isset( $parsed_url['path'] )     ?       $parsed_url['path']           : '';
325
-        $query    = isset( $parsed_url['query'] )    ? '?' . $parsed_url['query']          : '';
326
-        $fragment = isset( $parsed_url['fragment'] ) ? '#' . $parsed_url['fragment']       : '';
321
+        $scheme   = isset($parsed_url['scheme']) ? $parsed_url['scheme'].'://' : '';
322
+        $host     = isset($parsed_url['host']) ? $parsed_url['host'] : '';
323
+        $port     = isset($parsed_url['port']) ? ':'.$parsed_url['port'] : '';
324
+        $path     = isset($parsed_url['path']) ? $parsed_url['path'] : '';
325
+        $query    = isset($parsed_url['query']) ? '?'.$parsed_url['query'] : '';
326
+        $fragment = isset($parsed_url['fragment']) ? '#'.$parsed_url['fragment'] : '';
327 327
 
328 328
         //NOTE: user and pass were explicitly removed.
329 329
 
Please login to merge, or discard this patch.