CheckPoint::__construct()   A
last analyzed

Complexity

Conditions 3
Paths 2

Size

Total Lines 13

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 13
rs 9.8333
c 0
b 0
f 0
cc 3
nc 2
nop 1
1
<?php
2
/**
3
 * @copyright Copyright (c) 2015 Oleksandr Torosh (http://yonastudio.com)
4
 * @author Oleksandr Torosh <[email protected]>
5
 *
6
 * Костыль для переадресаций index.php, index.html на соотв. роуты, пример: '/index.php/news' -> '/news'
7
 * Данное решение было сделано для облегчения настройки веб-сервера и выполнения SEO-требований
8
 */
9
namespace YonaCMS\Plugin;
10
11
use Phalcon\Http\Request;
12
13
class CheckPoint
14
{
15
16
    public function __construct(Request $request)
17
    {
18
        if (strpos($request->getURI(), 'index.php') || strpos($request->getURI(), 'index.html')) {
19
            header('HTTP/1.0 301 Moved Permanently');
20
            $replaced_url = str_replace(
21
                ['index.php/', 'index.php', 'index.html'],
22
                ['', '', ''],
23
                str_replace('?', '', $request->getURI())
24
            );
25
            header('Location: http://' . $request->getHttpHost() . $replaced_url);
26
            exit(0);
27
        }
28
    }
29
30
}