Skip to content

Commit

Permalink
Added usage of getModuleName() and getHandlersNamespace() in Dispatch…
Browse files Browse the repository at this point in the history
…erListener Event
  • Loading branch information
Jeckerson committed Aug 18, 2019
1 parent d5b5813 commit 9befeb9
Showing 1 changed file with 10 additions and 6 deletions.
16 changes: 10 additions & 6 deletions src/Events/Listeners/DispatcherListener.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand Down Expand Up @@ -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',
]);
Expand All @@ -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',
]);
Expand Down

0 comments on commit 9befeb9

Please sign in to comment.