Hello!
I'm using a multi-module application template and I ran into this problem. At first I wanted to make all calls to the API into a separate module and make all calls to it. But, now I understand that this approach will destroy the encapsulation of modules. Of course, you can do IPI for each module separately, but in this case, you get a large amount of router rule (for each module there are now 3 rules, with the API will be at least 4, there are a lot of modules planned).
Can I somehow solve the problem with a lot of rules for the router?
Now the initialization of the router looks like this:
public function register()
{
$this->di->setShared(
$this->serviceName,
function () {
$router = new Router();
$router->notFound([
'module' => 'cabinet',
'controller' => 'error',
'action' => 'show404'
]);
$router->add("/:controller/:action/:params", array(
'module' => 'cabinet',
'controller' => 1,
'action' => 2,
'params'=>3
))->convert('action', function ($action) {
return Text::lower(Text::camelize($action));
});
$router->add("/", array(
'module' => 'cabinet',
'controller' => 'index',
'action' => 'index',
));
$router->add("/api", array(
'module' => 'api',
'controller' => 'index',
'action' => 'index',
));
$router->add("/api/:controller/:action/:params", array(
'module' => 'api',
'controller' => 1,
'action' => 2,
'params' => 3,
))->convert('action', function ($action) {
return Text::lower(Text::camelize($action));
});
$router->add("/admin", array(
'module' => 'admin',
'controller' => 'index',
'action' => 'index',
));
$router->add("/admin/:controller", array(
'module' => 'admin',
'controller' => 1,
'action' => 'index',
))->convert('action', function ($action) {
return Text::lower(Text::camelize($action));
});
$router->add("/admin/:controller/:action/:params", array(
'module' => 'admin',
'controller' => 1,
'action' => 2,
'params'=>3
))->convert('action', function ($action) {
return Text::lower(Text::camelize($action));
});
}