This is a sample dispatcher service registered with set
method of \Phalcon\DI\FactoryDefault
:
$eventsManager = new \Phalcon\Events\Manager();
$eventsManager->attach(
"dispatch:beforeDispatchLoop",
function (\Phalcon\Events\Event $event, $dispatcher) {
throw new \Phalcon\Exception("Some unhandled exception.");
}
);
$eventsManager->attach(
"dispatch:beforeException",
function($event, $dispatcher, $exception) {
$dispatcher->forward(
array(
'controller' => 'error',
'action' => 'e404',
)
);
return false;
}
);
$dispatcher = new \Phalcon\Mvc\Dispatcher();
$dispatcher->setEventsManager($eventsManager);
return $dispatcher;
Expected Behaviour: After exception has been thrown, trigger dispatch:beforeException
and handle dispatcher forward
method invocation.
Actual Behaviour: After exception has been thrown,dispatch:beforeException
event was triggered, but dispatcher forward
method invocation is not handled.
Is this to be expected? I assume this has something to do with the Dispatcher Loop flag attribute _finished
not evaluating to FALSE
after invoking the forward
method?
Is there a workaround to achieve the expected behaviour?