|
1
|
|
|
<?php |
|
2
|
|
|
/* |
|
3
|
|
|
* MikoPBX - free phone system for small business |
|
4
|
|
|
* Copyright (C) 2017-2020 Alexey Portnov and Nikolay Beketov |
|
5
|
|
|
* |
|
6
|
|
|
* This program is free software: you can redistribute it and/or modify |
|
7
|
|
|
* it under the terms of the GNU General Public License as published by |
|
8
|
|
|
* the Free Software Foundation; either version 3 of the License, or |
|
9
|
|
|
* (at your option) any later version. |
|
10
|
|
|
* |
|
11
|
|
|
* This program is distributed in the hope that it will be useful, |
|
12
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
13
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
14
|
|
|
* GNU General Public License for more details. |
|
15
|
|
|
* |
|
16
|
|
|
* You should have received a copy of the GNU General Public License along with this program. |
|
17
|
|
|
* If not, see <https://www.gnu.org/licenses/>. |
|
18
|
|
|
*/ |
|
19
|
|
|
|
|
20
|
|
|
declare(strict_types=1); |
|
21
|
|
|
|
|
22
|
|
|
namespace MikoPBX\Common\Providers; |
|
23
|
|
|
|
|
24
|
|
|
|
|
25
|
|
|
use MikoPBX\Modules\Config\WebUIConfigInterface; |
|
26
|
|
|
use MikoPBX\Modules\PbxExtensionUtils; |
|
27
|
|
|
use Phalcon\Di\DiInterface; |
|
28
|
|
|
use Phalcon\Di\ServiceProviderInterface; |
|
29
|
|
|
use Phalcon\Mvc\Router; |
|
30
|
|
|
|
|
31
|
|
|
/** |
|
32
|
|
|
* Register Router service |
|
33
|
|
|
*/ |
|
34
|
|
|
class RouterProvider implements ServiceProviderInterface |
|
35
|
|
|
{ |
|
36
|
|
|
public const SERVICE_NAME = 'router'; |
|
37
|
|
|
|
|
38
|
|
|
/** |
|
39
|
|
|
* Register router service provider |
|
40
|
|
|
* |
|
41
|
|
|
* @param \Phalcon\Di\DiInterface $di |
|
42
|
|
|
*/ |
|
43
|
|
|
public function register(DiInterface $di): void |
|
44
|
|
|
{ |
|
45
|
|
|
$di->set( |
|
46
|
|
|
self::SERVICE_NAME, |
|
47
|
|
|
function () { |
|
48
|
|
|
$router = new Router(); |
|
49
|
|
|
|
|
50
|
|
|
$router->setDefaultModule("admin-cabinet"); |
|
51
|
|
|
$router->setDefaultNamespace('MikoPBX\AdminCabinet\Controllers'); |
|
52
|
|
|
$router->setDefaultController('extensions'); |
|
53
|
|
|
$router->setDefaultAction('index'); |
|
54
|
|
|
|
|
55
|
|
|
$router->add('/admin-cabinet/:controller/:action/:params', [ |
|
56
|
|
|
'module' => 'admin-cabinet', |
|
57
|
|
|
'controller' => 1, |
|
58
|
|
|
'action' => 2, |
|
59
|
|
|
'params' => 3 |
|
60
|
|
|
]); |
|
61
|
|
|
|
|
62
|
|
|
// Add route for external modules which integrate its views into admin web ui |
|
63
|
|
|
$route = $router->add('/admin-cabinet/{namespace:module.*}/:controller/:action/:params', [ |
|
64
|
|
|
'module' => 'admin-cabinet', |
|
65
|
|
|
'namespace' => 1, |
|
66
|
|
|
'controller' => 2, |
|
67
|
|
|
'action' => 3, |
|
68
|
|
|
'params' => 4, |
|
69
|
|
|
]); |
|
70
|
|
|
|
|
71
|
|
|
$route->convert( |
|
72
|
|
|
'namespace', |
|
73
|
|
|
function ($namespace) { |
|
74
|
|
|
$camelizedNameSpace = \Phalcon\Text::Camelize($namespace); |
|
75
|
|
|
return "\\Modules\\{$camelizedNameSpace}\\App\\Controllers"; |
|
76
|
|
|
} |
|
77
|
|
|
); |
|
78
|
|
|
|
|
79
|
|
|
// Register additional app modules from external enabled modules |
|
80
|
|
|
PbxExtensionUtils::registerEnabledModulesInRouter($router); |
|
81
|
|
|
|
|
82
|
|
|
// Register additional routes from external enabled modules |
|
83
|
|
|
PBXConfModulesProvider::hookModulesProcedure(WebUIConfigInterface::ON_AFTER_ROUTES_PREPARED,[&$router]); |
|
84
|
|
|
|
|
85
|
|
|
return $router; |
|
86
|
|
|
} |
|
87
|
|
|
); |
|
88
|
|
|
} |
|
89
|
|
|
} |