Completed
Push — master ( e9b1ca...cbd317 )
by Henry
07:52
created

Router::autorun()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 5
ccs 3
cts 3
cp 1
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 0
crap 1
1
<?php
2
namespace Redaxscript\Bootstrap;
3
4
use Redaxscript\Router as BaseRouter;
5
use function in_array;
6
use function is_array;
7
8
/**
9
 * children class to boot the router
10
 *
11
 * @since 3.1.0
12
 *
13
 * @package Redaxscript
14
 * @category Bootstrap
15
 * @author Henry Ruhs
16
 */
17
18
class Router extends BootstrapAbstract
19
{
20
	/**
21
	 * automate run
22
	 *
23
	 * @since 3.1.0
24 3
	 */
25
26 3
	public function autorun()
27 3
	{
28 3
		$this->_setParameter();
29
		$this->_setRoute();
30
	}
31
32
	/**
33
	 * set the parameter
34
	 *
35
	 * @since 3.1.0
36 3
	 */
37
38 3
	protected function _setParameter()
39 3
	{
40
		$parameter = new BaseRouter\Parameter($this->_request);
41
		$parameter->init();
42
43 3
		/* set the registry */
44 3
45 3
		$this->_registry->set('firstParameter', $parameter->getFirst());
46 3
		$this->_registry->set('firstSubParameter', $parameter->getFirstSub());
47 3
		$this->_registry->set('secondParameter', $parameter->getSecond());
48 3
		$this->_registry->set('secondSubParameter', $parameter->getSecondSub());
49 3
		$this->_registry->set('thirdParameter', $parameter->getThird());
50
		$this->_registry->set('thirdSubParameter', $parameter->getThirdSub());
51 1
		if ($this->_registry->get('loggedIn') === $this->_registry->get('token') && $this->_registry->get('firstParameter') === 'admin')
52 1
		{
53 1
			$this->_registry->set('adminParameter', $parameter->getAdmin());
54 1
			$this->_registry->set('tableParameter', $parameter->getTable());
55
			$this->_registry->set('idParameter', $parameter->getId());
56 3
			$this->_registry->set('aliasParameter', $parameter->getAlias());
57 3
		}
58 3
		$this->_registry->set('lastParameter', $parameter->getLast());
59 3
		$this->_registry->set('lastSubParameter', $parameter->getLastSub());
60
		$this->_registry->set('tokenParameter', $parameter->getToken());
61
	}
62
63
	/**
64
	 * set the route
65
	 *
66
	 * @since 3.1.0
67 3
	 */
68
69 3
	protected function _setRoute()
70 3
	{
71 3
		$moduleArray = $this->_registry->get('moduleArray');
72 3
		$file = $this->_registry->get('file');
73 3
		$doRewrite = is_array($moduleArray) && in_array('mod_rewrite', $moduleArray) && $file === 'index.php';
74
		$resolver = new BaseRouter\Resolver($this->_request);
75
		$resolver->init();
76
77 3
		/* set the registry */
78 3
79 3
		$this->_registry->set('liteRoute', $resolver->getLite());
80 3
		$this->_registry->set('fullRoute', $resolver->getFull());
81 3
		$this->_registry->set('parameterRoute', $doRewrite ? '' : '?p=');
82 3
		$this->_registry->set('languageRoute', $doRewrite ? '.' : '&l=');
83
		$this->_registry->set('templateRoute', $doRewrite ? '.' : '&t=');
84
	}
85
}
86