Router::run()   F
last analyzed

Complexity

Conditions 56
Paths 224

Size

Total Lines 196
Code Lines 103

Duplication

Lines 37
Ratio 18.88 %

Importance

Changes 0
Metric Value
dl 37
loc 196
rs 3.68
c 0
b 0
f 0
cc 56
eloc 103
nc 224
nop 0

How to fix   Long Method    Complexity   

Long Method

Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.

For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.

Commonly applied refactorings include:

1
<?php
2
3
/**
4
 * Router
5
 *
6
 * @category  	core
7
 * @package   	core\
8
 * @author    	Judicaël Paquet <[email protected]>
9
 * @copyright 	Copyright (c) 2013-2014 PAQUET Judicaël FR Inc. (https://github.com/las93)
10
 * @license   	https://github.com/las93/venus2/blob/master/LICENSE.md Tout droit réservé à PAQUET Judicaël
11
 * @version   	Release: 2.0.0
12
 * @filesource	https://github.com/las93/venus2
13
 * @link      	https://github.com/las93
14
 * @since     	2.0.0
15
 */
16
namespace Venus\core;
17
18
use \Venus\core\Security                as Security;
19
use \Venus\lib\Cache                    as Cache;
20
use \Venus\lib\Less                     as Less;
21
use \Venus\lib\PhpDoc                   as PhpDoc;
22
use \Venus\lib\Typescript               as Typescript;
23
use \Venus\lib\Request                  as Request;
24
use \Venus\lib\Vendor                   as Vendor;
25
use \Venus\core\UrlManager              as UrlManager;
26
use \Venus\lib\Debug                    as Debug;
27
use \Venus\lib\Log\LoggerAwareInterface as LoggerAwareInterface;
28
use \Venus\lib\Log\LoggerInterface      as LoggerInterface;
29
30
/**
31
 * Router
32
 *
33
 * @category  	core
34
 * @package   	core\
35
 * @author    	Judicaël Paquet <[email protected]>
36
 * @copyright 	Copyright (c) 2013-2014 PAQUET Judicaël FR Inc. (https://github.com/las93)
37
 * @license   	https://github.com/las93/venus2/blob/master/LICENSE.md Tout droit réservé à PAQUET Judicaël
38
 * @version   	Release: 2.0.0
39
 * @filesource	https://github.com/las93/venus2
40
 * @link      	https://github.com/las93
41
 * @since     	2.0.0
42
 */
43
class Router implements LoggerAwareInterface
44
{
45
    /**
46
     * The base Uri to construct the route
47
     *
48
     * @access private
49
     * @var    string
50
     */
51
    private $_sBaseUri = '';
52
53
    /**
54
     * get the security of page
55
     *
56
     * @access private
57
     * @var    \Venus\core\Security
58
     */
59
    private $_oSecurity = null;
60
61
    /**
62
     * The Routes of the actual host
63
     *
64
     * @access private
65
     * @var    object
66
     */
67
    private $_oRoutes = null;
68
69
    /**
70
     * Logger
71
     *
72
     * @access private
73
     * @var    object
74
     */
75
    private $_oLogger = null;
76
77
    /**
78
     * constructor
79
     *
80
     * @access public
81
     */
82
    public function __construct()
83
    {
84
        $oLogger = Debug::getInstance();
85
        $this->setLogger($oLogger);
86
    }
87
88
    /**
89
     * run the routeur
90
     *
91
     * @access public
92
     * @return null|boolean
93
     */
94
    public function run()
0 ignored issues
show
Coding Style introduced by
run 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
run 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...
95
    {
96
        date_default_timezone_set(Config::get('Const')->timezone);
97
98
        $this->_create_constant();
99
100
        if (Request::isHttpRequest()) {
101
        
102
            // Search if a Less file exists
103 View Code Duplication
            if (defined('LESS_ACTIVE') && LESS_ACTIVE === true) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
104
105
                if (strstr($_SERVER['REQUEST_URI'], '.css')
106
                    && file_exists(preg_replace('/\.css/', '.less', $_SERVER['REQUEST_URI']))) {
107
108
                    Less::toCss($_SERVER['REQUEST_URI']);
109
                    exit;
0 ignored issues
show
Coding Style Compatibility introduced by
The method run() contains an exit expression.

An exit expression should only be used in rare cases. For example, if you write a short command line script.

In most cases however, using an exit expression makes the code untestable and often causes incompatibilities with other libraries. Thus, unless you are absolutely sure it is required here, we recommend to refactor your code to avoid its usage.

Loading history...
110
                }
111
            }
112
113
            // Search if a typescript file exists
114 View Code Duplication
            if (defined('TYPESCRIPT_ACTIVE') && TYPESCRIPT_ACTIVE === true) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
115
116
                if (strstr($_SERVER['REQUEST_URI'], '.js')
117
                && file_exists(preg_replace('/\.js/', '.ts', $_SERVER['REQUEST_URI']))) {
118
119
                    Typescript::toJs($_SERVER['REQUEST_URI']);
120
                    exit;
0 ignored issues
show
Coding Style Compatibility introduced by
The method run() contains an exit expression.

An exit expression should only be used in rare cases. For example, if you write a short command line script.

In most cases however, using an exit expression makes the code untestable and often causes incompatibilities with other libraries. Thus, unless you are absolutely sure it is required here, we recommend to refactor your code to avoid its usage.

Loading history...
121
                }
122
            }
123
124
            // Search public files in all plugins
125
            if ($_SERVER['REQUEST_URI'] !== '/') {
126
127
                foreach (Config::get('Plugins')->list as $iKey => $sPlugin) {
128
129
                    if (file_exists(__DIR__.DIRECTORY_SEPARATOR.'..'.DIRECTORY_SEPARATOR.'src'.DIRECTORY_SEPARATOR.'plugins'.DIRECTORY_SEPARATOR.$sPlugin.DIRECTORY_SEPARATOR.'public'.$_SERVER['REQUEST_URI'])) {
130
131
                        echo file_get_contents(__DIR__.DIRECTORY_SEPARATOR.'..'.DIRECTORY_SEPARATOR.'src'.DIRECTORY_SEPARATOR.'plugins'.DIRECTORY_SEPARATOR.$sPlugin.DIRECTORY_SEPARATOR.'public'.$_SERVER['REQUEST_URI']);
132
                        exit;
0 ignored issues
show
Coding Style Compatibility introduced by
The method run() contains an exit expression.

An exit expression should only be used in rare cases. For example, if you write a short command line script.

In most cases however, using an exit expression makes the code untestable and often causes incompatibilities with other libraries. Thus, unless you are absolutely sure it is required here, we recommend to refactor your code to avoid its usage.

Loading history...
133
                    } else if (strstr($_SERVER['REQUEST_URI'], '.css')
134
                        && file_exists(__DIR__.DIRECTORY_SEPARATOR.'..'.DIRECTORY_SEPARATOR.'src'.DIRECTORY_SEPARATOR.'plugins'.DIRECTORY_SEPARATOR.$sPlugin.DIRECTORY_SEPARATOR.'public'.preg_replace('/\.css/', '.less', $_SERVER['REQUEST_URI']))) {
135
136
                        Less::toCss(__DIR__.DIRECTORY_SEPARATOR.'..'.DIRECTORY_SEPARATOR.'src'.DIRECTORY_SEPARATOR.'plugins'.DIRECTORY_SEPARATOR.$sPlugin.DIRECTORY_SEPARATOR.'public'.preg_replace('/\.css/', '.less', $_SERVER['REQUEST_URI']));
137
                        exit;
0 ignored issues
show
Coding Style Compatibility introduced by
The method run() contains an exit expression.

An exit expression should only be used in rare cases. For example, if you write a short command line script.

In most cases however, using an exit expression makes the code untestable and often causes incompatibilities with other libraries. Thus, unless you are absolutely sure it is required here, we recommend to refactor your code to avoid its usage.

Loading history...
138
                    } else if (strstr($_SERVER['REQUEST_URI'], '.js')
139
                        && file_exists(__DIR__.DIRECTORY_SEPARATOR.'..'.DIRECTORY_SEPARATOR.'src'.DIRECTORY_SEPARATOR.'plugins'.DIRECTORY_SEPARATOR.$sPlugin.DIRECTORY_SEPARATOR.'public'.preg_replace('/\.js/', '.ts', $_SERVER['REQUEST_URI']))) {
140
141
                        Typescript::toJs(__DIR__.DIRECTORY_SEPARATOR.'..'.DIRECTORY_SEPARATOR.'src'.DIRECTORY_SEPARATOR.'plugins'.DIRECTORY_SEPARATOR.$sPlugin.DIRECTORY_SEPARATOR.'public'.preg_replace('/\.js/', '.ts', $_SERVER['REQUEST_URI']));
142
                        exit;
0 ignored issues
show
Coding Style Compatibility introduced by
The method run() contains an exit expression.

An exit expression should only be used in rare cases. For example, if you write a short command line script.

In most cases however, using an exit expression makes the code untestable and often causes incompatibilities with other libraries. Thus, unless you are absolutely sure it is required here, we recommend to refactor your code to avoid its usage.

Loading history...
143
                    }
144
                }
145
            }
146
147
            foreach (Config::get('Route') as $sMultiHost => $oHost) {
0 ignored issues
show
Bug introduced by
The expression \Venus\core\Config::get('Route') of type null is not traversable.
Loading history...
148
149
                foreach (explode(',', $sMultiHost) as $sHost) {
150
151
                    if ((!strstr($sHost, '/') && $sHost == $_SERVER['HTTP_HOST']) || (strstr($sHost, '/')
152
                        && strstr($_SERVER['HTTP_HOST'].$_SERVER['REQUEST_URI'], $sHost))) {
153
    
154
                        $this->_oRoutes = $oHost;
155
156 View Code Duplication
                        if (strstr($sHost, '/')
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
157
                            && strstr($_SERVER['HTTP_HOST'].$_SERVER['REQUEST_URI'], $sHost)) {
158
159
                            $this->_sBaseUri = preg_replace('#^[^/]+#', '', $sHost);
160
                        }
161
    
162
                        if (isset($oHost->location)) {
163
    
164
                            header('Status: 301 Moved Permanently', false, 301);
165
                            header('Location: '.$oHost->location);
166
                            exit;
0 ignored issues
show
Coding Style Compatibility introduced by
The method run() contains an exit expression.

An exit expression should only be used in rare cases. For example, if you write a short command line script.

In most cases however, using an exit expression makes the code untestable and often causes incompatibilities with other libraries. Thus, unless you are absolutely sure it is required here, we recommend to refactor your code to avoid its usage.

Loading history...
167
                        } else if (preg_match('#getCss\?#', $_SERVER['REQUEST_URI'])) {
168
169 View Code Duplication
                            foreach ($_GET as $sKey => $sValue) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
170
171
                                if (file_exists(str_replace(DIRECTORY_SEPARATOR.'core', DIRECTORY_SEPARATOR.'src'.DIRECTORY_SEPARATOR, __DIR__).$sKey.'.css')) {
172
173
                                    echo file_get_contents(str_replace(DIRECTORY_SEPARATOR.'core', DIRECTORY_SEPARATOR.'src'.DIRECTORY_SEPARATOR, __DIR__).$sKey.'.css')."\n";
174
                                }
175
                            }
176
177
                            exit;
0 ignored issues
show
Coding Style Compatibility introduced by
The method run() contains an exit expression.

An exit expression should only be used in rare cases. For example, if you write a short command line script.

In most cases however, using an exit expression makes the code untestable and often causes incompatibilities with other libraries. Thus, unless you are absolutely sure it is required here, we recommend to refactor your code to avoid its usage.

Loading history...
178
                        } else if (preg_match('#getJs\?#', $_SERVER['REQUEST_URI'])) {
179
180 View Code Duplication
                            foreach ($_GET as $sKey => $sValue) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
181
182
                                if (file_exists(str_replace(DIRECTORY_SEPARATOR.'core', DIRECTORY_SEPARATOR.'src'.DIRECTORY_SEPARATOR, __DIR__).$sKey.'.js')) {
183
184
                                    echo file_get_contents(str_replace(DIRECTORY_SEPARATOR.'core', DIRECTORY_SEPARATOR.'src'.DIRECTORY_SEPARATOR, __DIR__).$sKey.'.js')."\n";
185
                                }
186
                            }
187
188
                            exit;
0 ignored issues
show
Coding Style Compatibility introduced by
The method run() contains an exit expression.

An exit expression should only be used in rare cases. For example, if you write a short command line script.

In most cases however, using an exit expression makes the code untestable and often causes incompatibilities with other libraries. Thus, unless you are absolutely sure it is required here, we recommend to refactor your code to avoid its usage.

Loading history...
189
                        } else if (isset($oHost->routes)) {
190
    
191
                            foreach ($oHost->routes as $sKey => $oRoute) {
192
193
                                $mReturn = $this->_route($oRoute, $_SERVER['REQUEST_URI']);
194
195
                                if ($mReturn === 403) {
196
    
197
                                    $this->_getPage403();
198
                                }
199
                                else if ($mReturn === true) {
200
    
201
                                    if (isset($oRoute->cache)) { $this->_checkCache($oRoute->cache); }
202
    
203
                                    return true;
204
                                }
205
                            }
206
    
207
                            $this->_getPage404();
208
                        }
209
                    }
210
                }
211
            }
212
        } else if (Request::isCliRequest()) {
213
214
            if (isset($_SERVER['argv'])) { $aArguments = $_SERVER['argv']; }
215
            else { $aArguments = []; }
216
217
            define('PORTAL', 'Batch');
218
            set_include_path(get_include_path().PATH_SEPARATOR.'src'.PATH_SEPARATOR.PORTAL.PATH_SEPARATOR.'public');
219
220
            if (!isset($aArguments[1]) && strstr($aArguments[0], '/phpunit')) {
221
222
                $sBatchName = "phpunit";
223
                $aArguments[0] = "bin/console";
224
                $aArguments[1] = "phpunit";
225
            } else if (isset($aArguments[1])) {
226
                $sBatchName = $aArguments[1];
227
            }
228
            else {
229
                $aArguments[1] = 'help';
230
                $sBatchName = $aArguments[1];
231
            }
232
233
            if (isset(Config::get('Route')->batch->script->{$sBatchName})) {
234
235
                $oBatch = Config::get('Route')->batch->script->{$sBatchName};
236
                array_shift($aArguments);
237
                array_shift($aArguments);
238
239
                $aOptions = array();
240
241
                while (count($aArguments) > 0) {
242
243
                    if (preg_match('/^-[a-z]/', $aArguments[0])) {
244
245
                        $sOptionName = str_replace('-', '', $aArguments[0]);
246
247
                        if (isset($aArguments[1])) {
248
                            $sOptionValue = $aArguments[1];
249
                        } else {
250
                            $sOptionValue = '';
251
                        }
252
253
                        if (isset($oBatch->options->$sOptionName) && isset($oBatch->options->$sOptionName->type)
254
                            && $oBatch->options->$sOptionName->type === false) {
255
256
                            $aOptions[$sOptionName] = true;
257
                            array_shift($aArguments);
258
                        } else if (isset($oBatch->options->$sOptionName) && isset($oBatch->options->$sOptionName->type)
259
                            && ($oBatch->options->$sOptionName->type === 'string'
260
                            || $oBatch->options->$sOptionName->type === 'int')
261
                        ) {
262
263
                            $aOptions[$sOptionName] = $sOptionValue;
264
                            array_shift($aArguments);
265
                            array_shift($aArguments);
266
                        } else {
267
268
                            array_shift($aArguments);
269
                        }
270
                    } else {
271
272
                        array_shift($aArguments);
273
                    }
274
                }
275
            }
276
277
            if (isset($oBatch->controller) && isset($oBatch->action)) {
278
279
                echo $this->_loadController($oBatch->controller, $oBatch->action, array($aOptions));
0 ignored issues
show
Bug introduced by
The variable $oBatch does not seem to be defined for all execution paths leading up to this point.

If you define a variable conditionally, it can happen that it is not defined for all execution paths.

Let’s take a look at an example:

function myFunction($a) {
    switch ($a) {
        case 'foo':
            $x = 1;
            break;

        case 'bar':
            $x = 2;
            break;
    }

    // $x is potentially undefined here.
    echo $x;
}

In the above example, the variable $x is defined if you pass “foo” or “bar” as argument for $a. However, since the switch statement has no default case statement, if you pass any other value, the variable $x would be undefined.

Available Fixes

  1. Check for existence of the variable explicitly:

    function myFunction($a) {
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
        }
    
        if (isset($x)) { // Make sure it's always set.
            echo $x;
        }
    }
    
  2. Define a default value for the variable:

    function myFunction($a) {
        $x = ''; // Set a default which gets overridden for certain paths.
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
        }
    
        echo $x;
    }
    
  3. Add a value for the missing path:

    function myFunction($a) {
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
    
            // We add support for the missing case.
            default:
                $x = '';
                break;
        }
    
        echo $x;
    }
    
Loading history...
Bug introduced by
The variable $aOptions does not seem to be defined for all execution paths leading up to this point.

If you define a variable conditionally, it can happen that it is not defined for all execution paths.

Let’s take a look at an example:

function myFunction($a) {
    switch ($a) {
        case 'foo':
            $x = 1;
            break;

        case 'bar':
            $x = 2;
            break;
    }

    // $x is potentially undefined here.
    echo $x;
}

In the above example, the variable $x is defined if you pass “foo” or “bar” as argument for $a. However, since the switch statement has no default case statement, if you pass any other value, the variable $x would be undefined.

Available Fixes

  1. Check for existence of the variable explicitly:

    function myFunction($a) {
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
        }
    
        if (isset($x)) { // Make sure it's always set.
            echo $x;
        }
    }
    
  2. Define a default value for the variable:

    function myFunction($a) {
        $x = ''; // Set a default which gets overridden for certain paths.
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
        }
    
        echo $x;
    }
    
  3. Add a value for the missing path:

    function myFunction($a) {
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
    
            // We add support for the missing case.
            default:
                $x = '';
                break;
        }
    
        echo $x;
    }
    
Loading history...
280
            } else {
281
282
                if (Request::isCliRequest()) {
283
284
                    echo "Error : The batch not exists - please verify your Route or the name passed in your command name.\n";
285
                }
286
            }
287
288
        }
289
    }
290
291
    /**
292
     * run the routeur by the forwarsd metho (in the controller)
293
     *
294
     * @access public
295
     * @param  string $sRoute route we wantload
296
     * @param  array $aParams parameters to passe
297
     * @return void
298
     */
299
    public function runByFoward(string $sRoute, array $aParams)
0 ignored issues
show
Coding Style introduced by
runByFoward 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...
300
    {
301
        $this->_create_constant();
302
303
        if (isset($_SERVER) && isset($_SERVER['HTTP_HOST'])) {
304
305
            foreach (Config::get('Route') as $sHost => $oHost) {
0 ignored issues
show
Bug introduced by
The expression \Venus\core\Config::get('Route') of type null is not traversable.
Loading history...
306
307
                if ((!strstr($sHost, '/') && $sHost == $_SERVER['HTTP_HOST'])
308
                    || (strstr($sHost, '/') && strstr($_SERVER['HTTP_HOST'].$_SERVER['REQUEST_URI'], $sHost))) {
309
310
                    $this->_oRoutes = $oHost;
311
312 View Code Duplication
                    if (strstr($sHost, '/') && strstr($_SERVER['HTTP_HOST'].$_SERVER['REQUEST_URI'], $sHost)) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
313
314
                        $this->_sBaseUri = preg_replace('#^[^/]+#', '', $sHost);
315
                    }
316
317
                    foreach ($oHost->routes as $sKey => $oRoute) {
318
319
                        $this->_route($oRoute, $sRoute);
320
                    }
321
                }
322
            }
323
        }
324
        else if (defined('STDIN')) {
325
326
            $oBatch = Config::get('Route')->batch->script->{$sRoute};
327
            echo $this->_loadController($oBatch->controller, $oBatch->action, $aParams);
328
        }
329
    }
330
331
    /**
332
     * run the error http page
333
     *
334
     * @access public
335
     * @param  int iError http error
336
     * @return void
337
     */
338
    public function runHttpErrorPage(int $iError)
0 ignored issues
show
Unused Code introduced by
The parameter $iError is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
Coding Style introduced by
runHttpErrorPage 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...
339
    {
340
        $this->_create_constant();
341
342
        if (isset($_SERVER) && isset($_SERVER['HTTP_HOST'])) {
343
344
            foreach (Config::get('Route') as $sHost => $oHost) {
0 ignored issues
show
Bug introduced by
The expression \Venus\core\Config::get('Route') of type null is not traversable.
Loading history...
345
346
                if ((!strstr($sHost, '/') && $sHost == $_SERVER['HTTP_HOST'])
347
                    || (strstr($sHost, '/') && strstr($_SERVER['HTTP_HOST'].$_SERVER['REQUEST_URI'], $sHost))) {
348
349
                    $this->_oRoutes = $oHost->routes;
350
351 View Code Duplication
                    if (strstr($sHost, '/') && strstr($_SERVER['HTTP_HOST'].$_SERVER['REQUEST_URI'], $sHost)) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
352
353
                        $this->_sBaseUri = preg_replace('#^[^/]+#', '', $sHost);
354
                    }
355
356
                    $sHttpErrorPageName = '_getPage'.iError;
357
                    $this->$sHttpErrorPageName();
358
                }
359
            }
360
        }
361
    }
362
363
    /**
364
     * load a route
365
     *
366
     * @access private
367
     * @param  \stdClass $oRoute one route
368
     * @param  string $RequestUri URI
369
     * @return void
370
     */
371
    private function _route(\stdClass $oRoute, string $RequestUri)
0 ignored issues
show
Coding Style introduced by
_route 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
_route 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
_route 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...
372
    {
373
        $sCharset = 'UTF-8';
374
375
        if (isset($oRoute->route)) {
376
377
            $sRoute = str_replace("*", ".*", $oRoute->route);
378
379
            $sFinalRoute = preg_replace_callback(
380
                '|\[/{0,1}:([a-zA-Z_]+)\]|',
381
                function($aMatches) use ($oRoute) {
382
                    return "/{0,1}(?P<".$aMatches[1].">".$oRoute->constraints->{$aMatches[1]}.")";
383
                },
384
                $sRoute
385
            );
386
        }
387
        else {
388
389
            $sFinalRoute = '.*';
390
        }
391
392
        $RequestUri = preg_replace('/^([^?]+)\?.*$/', '$1', $RequestUri);
393
        $RequestUri = preg_replace('#^'.$this->_sBaseUri.'#', '', $RequestUri);
394
395
        if (preg_match('#^'.$sFinalRoute.'$#', $RequestUri, $aMatch)) {
396
397
            if (isset($oRoute->location)) {
398
399
                $aParamEntries = array();
400
401
                foreach ($oRoute->constraints as $sName => $sType) {
402
403
                    if (isset($aMatch[$sName])) {
404
405
                        $aParamEntries[$sName] = $aMatch[$sName];
406
                    }
407
                }
408
409
                $oUrlManager = new UrlManager;
410
                header('Status: 301 Moved Permanently', false, 301);
411
                header('Location: '.$oUrlManager->getUrl($oRoute->location, $aParamEntries));
412
                exit;
0 ignored issues
show
Coding Style Compatibility introduced by
The method _route() contains an exit expression.

An exit expression should only be used in rare cases. For example, if you write a short command line script.

In most cases however, using an exit expression makes the code untestable and often causes incompatibilities with other libraries. Thus, unless you are absolutely sure it is required here, we recommend to refactor your code to avoid its usage.

Loading history...
413
            }
414
415
            $this->_oSecurity = new Security;
416
417
            if (!$this->_oSecurity->checkSecurity() !== null) { return 403; }
418
419
            // create the $_GET by the URL
420
421
            foreach ($aMatch as $mKey => $sResults) {
422
423
                if (is_string($mKey)) {
424
425
                    $_GET[$mKey] = $sResults;
426
                }
427
            }
428
429
            if (isset($oRoute->methods) && $oRoute->methods != $_SERVER['REQUEST_METHOD']) { return false; }
430
431
            if (isset($oRoute->schemes) && $oRoute->schemes == 'https' && !Request::isHttpsRequest()) { return false; }
432
433
            if (isset($oRoute->cache) && isset($oRoute->cache->max_age) && !isset($_GET['flush'])) {
434
435
                $oMobileDetect = new \Mobile_Detect;
436
437
                if ($oMobileDetect->isMobile()) { $sCacheExt = '.mobi'; }
438
                else { $sCacheExt = ''; }
439
440
                $mCacheReturn = Cache::get($RequestUri.$sCacheExt, $oRoute->cache->max_age);
441
442
                if ($mCacheReturn && count($_POST) < 1) {
443
444
                    echo $mCacheReturn;
445
                    return true;
446
                }
447
            }
448
449
            if (isset($oRoute->cache)) { $this->_checkCache($oRoute->cache); }
450
451
            if (isset($oRoute->controller)) {
452
453
                define('PORTAL', preg_replace('/^\\\\Venus\\\\src\\\\([a-zA-Z0-9_]+)\\\\.+$/', '$1', $oRoute->controller));
454
                set_include_path(get_include_path().PATH_SEPARATOR.'src'.PATH_SEPARATOR.PORTAL.PATH_SEPARATOR.'public');
455
456
                if (isset($oRoute->content_type)) {
457
458
                    if ($oRoute->content_type == 'json') {
459
460
                        header('Content-type: application/json; charset='.$sCharset.'');
461
                    } else if ($oRoute->content_type == 'html') {
462
463
                        header('Content-type: text/html; charset='.$sCharset.'');
464
                    } else if ($oRoute->content_type == 'jpeg') {
465
466
                        header('Content-type: image/jpeg');
467
                    }
468
                }
469
                else {
470
471
                    header('Content-type: text/html; charset='.$sCharset.'');
472
                }
473
474
                $sControllerName = $oRoute->controller;
475
                $sActionName = $oRoute->action;
476
477
                $oController = new $sControllerName;
478
479
                $aEntries = array();
480
481
                if (isset($oRoute->constraints) && is_object($oRoute->constraints)) {
482
483
                    $mReturn = null;
484
485
                    foreach ($oRoute->constraints as $sName => $sType) {
486
487
                        if (isset($_GET[$sName]) && $_GET[$sName] != '') {
488
489
                            $aEntries[] = $_GET[$sName];
490
                        } else if (isset($oRoute->defaults_constraints) && is_object($oRoute->defaults_constraints)
491
                            && isset($oRoute->defaults_constraints->{$sName})) {
492
493
                            $aEntries[] = $oRoute->defaults_constraints->{$sName};
494
                        } else if (isset($_GET[$sName])) {
495
496
                            $aEntries[] = $_GET[$sName];
497
                        } else if (preg_match('/'.$sType.'/', '')) {
498
499
                            $aEntries[] = '';
500
                        } else {
501
502
                            $this->_oLogger->warning('Error: Parameter '.$sName.' not exists!');
503
                            break;
504
                        }
505
                    }
506
507
                    if ($mReturn === null) {
508
509
                        $mReturn = $this->_loadController($oController, $sActionName, $aEntries);
510
511
                    }
512
                }
513
                else {
514
515
                    $mReturn = $this->_loadController($oController, $sActionName, $aEntries);
516
                }
517
518
                if (isset($oRoute->content_type)) {
519
520
                    if ($oRoute->content_type === 'json') {
521
522
                        $mReturn = json_encode($mReturn, JSON_PRETTY_PRINT);
523
                    }
524
                }
525
            }
526
            else if (isset($oRoute->template) && isset($oRoute->layout) && $oRoute->layout === true) {
527
528
                define('PORTAL', preg_replace('/^\\\\Venus\\\\src\\\\([a-zA-Z0-9_]+)\\\\.+$/', '$1', $oRoute->template));
529
                set_include_path(get_include_path().PATH_SEPARATOR.'src'.PATH_SEPARATOR.PORTAL.PATH_SEPARATOR.'public');
530
531
                $oLayout = Vendor::getVendor('Apollina\Template', DIRECTORY_SEPARATOR.'src'.DIRECTORY_SEPARATOR.PORTAL.DIRECTORY_SEPARATOR.'View'.DIRECTORY_SEPARATOR.'Layout.tpl');
532
533
                if (isset($oRoute->vars)) {
534
535
                    foreach ($oRoute->vars as $sKey => $mValue) {
536
537
                        $oLayout->assign($sKey, $mValue);
538
                    }
539
                }
540
541
                $mReturn = $oLayout->assign('model', DIRECTORY_SEPARATOR.'src'.DIRECTORY_SEPARATOR.PORTAL.DIRECTORY_SEPARATOR.'View'.DIRECTORY_SEPARATOR.$oRoute->template.'.tpl')
542
                                   ->fetch();
543
            }
544
            else if (isset($oRoute->template)) {
545
546
                define('PORTAL', preg_replace('/^\\\\Venus\\\\src\\\\([a-zA-Z0-9_]+)\\\\.+$/', '$1', $oRoute->template));
547
                set_include_path(get_include_path().PATH_SEPARATOR.'src'.PATH_SEPARATOR.PORTAL.PATH_SEPARATOR.'public');
548
549
                $oTemplate = Vendor::getVendor('Apollina\Template', DIRECTORY_SEPARATOR.'src'.DIRECTORY_SEPARATOR.PORTAL.DIRECTORY_SEPARATOR.'View'.DIRECTORY_SEPARATOR.$oRoute->template.'.tpl');
550
551
                if (isset($oRoute->vars)) {
552
553
                    foreach ($oRoute->vars as $sKey => $mValue) {
554
555
                        $oTemplate->assign($sKey, $mValue);
556
                    }
557
                }
558
559
                $mReturn = $oTemplate->fetch();
560
            }
561
562
            // management of return or cache of it
563
564
            if (isset($oRoute->cache) && isset($oRoute->cache->max_age) && $mReturn) {
565
566
                $oMobileDetect = new \Mobile_Detect;
567
568
                if ($oMobileDetect->isMobile()) { $sCacheExt = '.mobi'; }
569
                else { $sCacheExt = ''; }
570
571 View Code Duplication
                if (defined('COMPRESS_HTML') && COMPRESS_HTML) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
572
573
                    $mReturn = str_replace(array("\t", "\r", "  "), array("", "", " "), $mReturn);
0 ignored issues
show
Bug introduced by
The variable $mReturn does not seem to be defined for all execution paths leading up to this point.

If you define a variable conditionally, it can happen that it is not defined for all execution paths.

Let’s take a look at an example:

function myFunction($a) {
    switch ($a) {
        case 'foo':
            $x = 1;
            break;

        case 'bar':
            $x = 2;
            break;
    }

    // $x is potentially undefined here.
    echo $x;
}

In the above example, the variable $x is defined if you pass “foo” or “bar” as argument for $a. However, since the switch statement has no default case statement, if you pass any other value, the variable $x would be undefined.

Available Fixes

  1. Check for existence of the variable explicitly:

    function myFunction($a) {
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
        }
    
        if (isset($x)) { // Make sure it's always set.
            echo $x;
        }
    }
    
  2. Define a default value for the variable:

    function myFunction($a) {
        $x = ''; // Set a default which gets overridden for certain paths.
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
        }
    
        echo $x;
    }
    
  3. Add a value for the missing path:

    function myFunction($a) {
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
    
            // We add support for the missing case.
            default:
                $x = '';
                break;
        }
    
        echo $x;
    }
    
Loading history...
574
                }
575
576
                Cache::set($RequestUri.$sCacheExt, $mReturn, $oRoute->cache->max_age);
577
            }
578
579
            if ($mReturn) {
580
581
                echo $mReturn;
582
                return true;
583
            }
584
        }
585
    }
586
587
    /**
588
     * create the constants
589
     *
590
     * @access private
591
     * @return void
592
     */
593
    private function _create_constant()
594
    {
595
        foreach (Config::get('Const') as $sKey => $mValue) {
0 ignored issues
show
Bug introduced by
The expression \Venus\core\Config::get('Const') of type null is not traversable.
Loading history...
596
597
            if (is_string($mValue) || is_int($mValue) || is_float($mValue) || is_bool($mValue)) {
598
599
                define(strtoupper($sKey), $mValue);
600
            }
601
        }
602
    }
603
604
    /**
605
     * load the controller
606
     *
607
     * @access private
608
     * @param  object $oControllerName controller name
609
     * @param  string $sActionName method name
610
     * @param  array $aParams parameters
611
     * @return mixed
612
     */
613
    private function _loadController($oControllerName, string $sActionName, array $aParams = array())
614
    {
615
        $aPhpDoc = PhpDoc::getPhpDocOfMethod($oControllerName, $sActionName);
616
617
        if (isset($aPhpDoc['Cache'])) {
618
619
            if (!isset($aPhpDoc['Cache']['maxage'])) { $aPhpDoc['Cache']['maxage'] = 0; }
620
621
            $oMobileDetect = new \Mobile_Detect;
622
623
            if ($oMobileDetect->isMobile()) { $sCacheExt = '.mobi'; }
624
            else { $sCacheExt = ''; }
625
626
            $mCacheReturn = Cache::get($sActionName.$sCacheExt, $aPhpDoc['Cache']['maxage']);
627
628
            if ($mCacheReturn !== false) { return $mCacheReturn; }
629
        }
630
631
        if (isset($aPhpDoc['Secure'])) {
632
633
            if (isset($aPhpDoc['Secure']['roles']) && $this->_oSecurity->getUserRole() != $aPhpDoc['Secure']['roles']) {
634
635
                $this->_getPage403();
636
            }
637
        }
638
639
        $oController = new $oControllerName;
640
641
        ob_start();
642
643
        if (!defined('PORTAL')) { define('PORTAL', 'Batch'); }
644
645
        if (method_exists($oController, 'beforeExecuteRoute')) {
646
647
            call_user_func_array(array($oController, 'beforeExecuteRoute'), array());
648
        }
649
650
        $mReturnController = call_user_func_array(array($oController, $sActionName), $aParams);
651
652
        if (method_exists($oController, 'afterExecuteRoute')) {
653
654
            call_user_func_array(array($oController, 'afterExecuteRoute'), array());
655
        }
656
657
        $mReturn = ob_get_clean();
658
659
        if ($mReturn == '') { $mReturn = $mReturnController; }
660
661
        if (isset($aPhpDoc['Cache'])) {
662
663
            $oMobileDetect = new \Mobile_Detect;
664
665
            if ($oMobileDetect->isMobile()) { $sCacheExt = '.mobi'; }
666
            else { $sCacheExt = ''; }
667
668 View Code Duplication
            if (defined('COMPRESS_HTML') && COMPRESS_HTML) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
669
670
                $mReturn = str_replace(array("\t", "\r", "  "), array("", "", "", " "), $mReturn);
671
            }
672
673
            Cache::set($sActionName.$sCacheExt, $mReturn, $aPhpDoc['Cache']['maxage']);
674
        }
675
676
        return $mReturn;
677
    }
678
679
    /**
680
     * get the page 403
681
     *
682
     * @access private
683
     * @return void
684
     */
685 View Code Duplication
    private function _getPage403()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
Coding Style introduced by
_getPage403 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...
686
    {
687
        header("HTTP/1.0 403 Forbidden");
688
689
        if (isset($this->_oRoutes->e403)) {
690
691
            $this->_oRoutes->e403->route = '/';
692
            $_SERVER['REQUEST_URI'] = '/';
693
            $this->_route($this->_oRoutes->e403, $_SERVER['REQUEST_URI']);
694
        }
695
696
        exit;
0 ignored issues
show
Coding Style Compatibility introduced by
The method _getPage403() contains an exit expression.

An exit expression should only be used in rare cases. For example, if you write a short command line script.

In most cases however, using an exit expression makes the code untestable and often causes incompatibilities with other libraries. Thus, unless you are absolutely sure it is required here, we recommend to refactor your code to avoid its usage.

Loading history...
697
    }
698
699
    /**
700
     * get the page 404
701
     *
702
     * @access private
703
     * @return void
704
     */
705 View Code Duplication
    private function _getPage404()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
Coding Style introduced by
_getPage404 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...
706
    {
707
        header("HTTP/1.0 404 Not Found");
708
709
        if (isset($this->_oRoutes->e404)) {
710
711
            $this->_oRoutes->e404->route = '/';
712
            $_SERVER['REQUEST_URI'] = '/';
713
            $this->_route($this->_oRoutes->e404, $_SERVER['REQUEST_URI']);
714
        }
715
716
        exit;
0 ignored issues
show
Coding Style Compatibility introduced by
The method _getPage404() contains an exit expression.

An exit expression should only be used in rare cases. For example, if you write a short command line script.

In most cases however, using an exit expression makes the code untestable and often causes incompatibilities with other libraries. Thus, unless you are absolutely sure it is required here, we recommend to refactor your code to avoid its usage.

Loading history...
717
    }
718
719
    /**
720
     * check the cache - just if it's not yet defined
721
     *
722
     * @access private
723
     * @param  \stdClass $oCache object of cache configuration
724
     * @return void
725
     */
726
    private function _checkCache(\stdClass $oCache)
727
    {
728
        /**
729
         * cache-control http
730
         */
731
732
        $sHearderValidity = false;
733
        $sHeader = "Cache-Control:";
734
735
        if (isset($oCache->visibility) && ($oCache->visibility = 'public' || $oCache->visibility = 'private')) {
0 ignored issues
show
Comprehensibility introduced by
Consider adding parentheses for clarity. Current Interpretation: $oCache->visibility = ('...isibility = 'private')), Probably Intended Meaning: ($oCache->visibility = '...>visibility = 'private'
Loading history...
736
737
            $sHearderValidity = true;
738
            $sHeader .= " ".$oCache->visibility.",";
739
        }
740
741
        if (isset($oCache->max_age)) {
742
743
            $sHearderValidity = true;
744
            $sHeader .= " maxage=".$oCache->max_age.",";
745
        }
746
747
        if (isset($oCache->must_revalidate) && $oCache->must_revalidate === true) {
748
749
            $sHearderValidity = true;
750
            $sHeader .= " must-revalidate,";
751
        }
752
753
        if ($sHearderValidity === true) {
754
755
            $sHeader = substr($sHeader, 0, -1);
756
757
            if (!headers_sent()) { header($sHeader); }
758
        }
759
760
        /**
761
         * ETag http
762
         */
763
764
        if (isset($oCache->ETag)) { header("ETag: \"".$oCache->ETag."\""); }
765
766
        /**
767
         * expire
768
         */
769
770 View Code Duplication
        if (isset($oCache->max_age)) { if (!headers_sent()) { header('Expires: '.gmdate('D, d M Y H:i:s', time() + $oCache->max_age).' GMT'); } }
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
771
772
        /**
773
         * Last-Modified http
774
         */
775
776 View Code Duplication
        if (isset($oCache->last_modified)) { if (!headers_sent()) { header('Last-Modified: '.gmdate('D, d M Y H:i:s', time() + $oCache->last_modified).' GMT'); } }
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
777
778
        /**
779
         * vary http
780
         */
781
782
        if (isset($oCache->vary)) { header('Vary: '.$oCache->vary); }
783
    }
784
785
    /**
786
     * Sets a logger instance on the object
787
     *
788
     * @access private
789
     * @param  LoggerInterface $logger
790
     * @return null
791
     */
792
    public function setLogger(LoggerInterface $logger) {
793
794
        $this->_oLogger = $logger;
795
    }
796
}
797