|
1
|
|
|
<?php |
|
2
|
|
|
/** |
|
3
|
|
|
* @author Alexander Torosh <[email protected]> |
|
4
|
|
|
*/ |
|
5
|
|
|
|
|
6
|
|
|
namespace Web; |
|
7
|
|
|
|
|
8
|
|
|
use Phalcon\Di\AbstractInjectionAware; |
|
9
|
|
|
use Phalcon\Di\DiInterface; |
|
10
|
|
|
use Phalcon\Events\Manager; |
|
11
|
|
|
use Phalcon\Mvc\Router as PhalconRouter; |
|
12
|
|
|
use Phalcon\Mvc\Router\Group; |
|
13
|
|
|
|
|
14
|
|
|
class Router extends AbstractInjectionAware |
|
15
|
|
|
{ |
|
16
|
|
|
// @var $router Router |
|
17
|
|
|
private $router; |
|
18
|
|
|
|
|
19
|
|
|
public function __construct(DiInterface $container, Manager $eventsManager) |
|
20
|
|
|
{ |
|
21
|
|
|
$this->setDI($container); |
|
22
|
|
|
$this->init(); |
|
23
|
|
|
$this->router->setEventsManager($eventsManager); |
|
24
|
|
|
} |
|
25
|
|
|
|
|
26
|
|
|
/** |
|
27
|
|
|
* @return mixed |
|
28
|
|
|
*/ |
|
29
|
|
|
public function getRouter(): PhalconRouter |
|
30
|
|
|
{ |
|
31
|
|
|
return $this->router; |
|
32
|
|
|
} |
|
33
|
|
|
|
|
34
|
|
|
private function init() |
|
35
|
|
|
{ |
|
36
|
|
|
$router = new PhalconRouter(); |
|
37
|
|
|
$router |
|
38
|
|
|
->setDefaultModule('front') |
|
39
|
|
|
->setDefaultController('index') |
|
40
|
|
|
->setDefaultAction('index') |
|
41
|
|
|
; |
|
42
|
|
|
|
|
43
|
|
|
// Frontend Router Groups |
|
44
|
|
|
$router->mount($this->frontIndex()); |
|
45
|
|
|
|
|
46
|
|
|
// Backend Router Groups |
|
47
|
|
|
$router->mount($this->dashboardIndex()); |
|
48
|
|
|
$router->mount($this->dashboardAuth()); |
|
49
|
|
|
|
|
50
|
|
|
$this->router = $router; |
|
51
|
|
|
} |
|
52
|
|
|
|
|
53
|
|
|
private function frontIndex(): Group |
|
54
|
|
|
{ |
|
55
|
|
|
$group = new Group([ |
|
56
|
|
|
'controller' => 'index', |
|
57
|
|
|
]); |
|
58
|
|
|
$group->setPrefix('/'); |
|
59
|
|
|
|
|
60
|
|
|
$group->add('', ['action' => 'index'])->setName('homepage'); |
|
61
|
|
|
|
|
62
|
|
|
return $group; |
|
63
|
|
|
} |
|
64
|
|
|
|
|
65
|
|
View Code Duplication |
private function dashboardIndex(): Group |
|
66
|
|
|
{ |
|
67
|
|
|
$group = new Group([ |
|
68
|
|
|
'module' => 'dashboard', |
|
69
|
|
|
'controller' => 'index', |
|
70
|
|
|
]); |
|
71
|
|
|
$group->setPrefix('/dashboard'); |
|
72
|
|
|
|
|
73
|
|
|
$group->addGet('', ['action' => 'index'])->setName('dashboardIndex'); |
|
74
|
|
|
|
|
75
|
|
|
return $group; |
|
76
|
|
|
} |
|
77
|
|
|
|
|
78
|
|
View Code Duplication |
private function dashboardAuth(): Group |
|
79
|
|
|
{ |
|
80
|
|
|
$group = new Group([ |
|
81
|
|
|
'module' => 'dashboard', |
|
82
|
|
|
'controller' => 'auth', |
|
83
|
|
|
]); |
|
84
|
|
|
$group->setPrefix('/dashboard/auth'); |
|
85
|
|
|
|
|
86
|
|
|
$group->addGet('/login', ['action' => 'login'])->setName('dashboardLogin'); |
|
87
|
|
|
|
|
88
|
|
|
return $group; |
|
89
|
|
|
} |
|
90
|
|
|
} |
|
91
|
|
|
|