1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/** |
4
|
|
|
* This file is part of the Zemit Framework. |
5
|
|
|
* |
6
|
|
|
* (c) Zemit Team <[email protected]> |
7
|
|
|
* |
8
|
|
|
* For the full copyright and license information, please view the LICENSE.txt |
9
|
|
|
* file that was distributed with this source code. |
10
|
|
|
*/ |
11
|
|
|
|
12
|
|
|
namespace Zemit\Bootstrap; |
13
|
|
|
|
14
|
|
|
use Phalcon\Config\ConfigInterface; |
15
|
|
|
|
16
|
|
|
/** |
17
|
|
|
* Zemit Router |
18
|
|
|
* {@inheritDoc} |
19
|
|
|
*/ |
20
|
|
|
class Router extends \Zemit\Mvc\Router |
21
|
|
|
{ |
22
|
|
|
public array $defaults = [ |
23
|
|
|
'namespace' => \Zemit\Modules\Frontend\Controller::class, |
24
|
|
|
'module' => 'frontend', |
25
|
|
|
'controller' => 'index', |
26
|
|
|
'action' => 'index', |
27
|
|
|
]; |
28
|
|
|
|
29
|
|
|
public array $notFound = [ |
30
|
|
|
'controller' => 'error', |
31
|
|
|
'action' => 'notFound', |
32
|
|
|
]; |
33
|
|
|
|
34
|
|
|
/** |
35
|
|
|
* Router constructor. |
36
|
|
|
*/ |
37
|
|
|
public function __construct($defaultRoutes = true, ?ConfigInterface $config = null) |
38
|
|
|
{ |
39
|
|
|
parent::__construct($defaultRoutes, $config); |
40
|
|
|
} |
41
|
|
|
|
42
|
|
|
public function baseRoutes(): void |
43
|
|
|
{ |
44
|
|
|
$this->add('/', [ |
45
|
|
|
])->setName('default'); |
46
|
|
|
|
47
|
|
|
$this->add('/:controller', [ |
48
|
|
|
'controller' => 1, |
49
|
|
|
])->setName('default-controller'); |
50
|
|
|
|
51
|
|
|
$this->add('/:controller/:action/:params', [ |
52
|
|
|
'controller' => 1, |
53
|
|
|
'action' => 2, |
54
|
|
|
'params' => 3, |
55
|
|
|
])->setName('default-controller-action'); |
56
|
|
|
|
57
|
|
|
$localeConfig = $this->getConfig()->get('locale')->toArray(); |
58
|
|
|
|
59
|
|
|
if (!empty($localeConfig['allowed'])) { |
60
|
|
|
$localeRegex = '{locale:(' . implode('|', $localeConfig['allowed']) . ')}'; |
61
|
|
|
|
62
|
|
|
$this->add('/' . $localeRegex, [ |
63
|
|
|
'locale' => 1, |
64
|
|
|
])->setName('locale'); |
65
|
|
|
|
66
|
|
|
$this->add('/' . $localeRegex . '/:controller', [ |
67
|
|
|
'locale' => 1, |
68
|
|
|
'controller' => 2, |
69
|
|
|
])->setName('locale-controller'); |
70
|
|
|
|
71
|
|
|
$this->add('/' . $localeRegex . '/:controller/:action/:params', [ |
72
|
|
|
'locale' => 1, |
73
|
|
|
'controller' => 2, |
74
|
|
|
'action' => 3, |
75
|
|
|
'params' => 4, |
76
|
|
|
])->setName('locale-controller-action'); |
77
|
|
|
} |
78
|
|
|
|
79
|
|
|
foreach ($localeConfig['allowed'] as $locale) { |
80
|
|
|
$localeRegex = $locale; |
81
|
|
|
|
82
|
|
|
$this->add('/' . $localeRegex, [ |
83
|
|
|
'locale' => $locale, |
84
|
|
|
])->setName($locale); |
85
|
|
|
|
86
|
|
|
$this->add('/' . $localeRegex . '/:controller', [ |
87
|
|
|
'locale' => $locale, |
88
|
|
|
'controller' => 1, |
89
|
|
|
])->setName($locale . '-controller'); |
90
|
|
|
|
91
|
|
|
$this->add('/' . $localeRegex . '/:controller/:action/:params', [ |
92
|
|
|
'locale' => $locale, |
93
|
|
|
'controller' => 1, |
94
|
|
|
'action' => 2, |
95
|
|
|
'params' => 3, |
96
|
|
|
])->setName($locale . '-controller-action'); |
97
|
|
|
} |
98
|
|
|
} |
99
|
|
|
} |
100
|
|
|
|