From 9befeb9e34444d285a4062c68540fd018cbfc593 Mon Sep 17 00:00:00 2001 From: Anton Vasiliev Date: Sun, 18 Aug 2019 19:10:52 +0100 Subject: [PATCH] Added usage of getModuleName() and getHandlersNamespace() in DispatcherListener Event --- src/Events/Listeners/DispatcherListener.php | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/src/Events/Listeners/DispatcherListener.php b/src/Events/Listeners/DispatcherListener.php index c141995..ca90ea1 100644 --- a/src/Events/Listeners/DispatcherListener.php +++ b/src/Events/Listeners/DispatcherListener.php @@ -4,13 +4,14 @@ use Exception; use Phalcon\Di\Exception as DiException; -use Phalcon\Plugin; use Phalcon\Events\Event; use Phalcon\Mvc\Dispatcher; +use Phalcon\Mvc\Dispatcher\Exception as MvcDispatcherException; +use Phalcon\Plugin; use Phlexus\Libraries\Auth\AuthException; use Phlexus\Module\ModuleException; use Phlexus\Module\ModuleInterface; -use Phalcon\Mvc\Dispatcher\Exception as MvcDispatcherException; +use Phlexus\Modules\BaseAdmin\Module as AdminModule; final class DispatcherListener extends Plugin { @@ -62,11 +63,14 @@ public function beforeForward(Event $event, Dispatcher $dispatcher, array $forwa */ public function beforeException(Event $event, Dispatcher $dispatcher, Exception $exception): bool { + $moduleName = AdminModule::getModuleName(); + $namespace = AdminModule::getHandlersNamespace() . '\\Controllers'; + if ($exception instanceof MvcDispatcherException) { $this->response->setStatusCode(404); $dispatcher->forward([ - 'module' => 'Admin', - 'namespace' => 'Phlexus\Modules\Admin\Controllers', + 'module' => $moduleName, + 'namespace' => $namespace, 'controller' => 'errors', 'action' => 'show404', ]); @@ -77,8 +81,8 @@ public function beforeException(Event $event, Dispatcher $dispatcher, Exception if ($exception instanceof AuthException) { $this->response->setStatusCode(402); $dispatcher->forward([ - 'module' => 'Admin', - 'namespace' => 'Phlexus\Modules\Admin\Controllers', + 'module' => $moduleName, + 'namespace' => $namespace, 'controller' => 'auth', 'action' => 'login', ]);