GitHub Access Token became invalid

It seems like the GitHub access token used for retrieving details about this repository from GitHub became invalid. This might prevent certain types of inspections from being run (in particular, everything related to pull requests).
Please ask an admin of your repository to re-new the access token on this website.
Completed
Push — master ( ee2d44...c597f0 )
by やかみ
03:11
created

Request::isCli()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 0
Metric Value
cc 1
eloc 2
c 0
b 0
f 0
nc 1
nop 0
dl 0
loc 4
ccs 2
cts 2
cp 1
crap 1
rs 10
1
<?php
2
/**
3
 * Kotori.php
4
 *
5
 * A Tiny Model-View-Controller PHP Framework
6
 *
7
 * This content is released under the Apache 2 License
8
 *
9
 * Copyright (c) 2015-2017 Kotori Technology. All rights reserved.
10
 *
11
 * Licensed under the Apache License, Version 2.0 (the "License");
12
 * you may not use this file except in compliance with the License.
13
 * You may obtain a copy of the License at
14
 *
15
 *     http://www.apache.org/licenses/LICENSE-2.0
16
 *
17
 * Unless required by applicable law or agreed to in writing, software
18
 * distributed under the License is distributed on an "AS IS" BASIS,
19
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
20
 * See the License for the specific language governing permissions and
21
 * limitations under the License.
22
 */
23
24
/**
25
 * Request Class
26
 *
27
 * @package     Kotori
28
 * @subpackage  Http
29
 * @author      Kokororin
30
 * @link        https://kotori.love
31
 */
32
namespace Kotori\Http;
33
34
use Kotori\Debug\Hook;
35
36
class Request
37
{
38
    /**
39
     * Ip address
40
     *
41
     * @var mixed
42
     */
43
    protected $_ip = null;
44
45
    /**
46
     * Class constructor
47
     *
48
     * Initialize Request.
49
     *
50
     * @return void
0 ignored issues
show
Comprehensibility Best Practice introduced by
Adding a @return annotation to constructors is generally not recommended as a constructor does not have a meaningful return value.

Adding a @return annotation to a constructor is not recommended, since a constructor does not have a meaningful return value.

Please refer to the PHP core documentation on constructors.

Loading history...
51
     */
52 9
    public function __construct()
53
    {
54 9
        Hook::listen(__CLASS__);
55 9
    }
56
57
    /**
58
     * Internal method used to retrieve values from given arrays.
59
     *
60
     * @param  array $source
61
     * @param  mixed $key
62
     * @param  mixed $default
63
     * @return mixed
64
     */
65
    protected function getRequestParams(&$source, $key = null, $default = null)
66
    {
67
        // If $key is NULL, it means that the whole $source is requested
68
        if (!isset($key) || $key == null) {
69
            $key = array_keys($source);
70
        }
71
72
        if (is_array($key)) {
73
            $output = [];
74
            foreach ($key as $k) {
75
                $output[$k] = $this->getRequestParams($source, $k);
76
            }
77
78
            return $output;
79
        }
80
81
        if (isset($source[$key])) {
82
            $value = $source[$key];
83
        } else {
84
            return $default;
85
        }
86
87
        return $value;
88
89
    }
90
91
    /**
92
     * Fetch an item from the GET array
93
     *
94
     * @param  mixed $key
95
     * @return mixed
96
     */
97
    public function get($key = null, $default = null)
0 ignored issues
show
Coding Style introduced by
get uses the super-global variable $_GET which is generally not recommended.

Instead of super-globals, we recommend to explicitly inject the dependencies of your class. This makes your code less dependent on global state and it becomes generally more testable:

// Bad
class Router
{
    public function generate($path)
    {
        return $_SERVER['HOST'].$path;
    }
}

// Better
class Router
{
    private $host;

    public function __construct($host)
    {
        $this->host = $host;
    }

    public function generate($path)
    {
        return $this->host.$path;
    }
}

class Controller
{
    public function myAction(Request $request)
    {
        // Instead of
        $page = isset($_GET['page']) ? intval($_GET['page']) : 1;

        // Better (assuming you use the Symfony2 request)
        $page = $request->query->get('page', 1);
    }
}
Loading history...
98
    {
99
        return $this->getRequestParams($_GET, $key, $default);
100
    }
101
102
    /**
103
     * Fetch an item from the POST array
104
     *
105
     * @param  mixed $key
106
     * @param  mixed $default
107
     * @return mixed
108
     */
109
    public function post($key = null, $default = null)
0 ignored issues
show
Coding Style introduced by
post uses the super-global variable $_POST which is generally not recommended.

Instead of super-globals, we recommend to explicitly inject the dependencies of your class. This makes your code less dependent on global state and it becomes generally more testable:

// Bad
class Router
{
    public function generate($path)
    {
        return $_SERVER['HOST'].$path;
    }
}

// Better
class Router
{
    private $host;

    public function __construct($host)
    {
        $this->host = $host;
    }

    public function generate($path)
    {
        return $this->host.$path;
    }
}

class Controller
{
    public function myAction(Request $request)
    {
        // Instead of
        $page = isset($_GET['page']) ? intval($_GET['page']) : 1;

        // Better (assuming you use the Symfony2 request)
        $page = $request->query->get('page', 1);
    }
}
Loading history...
110
    {
111
        $rawPostData = file_get_contents('php://input');
112
        $source = json_decode($rawPostData, true);
113
        if (json_last_error() != JSON_ERROR_NONE) {
114
            $source = $_POST;
115
        }
116
117
        return $this->getRequestParams($source, $key, $default);
118
    }
119
120
    /**
121
     * Fetch an item from the SERVER array
122
     *
123
     * @param  mixed $key
124
     * @param  mixed $default
125
     * @return mixed
126
     */
127
    public function server($key = null, $default = null)
0 ignored issues
show
Coding Style introduced by
server uses the super-global variable $_SERVER which is generally not recommended.

Instead of super-globals, we recommend to explicitly inject the dependencies of your class. This makes your code less dependent on global state and it becomes generally more testable:

// Bad
class Router
{
    public function generate($path)
    {
        return $_SERVER['HOST'].$path;
    }
}

// Better
class Router
{
    private $host;

    public function __construct($host)
    {
        $this->host = $host;
    }

    public function generate($path)
    {
        return $this->host.$path;
    }
}

class Controller
{
    public function myAction(Request $request)
    {
        // Instead of
        $page = isset($_GET['page']) ? intval($_GET['page']) : 1;

        // Better (assuming you use the Symfony2 request)
        $page = $request->query->get('page', 1);
    }
}
Loading history...
128
    {
129
        return $this->getRequestParams($_SERVER, $key, $default);
130
    }
131
132
    /**
133
     * Set or Get cookie
134
     *
135
     * @param  mixed  $key
136
     * @param  string $value
137
     * @param  mixed  $options
138
     * @return mixed
139
     */
140 2
    public function cookie($key = '', $value = '', $options = null)
0 ignored issues
show
Coding Style introduced by
cookie uses the super-global variable $_COOKIE which is generally not recommended.

Instead of super-globals, we recommend to explicitly inject the dependencies of your class. This makes your code less dependent on global state and it becomes generally more testable:

// Bad
class Router
{
    public function generate($path)
    {
        return $_SERVER['HOST'].$path;
    }
}

// Better
class Router
{
    private $host;

    public function __construct($host)
    {
        $this->host = $host;
    }

    public function generate($path)
    {
        return $this->host.$path;
    }
}

class Controller
{
    public function myAction(Request $request)
    {
        // Instead of
        $page = isset($_GET['page']) ? intval($_GET['page']) : 1;

        // Better (assuming you use the Symfony2 request)
        $page = $request->query->get('page', 1);
    }
}
Loading history...
141
    {
142
        $defaultOptions = [
143 2
            'prefix' => '',
144
            'expire' => 86400,
145
            'path' => '/',
146
            'secure' => false,
147
            'httponly' => false,
148
        ];
149
150 2
        if (!is_null($options)) {
151
            if (is_numeric($options)) {
152
                $options = ['expire' => $options];
153
            } elseif (is_string($options)) {
154
                parse_str($options, $options);
155
            }
156
157
            $options = array_merge($defaultOptions, array_change_key_case($options));
158
        }
159
160 2
        if (!empty($options['httponly'])) {
161
            ini_set('session.cookie_httponly', 1);
162
        }
163
164 2
        if (is_null($key)) {
165
            if (empty($_COOKIE)) {
166
                return null;
167
            }
168
169
            $prefix = empty($value) ? $options['prefix'] : $value;
170
            if (!empty($prefix)) {
171
                foreach ($_COOKIE as $key => $val) {
172
                    if (0 === stripos($key, $prefix)) {
173
                        setcookie($key, '', time() - 3600, $options['path'], $options['domain'], $options['secure'], $options['httponly']);
174
                        unset($_COOKIE[$key]);
175
                    }
176
                }
177
            }
178
179
            return null;
180 2
        } elseif ('' === $key) {
181
            // Get All Cookie
182
            return $_COOKIE;
183
        }
184
185 2
        $key = $options['prefix'] . str_replace('.', '_', $key);
186 2
        if ('' === $value) {
187 2
            if (isset($_COOKIE[$key])) {
188 1
                $value = $_COOKIE[$key];
189 1
                if (0 === strpos($value, 'kotori:')) {
190
                    $value = substr($value, 6);
191
                    return array_map('urldecode', json_decode(MAGIC_QUOTES_GPC ? stripslashes($value) : $value, true));
192
                } else {
193 1
                    return $value;
194
                }
195
            } else {
196 1
                return null;
197
            }
198
        } else {
199 2
            if (is_null($value)) {
200 1
                setcookie($key, '', time() - 3600, $options['path'], $options['domain'], $options['secure'], $options['httponly']);
201 1
                unset($_COOKIE[$key]); // Delete Cookie
202
            } else {
203
                // Set Cookie
204 2
                if (is_array($value)) {
205
                    $value = 'kotori:' . json_encode(array_map('urlencode', $value));
206
                }
207
208 2
                $expire = !empty($options['expire']) ? time() + intval($options['expire']) : 0;
209 2
                setcookie($key, $value, $expire, $options['path'], $options['domain'], $options['secure'], $options['httponly']);
210 2
                $_COOKIE[$key] = $value;
211
            }
212
        }
213
214 2
        return null;
215
    }
216
217
    /**
218
     * Set or Get session
219
     *
220
     * @param  mixed  $key
221
     * @param  string $value
222
     * @return mixed
223
     */
224 2
    public function session($key = '', $value = '')
0 ignored issues
show
Coding Style introduced by
session uses the super-global variable $_SESSION which is generally not recommended.

Instead of super-globals, we recommend to explicitly inject the dependencies of your class. This makes your code less dependent on global state and it becomes generally more testable:

// Bad
class Router
{
    public function generate($path)
    {
        return $_SERVER['HOST'].$path;
    }
}

// Better
class Router
{
    private $host;

    public function __construct($host)
    {
        $this->host = $host;
    }

    public function generate($path)
    {
        return $this->host.$path;
    }
}

class Controller
{
    public function myAction(Request $request)
    {
        // Instead of
        $page = isset($_GET['page']) ? intval($_GET['page']) : 1;

        // Better (assuming you use the Symfony2 request)
        $page = $request->query->get('page', 1);
    }
}
Loading history...
225
    {
226 2
        if (is_null($key)) {
227
            if (empty($_SESSION)) {
228
                return null;
229
            }
230
231
            unset($_SESSION);
232 2
        } elseif ('' === $key) {
233
            // Get All Session
234
            return $_SESSION;
235
        }
236
237 2
        if ('' === $value) {
238 2
            return isset($_SESSION[$key]) ? $_SESSION[$key] : null;
239
        } else {
240 2
            if (is_null($value)) {
241 1
                unset($_SESSION[$key]);
242
            } else {
243 2
                $_SESSION[$key] = $value;
244
            }
245
        }
246
247 2
        return null;
248
    }
249
250
    /**
251
     * Is HTTPS?
252
     *
253
     * Determines if the application is accessed via an encrypted
254
     * (HTTPS) connection.
255
     *
256
     * @return  boolean
257
     */
258 2
    public function isSecure()
0 ignored issues
show
Coding Style introduced by
isSecure uses the super-global variable $_SERVER which is generally not recommended.

Instead of super-globals, we recommend to explicitly inject the dependencies of your class. This makes your code less dependent on global state and it becomes generally more testable:

// Bad
class Router
{
    public function generate($path)
    {
        return $_SERVER['HOST'].$path;
    }
}

// Better
class Router
{
    private $host;

    public function __construct($host)
    {
        $this->host = $host;
    }

    public function generate($path)
    {
        return $this->host.$path;
    }
}

class Controller
{
    public function myAction(Request $request)
    {
        // Instead of
        $page = isset($_GET['page']) ? intval($_GET['page']) : 1;

        // Better (assuming you use the Symfony2 request)
        $page = $request->query->get('page', 1);
    }
}
Loading history...
259
    {
260 2
        if (!empty($_SERVER['HTTPS']) && strtolower($_SERVER['HTTPS']) !== 'off') {
261
            return true;
262 2
        } elseif (isset($_SERVER['HTTP_X_FORWARDED_PROTO']) && 'https' === $_SERVER['HTTP_X_FORWARDED_PROTO']) {
263
            return true;
264 2
        } elseif (!empty($_SERVER['HTTP_FRONT_END_HTTPS']) && strtolower($_SERVER['HTTP_FRONT_END_HTTPS']) !== 'off') {
265
            return true;
266
        }
267
268 2
        return false;
269
    }
270
271
    /**
272
     * Base URL
273
     *
274
     * Returns base url
275
     *
276
     * @return string
277
     */
278 1
    public function getBaseUrl()
0 ignored issues
show
Coding Style introduced by
getBaseUrl uses the super-global variable $_SERVER which is generally not recommended.

Instead of super-globals, we recommend to explicitly inject the dependencies of your class. This makes your code less dependent on global state and it becomes generally more testable:

// Bad
class Router
{
    public function generate($path)
    {
        return $_SERVER['HOST'].$path;
    }
}

// Better
class Router
{
    private $host;

    public function __construct($host)
    {
        $this->host = $host;
    }

    public function generate($path)
    {
        return $this->host.$path;
    }
}

class Controller
{
    public function myAction(Request $request)
    {
        // Instead of
        $page = isset($_GET['page']) ? intval($_GET['page']) : 1;

        // Better (assuming you use the Symfony2 request)
        $page = $request->query->get('page', 1);
    }
}
Loading history...
279
    {
280 1
        if (isset($_SERVER['HTTP_HOST']) && preg_match('/^((\[[0-9a-f:]+\])|(\d{1,3}(\.\d{1,3}){3})|[a-z0-9\-\.]+)(:\d+)?$/i', $_SERVER['HTTP_HOST'])) {
281 1
            $base_url = ($this->isSecure() ? 'https' : 'http') . '://' . $_SERVER['HTTP_HOST']
282 1
            . substr($_SERVER['SCRIPT_NAME'], 0, strpos($_SERVER['SCRIPT_NAME'], basename($_SERVER['SCRIPT_FILENAME'])));
283
        } else {
284
            $base_url = 'http://localhost/';
285
        }
286
287 1
        return rtrim($base_url, '/') . '/';
288
    }
289
290
    /**
291
     * Returns Client Ip Address
292
     *
293
     * @param  int     $type
294
     * @return string
295
     */
296 1
    public function getClientIp($type = 0)
0 ignored issues
show
Coding Style introduced by
getClientIp uses the super-global variable $_SERVER which is generally not recommended.

Instead of super-globals, we recommend to explicitly inject the dependencies of your class. This makes your code less dependent on global state and it becomes generally more testable:

// Bad
class Router
{
    public function generate($path)
    {
        return $_SERVER['HOST'].$path;
    }
}

// Better
class Router
{
    private $host;

    public function __construct($host)
    {
        $this->host = $host;
    }

    public function generate($path)
    {
        return $this->host.$path;
    }
}

class Controller
{
    public function myAction(Request $request)
    {
        // Instead of
        $page = isset($_GET['page']) ? intval($_GET['page']) : 1;

        // Better (assuming you use the Symfony2 request)
        $page = $request->query->get('page', 1);
    }
}
Loading history...
297
    {
298 1
        $type = $type ? 1 : 0;
299
300 1
        if ($this->_ip !== null) {
301
            return $this->_ip[$type];
302
        }
303
304 1
        if (isset($_SERVER['HTTP_CF_CONNECTING_IP'])) {
305
            $this->_ip = $_SERVER['HTTP_CF_CONNECTING_IP'];
306 1
        } elseif (isset($_SERVER['HTTP_X_FORWARDED_FOR'])) {
307
            $arr = explode(',', $_SERVER['HTTP_X_FORWARDED_FOR']);
308
            $pos = array_search('unknown', $arr);
309
            if (false !== $pos) {
310
                unset($arr[$pos]);
311
            }
312
313
            $this->_ip = trim($arr[0]);
314 1
        } elseif (isset($_SERVER['HTTP_CLIENT_IP'])) {
315
            $this->_ip = $_SERVER['HTTP_CLIENT_IP'];
316 1
        } elseif (isset($_SERVER['REMOTE_ADDR'])) {
317 1
            $this->_ip = $_SERVER['REMOTE_ADDR'];
318
        }
319
320
        // Check ip
321 1
        $long = sprintf("%u", ip2long($this->_ip));
322 1
        $this->_ip = $long ? [$this->_ip, $long] : ['0.0.0.0', 0];
323 1
        return $this->_ip[$type];
324
    }
325
326
    /**
327
     * Returns Http Host
328
     *
329
     * @return string
330
     */
331 1
    public function getHostName()
0 ignored issues
show
Coding Style introduced by
getHostName uses the super-global variable $_SERVER which is generally not recommended.

Instead of super-globals, we recommend to explicitly inject the dependencies of your class. This makes your code less dependent on global state and it becomes generally more testable:

// Bad
class Router
{
    public function generate($path)
    {
        return $_SERVER['HOST'].$path;
    }
}

// Better
class Router
{
    private $host;

    public function __construct($host)
    {
        $this->host = $host;
    }

    public function generate($path)
    {
        return $this->host.$path;
    }
}

class Controller
{
    public function myAction(Request $request)
    {
        // Instead of
        $page = isset($_GET['page']) ? intval($_GET['page']) : 1;

        // Better (assuming you use the Symfony2 request)
        $page = $request->query->get('page', 1);
    }
}
Loading history...
332
    {
333 1
        $possibleHostSources = ['HTTP_X_FORWARDED_HOST', 'HTTP_HOST', 'SERVER_NAME', 'SERVER_ADDR'];
334
        $sourceTransformations = [
335 1
            "HTTP_X_FORWARDED_HOST" => function ($value) {
336
                $elements = explode(',', $value);
337
                return trim(end($elements));
338 1
            },
339
        ];
340 1
        $host = '';
341 1
        foreach ($possibleHostSources as $source) {
342 1
            if (!empty($host)) {
343 1
                break;
344
            }
345
346 1
            if (empty($_SERVER[$source])) {
347 1
                continue;
348
            }
349
350 1
            $host = $_SERVER[$source];
351 1
            if (array_key_exists($source, $sourceTransformations)) {
352 1
                $host = $sourceTransformations[$source]($host);
353
            }
354
        }
355
356
        // Remove port number from host
357 1
        $host = preg_replace('/:\d+$/', '', $host);
358
359 1
        return trim($host);
360
    }
361
362
    /**
363
     * Detect whether request method is GET
364
     *
365
     * @return boolean
366
     */
367
    public function isGet()
0 ignored issues
show
Coding Style introduced by
isGet uses the super-global variable $_SERVER which is generally not recommended.

Instead of super-globals, we recommend to explicitly inject the dependencies of your class. This makes your code less dependent on global state and it becomes generally more testable:

// Bad
class Router
{
    public function generate($path)
    {
        return $_SERVER['HOST'].$path;
    }
}

// Better
class Router
{
    private $host;

    public function __construct($host)
    {
        $this->host = $host;
    }

    public function generate($path)
    {
        return $this->host.$path;
    }
}

class Controller
{
    public function myAction(Request $request)
    {
        // Instead of
        $page = isset($_GET['page']) ? intval($_GET['page']) : 1;

        // Better (assuming you use the Symfony2 request)
        $page = $request->query->get('page', 1);
    }
}
Loading history...
368
    {
369
        return 'GET' == $_SERVER['REQUEST_METHOD'];
370
    }
371
372
    /**
373
     * Detect whether request method is POST
374
     *
375
     * @return boolean
376
     */
377
    public function isPost()
0 ignored issues
show
Coding Style introduced by
isPost uses the super-global variable $_SERVER which is generally not recommended.

Instead of super-globals, we recommend to explicitly inject the dependencies of your class. This makes your code less dependent on global state and it becomes generally more testable:

// Bad
class Router
{
    public function generate($path)
    {
        return $_SERVER['HOST'].$path;
    }
}

// Better
class Router
{
    private $host;

    public function __construct($host)
    {
        $this->host = $host;
    }

    public function generate($path)
    {
        return $this->host.$path;
    }
}

class Controller
{
    public function myAction(Request $request)
    {
        // Instead of
        $page = isset($_GET['page']) ? intval($_GET['page']) : 1;

        // Better (assuming you use the Symfony2 request)
        $page = $request->query->get('page', 1);
    }
}
Loading history...
378
    {
379
        return 'POST' == $_SERVER['REQUEST_METHOD'];
380
    }
381
382
    /**
383
     * Detect whether request method is PUT
384
     *
385
     * @return boolean
386
     */
387
    public function isPut()
0 ignored issues
show
Coding Style introduced by
isPut uses the super-global variable $_SERVER which is generally not recommended.

Instead of super-globals, we recommend to explicitly inject the dependencies of your class. This makes your code less dependent on global state and it becomes generally more testable:

// Bad
class Router
{
    public function generate($path)
    {
        return $_SERVER['HOST'].$path;
    }
}

// Better
class Router
{
    private $host;

    public function __construct($host)
    {
        $this->host = $host;
    }

    public function generate($path)
    {
        return $this->host.$path;
    }
}

class Controller
{
    public function myAction(Request $request)
    {
        // Instead of
        $page = isset($_GET['page']) ? intval($_GET['page']) : 1;

        // Better (assuming you use the Symfony2 request)
        $page = $request->query->get('page', 1);
    }
}
Loading history...
388
    {
389
        return 'PUT' == $_SERVER['REQUEST_METHOD'];
390
    }
391
392
    /**
393
     * Detect whether request method is AJAX
394
     *
395
     * @return boolean
396
     */
397
    public function isAjax()
0 ignored issues
show
Coding Style introduced by
isAjax uses the super-global variable $_SERVER which is generally not recommended.

Instead of super-globals, we recommend to explicitly inject the dependencies of your class. This makes your code less dependent on global state and it becomes generally more testable:

// Bad
class Router
{
    public function generate($path)
    {
        return $_SERVER['HOST'].$path;
    }
}

// Better
class Router
{
    private $host;

    public function __construct($host)
    {
        $this->host = $host;
    }

    public function generate($path)
    {
        return $this->host.$path;
    }
}

class Controller
{
    public function myAction(Request $request)
    {
        // Instead of
        $page = isset($_GET['page']) ? intval($_GET['page']) : 1;

        // Better (assuming you use the Symfony2 request)
        $page = $request->query->get('page', 1);
    }
}
Loading history...
398
    {
399
        return ((isset($_SERVER['HTTP_X_REQUESTED_WITH']) && strtolower($_SERVER['HTTP_X_REQUESTED_WITH']) == 'xmlhttprequest')) ? true : false;
400
    }
401
402
    /**
403
     * Is CLI?
404
     *
405
     * Test to see if a request was made from the command line.
406
     *
407
     * @return  boolean
408
     */
409 3
    public function isCli()
410
    {
411 3
        return PHP_SAPI === 'cli';
412
    }
413
414
    /**
415
     * Detect whether user agent is Mobile
416
     *
417
     * @return boolean
418
     */
419 1
    public function isMobile()
0 ignored issues
show
Coding Style introduced by
isMobile uses the super-global variable $_SERVER which is generally not recommended.

Instead of super-globals, we recommend to explicitly inject the dependencies of your class. This makes your code less dependent on global state and it becomes generally more testable:

// Bad
class Router
{
    public function generate($path)
    {
        return $_SERVER['HOST'].$path;
    }
}

// Better
class Router
{
    private $host;

    public function __construct($host)
    {
        $this->host = $host;
    }

    public function generate($path)
    {
        return $this->host.$path;
    }
}

class Controller
{
    public function myAction(Request $request)
    {
        // Instead of
        $page = isset($_GET['page']) ? intval($_GET['page']) : 1;

        // Better (assuming you use the Symfony2 request)
        $page = $request->query->get('page', 1);
    }
}
Loading history...
420
    {
421 1
        $userAgent = isset($_SERVER['USER_AGENT']) ? $_SERVER['USER_AGENT'] : null;
422 1
        if ($userAgent == null) {
423 1
            return false;
424
        }
425
426
        return preg_match('/android.+mobile|avantgo|bada\/|blackberry|blazer|compal|elaine|fennec|hiptop|iemobile|ip(hone|od)|iris|kindle|lge |maemo|midp|mmp|netfront|opera m(ob|in)i|palm( os)?|phone|p(ixi|re)\/|plucker|pocket|psp|symbian|treo|up\.(browser|link)|vodafone|wap|windows (ce|phone)|xda|xiino/i', $userAgent) || preg_match('/1207|6310|6590|3gso|4thp|50[1-6]i|770s|802s|a wa|abac|ac(er|oo|s\-)|ai(ko|rn)|al(av|ca|co)|amoi|an(ex|ny|yw)|aptu|ar(ch|go)|as(te|us)|attw|au(di|\-m|r |s )|avan|be(ck|ll|nq)|bi(lb|rd)|bl(ac|az)|br(e|v)w|bumb|bw\-(n|u)|c55\/|capi|ccwa|cdm\-|cell|chtm|cldc|cmd\-|co(mp|nd)|craw|da(it|ll|ng)|dbte|dc\-s|devi|dica|dmob|do(c|p)o|ds(12|\-d)|el(49|ai)|em(l2|ul)|er(ic|k0)|esl8|ez([4-7]0|os|wa|ze)|fetc|fly(\-|_)|g1 u|g560|gene|gf\-5|g\-mo|go(\.w|od)|gr(ad|un)|haie|hcit|hd\-(m|p|t)|hei\-|hi(pt|ta)|hp( i|ip)|hs\-c|ht(c(\-| |_|a|g|p|s|t)|tp)|hu(aw|tc)|i\-(20|go|ma)|i230|iac( |\-|\/)|ibro|idea|ig01|ikom|im1k|inno|ipaq|iris|ja(t|v)a|jbro|jemu|jigs|kddi|keji|kgt( |\/)|klon|kpt |kwc\-|kyo(c|k)|le(no|xi)|lg( g|\/(k|l|u)|50|54|\-[a-w])|libw|lynx|m1\-w|m3ga|m50\/|ma(te|ui|xo)|mc(01|21|ca)|m\-cr|me(di|rc|ri)|mi(o8|oa|ts)|mmef|mo(01|02|bi|de|do|t(\-| |o|v)|zz)|mt(50|p1|v )|mwbp|mywa|n10[0-2]|n20[2-3]|n30(0|2)|n50(0|2|5)|n7(0(0|1)|10)|ne((c|m)\-|on|tf|wf|wg|wt)|nok(6|i)|nzph|o2im|op(ti|wv)|oran|owg1|p800|pan(a|d|t)|pdxg|pg(13|\-([1-8]|c))|phil|pire|pl(ay|uc)|pn\-2|po(ck|rt|se)|prox|psio|pt\-g|qa\-a|qc(07|12|21|32|60|\-[2-7]|i\-)|qtek|r380|r600|raks|rim9|ro(ve|zo)|s55\/|sa(ge|ma|mm|ms|ny|va)|sc(01|h\-|oo|p\-)|sdk\/|se(c(\-|0|1)|47|mc|nd|ri)|sgh\-|shar|sie(\-|m)|sk\-0|sl(45|id)|sm(al|ar|b3|it|t5)|so(ft|ny)|sp(01|h\-|v\-|v )|sy(01|mb)|t2(18|50)|t6(00|10|18)|ta(gt|lk)|tcl\-|tdg\-|tel(i|m)|tim\-|t\-mo|to(pl|sh)|ts(70|m\-|m3|m5)|tx\-9|up(\.b|g1|si)|utst|v400|v750|veri|vi(rg|te)|vk(40|5[0-3]|\-v)|vm40|voda|vulc|vx(52|53|60|61|70|80|81|83|85|98)|w3c(\-| )|webc|whit|wi(g |nc|nw)|wmlb|wonu|x700|yas\-|your|zeto|zte\-/i', substr($userAgent, 0, 4));
427
    }
428
}
429