Completed
Push — develop ( e325e0...dabc0d )
by John
02:55
created

Request::getBody()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
c 0
b 0
f 0
dl 0
loc 4
rs 10
cc 1
eloc 2
nc 1
nop 0
1
<?php
2
3
namespace Alpha\Util\Http;
4
5
use Alpha\Exception\IllegalArguementException;
6
use Alpha\Util\Config\ConfigProvider;
7
8
/**
9
 * A class to encapsulate a HTTP request.
10
 *
11
 * @since 2.0
12
 *
13
 * @author John Collins <[email protected]>
14
 * @license http://www.opensource.org/licenses/bsd-license.php The BSD License
15
 * @copyright Copyright (c) 2017, John Collins (founder of Alpha Framework).
16
 * All rights reserved.
17
 *
18
 * <pre>
19
 * Redistribution and use in source and binary forms, with or
20
 * without modification, are permitted provided that the
21
 * following conditions are met:
22
 *
23
 * * Redistributions of source code must retain the above
24
 *   copyright notice, this list of conditions and the
25
 *   following disclaimer.
26
 * * Redistributions in binary form must reproduce the above
27
 *   copyright notice, this list of conditions and the
28
 *   following disclaimer in the documentation and/or other
29
 *   materials provided with the distribution.
30
 * * Neither the name of the Alpha Framework nor the names
31
 *   of its contributors may be used to endorse or promote
32
 *   products derived from this software without specific
33
 *   prior written permission.
34
 *
35
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
36
 * CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
37
 * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
38
 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
39
 * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
40
 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
41
 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
42
 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
43
 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
44
 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
45
 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
46
 * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
47
 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
48
 * </pre>
49
 */
50
class Request
51
{
52
    /**
53
     * Array of supported HTTP methods.
54
     *
55
     * @var array
56
     *
57
     * @since 2.0
58
     */
59
    private $HTTPMethods = array('HEAD', 'GET', 'POST', 'PUT', 'PATCH', 'DELETE', 'OPTIONS', 'TRACE');
60
61
    /**
62
     * The HTTP method of this request (must be in HTTPMethods array).
63
     *
64
     * @var string
65
     *
66
     * @since 2.0
67
     */
68
    private $method;
69
70
    /**
71
     * An associative array of HTTP headers on this request.
72
     *
73
     * @var array
74
     *
75
     * @since 2.0
76
     */
77
    private $headers;
78
79
    /**
80
     * An associative array of HTTP cookies on this request.
81
     *
82
     * @var array
83
     *
84
     * @since 2.0
85
     */
86
    private $cookies;
87
88
    /**
89
     * The HTTP params (form data and query string) on this request.
90
     *
91
     * @var array
92
     *
93
     * @since 2.0
94
     */
95
    private $params;
96
97
    /**
98
     * An associative 3D array of uploaded files.
99
     *
100
     * @var array
101
     *
102
     * @since 2.0
103
     */
104
    private $files;
105
106
    /**
107
     * The request body if one was provided.
108
     *
109
     * @var string
110
     *
111
     * @since 2.0
112
     */
113
    private $body;
114
115
    /**
116
     * The host header provided on the request.
117
     *
118
     * @var string
119
     *
120
     * @since 2.0
121
     */
122
    private $host;
123
124
    /**
125
     * The IP of the client making the request.
126
     *
127
     * @var string
128
     *
129
     * @since 2.0
130
     */
131
    private $IP;
132
133
    /**
134
     * The URI requested.
135
     *
136
     * @var string
137
     *
138
     * @since 2.0
139
     */
140
    private $URI;
141
142
    /**
143
     * The query string provided on the request (if any).
144
     *
145
     * @var string
146
     *
147
     * @since 2.0
148
     */
149
    private $queryString;
150
151
    /**
152
     * Builds up the request based on available PHP super globals, in addition to
153
     * any overrides provided (useful for testing).
154
     *
155
     * @param array $overrides Hash array of PHP super globals to override
156
     *
157
     * @throws \Alpha\Exception\IllegalArguementException
158
     *
159
     * @since 2.0
160
     */
161
    public function __construct($overrides = array())
0 ignored issues
show
Coding Style introduced by
__construct 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...
Coding Style introduced by
__construct 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...
Coding Style introduced by
__construct 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...
Coding Style introduced by
__construct 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...
Coding Style introduced by
__construct uses the super-global variable $_FILES 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...
162
    {
163
        // set HTTP headers
164
        if (isset($overrides['headers']) && is_array($overrides['headers'])) {
165
            $this->headers = $overrides['headers'];
166
        } else {
167
            $this->headers = $this->getGlobalHeaders();
168
        }
169
170
        // set HTTP method
171
        if (isset($overrides['method']) && in_array($overrides['method'], $this->HTTPMethods)) {
172
            $this->method = $overrides['method'];
173
        } else {
174
            $method = $this->getGlobalServerValue('REQUEST_METHOD');
175
            if (in_array($method, $this->HTTPMethods)) {
176
                $this->method = $method;
177
            }
178
        }
179
180
        // allow the POST param _METHOD to override the HTTP method
181
        if (isset($_POST['_METHOD']) && in_array($_POST['_METHOD'], $this->HTTPMethods)) {
182
            $this->method = $_POST['_METHOD'];
183
        }
184
185
        // allow the POST param X-HTTP-Method-Override to override the HTTP method
186
        if (isset($this->headers['X-HTTP-Method-Override']) && in_array($this->headers['X-HTTP-Method-Override'], $this->HTTPMethods)) {
187
            $this->method = $this->headers['X-HTTP-Method-Override'];
188
        }
189
190
        if ($this->method == '') {
191
            throw new IllegalArguementException('No valid HTTP method provided when creating new Request object');
192
        }
193
194
        // set HTTP cookies
195
        if (isset($overrides['cookies']) && is_array($overrides['cookies'])) {
196
            $this->cookies = $overrides['cookies'];
197
        } elseif (isset($_COOKIE)) {
198
            $this->cookies = $_COOKIE;
199
        } else {
200
            $this->cookies = array();
201
        }
202
203
        // set HTTP params
204
        if (isset($overrides['params']) && is_array($overrides['params'])) {
205
            $this->params = $overrides['params'];
206
        } else {
207
            $this->params = array();
208
209
            if (isset($_GET)) {
210
                $this->params = array_merge($this->params, $_GET);
211
            }
212
213
            if (isset($_POST)) {
214
                $this->params = array_merge($this->params, $_POST);
215
            }
216
        }
217
218
        // set HTTP body
219
        if (isset($overrides['body'])) {
220
            $this->body = $overrides['body'];
221
        } else {
222
            $this->body = $this->getGlobalBody();
223
        }
224
225
        // set HTTP host
226
        if (isset($overrides['host'])) {
227
            $this->host = $overrides['host'];
228
        } elseif (isset($_SERVER['HTTP_HOST'])) {
229
            $this->host = $_SERVER['HTTP_HOST'];
230
        } else {
231
            $this->host = 'localhost';
232
        }
233
234
        // set IP of the client
235
        if (isset($overrides['IP'])) {
236
            $this->IP = $overrides['IP'];
237
        } elseif (isset($_SERVER['REMOTE_ADDR'])) {
238
            $this->IP = $_SERVER['REMOTE_ADDR'];
239
        } else {
240
            $this->IP = '127.0.0.1';
241
        }
242
243
        // set requested URI
244
        if (isset($overrides['URI'])) {
245
            $this->URI = $overrides['URI'];
246
        } elseif (isset($_SERVER['REQUEST_URI'])) {
247
            $this->URI = $_SERVER['REQUEST_URI'];
248
        }
249
250
        // set uploaded files (if any)
251
        if (isset($overrides['files'])) {
252
            $this->files = $overrides['files'];
253
        } elseif (isset($_FILES)) {
254
            $this->files = $_FILES;
255
        }
256
    }
257
258
    /**
259
     * Tries to get the requested param from the $_SERVER super global, otherwise returns an
260
     * empty string.
261
     *
262
     * @return string
263
     *
264
     * @since 3.0
265
     */
266
    private function getGlobalServerValue($param)
0 ignored issues
show
Coding Style introduced by
getGlobalServerValue 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...
267
    {
268
        $server = $_SERVER;
269
270
        if (isset($server[$param])) {
271
            return $server[$param];
272
        } else {
273
            return '';
274
        }
275
    }
276
277
    /**
278
     * Get the HTTP method of this request.
279
     *
280
     * @return string
281
     *
282
     * @since 2.0
283
     */
284
    public function getMethod()
285
    {
286
        return $this->method;
287
    }
288
289
    /**
290
     * Set the HTTP method of this request.
291
     *
292
     * @param string $method
293
     *
294
     * @throws \Alpha\Exception\IllegalArguementException
295
     *
296
     * @since 2.0
297
     */
298
    public function setMethod($method)
299
    {
300
        if (in_array($method, $this->HTTPMethods)) {
301
            $this->method = $method;
302
        } else {
303
            throw new IllegalArguementException('The method provided ['.$method.'] is not valid!');
304
        }
305
    }
306
307
    /**
308
     * Return all headers on this request.
309
     *
310
     * @return array
311
     *
312
     * @since 2.0
313
     */
314
    public function getHeaders()
315
    {
316
        return $this->headers;
317
    }
318
319
    /**
320
     * Get the header matching the key provided.
321
     *
322
     * @param string $key     The key to search for
323
     * @param mixed  $default If key is not found, return this instead
324
     *
325
     * @return string
326
     *
327
     * @since 2.0
328
     */
329
    public function getHeader($key, $default = null)
330
    {
331
        if (array_key_exists($key, $this->headers)) {
332
            return $this->headers[$key];
333
        } else {
334
            return $default;
335
        }
336
    }
337
338
    /**
339
     * Tries to get the current HTTP request headers from super globals.
340
     *
341
     * @return array
342
     *
343
     * @since 2.0
344
     */
345
    private function getGlobalHeaders()
0 ignored issues
show
Coding Style introduced by
getGlobalHeaders 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...
346
    {
347
        if (!function_exists('getallheaders')) {
348
            $headers = array();
349
            foreach ($_SERVER as $name => $value) {
350
                if (substr($name, 0, 5) == 'HTTP_') {
351
                    $headers[str_replace(' ', '-', ucwords(strtolower(str_replace('_', ' ', substr($name, 5)))))] = $value;
352
                }
353
                if ($name == 'CONTENT_TYPE') {
354
                    $headers['Content-Type'] = $value;
355
                }
356
                if ($name == 'CONTENT_LENGTH') {
357
                    $headers['Content-Length'] = $value;
358
                }
359
            }
360
361
            return $headers;
362
        } else {
363
            return getallheaders();
364
        }
365
    }
366
367
    /**
368
     * Return all cookies on this request.
369
     *
370
     * @return array
371
     *
372
     * @since 2.0
373
     */
374
    public function getCookies()
375
    {
376
        return $this->cookies;
377
    }
378
379
    /**
380
     * Get the cookie matching the key provided.
381
     *
382
     * @param string $key     The key to search for
383
     * @param mixed  $default If key is not found, return this instead
384
     *
385
     * @return mixed
386
     *
387
     * @since 2.0
388
     */
389
    public function getCookie($key, $default = null)
390
    {
391
        if (array_key_exists($key, $this->cookies)) {
392
            return $this->cookies[$key];
393
        } else {
394
            return $default;
395
        }
396
    }
397
398
    /**
399
     * Return all params on this request.
400
     *
401
     * @return array
402
     *
403
     * @since 2.0
404
     */
405
    public function getParams()
406
    {
407
        return $this->params;
408
    }
409
410
    /**
411
     * Get the param matching the key provided.
412
     *
413
     * @param string $key     The key to search for
414
     * @param mixed  $default If key is not found, return this instead
415
     *
416
     * @return string
417
     *
418
     * @since 2.0
419
     */
420
    public function getParam($key, $default = null)
421
    {
422
        if (array_key_exists($key, $this->params)) {
423
            return $this->params[$key];
424
        } else {
425
            return $default;
426
        }
427
    }
428
429
    /**
430
     * Append the hash array provided to the params for this request.
431
     *
432
     * @param array A hash array of values to add to the request params
433
     *
434
     * @since 2.0
435
     */
436
    public function addParams($params)
437
    {
438
        if (is_array($params)) {
439
            $this->params = array_merge($this->params, $params);
440
        }
441
    }
442
443
    /**
444
     * Set the params array.
445
     *
446
     * @param array A hash array of values to set as the request params
447
     *
448
     * @since 2.0
449
     */
450
    public function setParams($params)
451
    {
452
        if (is_array($params)) {
453
            $this->params = $params;
454
        }
455
    }
456
457
    /**
458
     * Return all files on this request.
459
     *
460
     * @return array
461
     *
462
     * @since 2.0
463
     */
464
    public function getFiles()
465
    {
466
        return $this->files;
467
    }
468
469
    /**
470
     * Get the file matching the key provided.
471
     *
472
     * @param string $key     The key to search for
473
     * @param mixed  $default If key is not found, return this instead
474
     *
475
     * @return mixed
476
     *
477
     * @since 2.0
478
     */
479
    public function getFile($key, $default = null)
480
    {
481
        if (array_key_exists($key, $this->files)) {
482
            return $this->files[$key];
483
        } else {
484
            return $default;
485
        }
486
    }
487
488
    /**
489
     * Get the request body if one was provided.
490
     *
491
     * @return string
492
     *
493
     * @since 2.0
494
     */
495
    public function getBody()
496
    {
497
        return $this->body;
498
    }
499
500
    /**
501
     * Attempts to get the raw body of the current request from super globals.
502
     *
503
     * @return string
504
     *
505
     * @since 2.0
506
     */
507
    private function getGlobalBody()
0 ignored issues
show
Coding Style introduced by
getGlobalBody uses the super-global variable $GLOBALS 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...
508
    {
509
        if (isset($GLOBALS['HTTP_RAW_POST_DATA'])) {
510
            return $GLOBALS['HTTP_RAW_POST_DATA'];
511
        } else {
512
            return file_get_contents('php://input');
513
        }
514
    }
515
516
    /**
517
     * Get the Accept header of the request.
518
     *
519
     * @return string
520
     *
521
     * @since 2.0
522
     */
523
    public function getAccept()
524
    {
525
        return $this->getHeader('Accept');
526
    }
527
528
    /**
529
     * Get the Content-Type header of the request.
530
     *
531
     * @return string
532
     *
533
     * @since 2.0
534
     */
535
    public function getContentType()
536
    {
537
        return $this->getHeader('Content-Type');
538
    }
539
540
    /**
541
     * Get the Content-Length header of the request.
542
     *
543
     * @return string
544
     *
545
     * @since 2.0
546
     */
547
    public function getContentLength()
548
    {
549
        return $this->getHeader('Content-Length');
550
    }
551
552
    /**
553
     * Get the host name of the client that sent the request.
554
     *
555
     * @return string
556
     *
557
     * @since 2.0
558
     */
559
    public function getHost()
560
    {
561
        return $this->host;
562
    }
563
564
    /**
565
     * Get the URI that was requested.
566
     *
567
     * @return string
568
     *
569
     * @since 2.0
570
     */
571
    public function getURI()
572
    {
573
        return $this->URI;
574
    }
575
576
    /**
577
     * Get the URL that was requested.
578
     *
579
     * @return string
580
     *
581
     * @since 2.0
582
     */
583
    public function getURL()
584
    {
585
        $config = ConfigProvider::getInstance();
586
587
        return $config->get('app.url').$this->getURI();
588
    }
589
590
    /**
591
     * Get the IP address of the client that sent the request.
592
     *
593
     * @return string
594
     *
595
     * @since 2.0
596
     */
597
    public function getIP()
598
    {
599
        return $this->IP;
600
    }
601
602
    /**
603
     * Get the Referrer header of the request.
604
     *
605
     * @return string
606
     *
607
     * @since 2.0
608
     */
609
    public function getReferrer()
610
    {
611
        return $this->getHeader('Referrer');
612
    }
613
614
    /**
615
     * Get the User-Agent header of the request.
616
     *
617
     * @return string
618
     *
619
     * @since 2.0
620
     */
621
    public function getUserAgent()
622
    {
623
        return $this->getHeader('User-Agent');
624
    }
625
626
    /**
627
     * Get the query string provided on the request.
628
     *
629
     * @return string
630
     *
631
     * @since 2.0
632
     */
633
    public function getQueryString()
634
    {
635
        return $this->queryString;
636
    }
637
638
    /**
639
     * Parses the route provided to extract matching params of the route from this request's URI.
640
     *
641
     * @param string $route         The route with parameter names, e.g. /user/{username}
642
     * @param array  $defaultParams Optional hash array of default request param values to use if they are missing from URI
643
     *
644
     * @since 2.0
645
     */
646
    public function parseParamsFromRoute($route, $defaultParams = array())
647
    {
648
        // if the URI has a query-string, we will ignore it for now
649
        if (mb_strpos($this->URI, '?') !== false) {
650
            $URI = mb_substr($this->URI, 0, mb_strpos($this->URI, '?'));
651
652
            // let's take this opportunity to pass query string params to $this->params
653
            $queryString = mb_substr($this->URI, (mb_strpos($this->URI, '?')+1));
654
            $this->queryString = $queryString;
655
            parse_str($queryString, $this->params);
656
        } else {
657
            $URI = $this->URI;
658
        }
659
660
        $paramNames = explode('/', $route);
661
        $paramValues = explode('/', $URI);
662
663
        for ($i = 0; $i < count($paramNames); ++$i) {
0 ignored issues
show
Performance Best Practice introduced by
It seems like you are calling the size function count() as part of the test condition. You might want to compute the size beforehand, and not on each iteration.

If the size of the collection does not change during the iteration, it is generally a good practice to compute it beforehand, and not on each iteration:

for ($i=0; $i<count($array); $i++) { // calls count() on each iteration
}

// Better
for ($i=0, $c=count($array); $i<$c; $i++) { // calls count() just once
}
Loading history...
664
            $name = $paramNames[$i];
665
666
            if (!isset($this->params[trim($name, '{}')])) {
667
                if (isset($paramValues[$i]) && substr($name, 0, 1) == '{' && substr($name, strlen($name)-1, 1) == '}') {
668
                    $this->params[trim($name, '{}')] = $paramValues[$i];
669
                }
670
                if (!isset($paramValues[$i]) && isset($defaultParams[trim($name, '{}')])) {
671
                    $this->params[trim($name, '{}')] = $defaultParams[trim($name, '{}')];
672
                }
673
            }
674
        }
675
    }
676
677
    /**
678
     * Checks to see if the request contains a secure/encrypted token.
679
     *
680
     * @return bool
681
     *
682
     * @since 2.0
683
     */
684
    public function isSecureURI()
685
    {
686
        if (isset($this->params['act']) && mb_strpos($this->URI, '/tk/') !== false) {
687
            return true;
688
        } else {
689
            return false;
690
        }
691
    }
692
}
693