Archived
1
0
Fork 0
This repository has been archived on 2026-04-03. You can view files and clone it, but you cannot make any changes to it's state, such as pushing and creating new issues, pull requests or comments.
httpcb/app/plugins/ExceptionHandlerPlugin.php
2017-09-01 17:10:27 +02:00

49 lines
1.4 KiB
PHP

<?php
use Phalcon\Events\Event;
use Phalcon\Mvc\User\Plugin;
use Phalcon\Mvc\Dispatcher;
use Phalcon\Mvc\Dispatcher\Exception as DispatcherException;
/**
* Class ExceptionHandlerPlugin
*
* Plugin for forwarding user to 404 (not found) page
* if a request could not be dispatched.
*/
class ExceptionHandlerPlugin extends Plugin
{
protected $_route_notfound = array(
'controller' => 'error',
'action' => 'show404'
);
protected $_route_error = array(
'controller' => 'error',
'action' => 'error',
);
/**
* @param Event $event
* @param Dispatcher $dispatcher
* @param Exception $exception
* @return bool
*/
public function beforeException(Event $event, Dispatcher $dispatcher, Exception $exception)
{
// Figure out if this was a exception from dispatcher and that exception
// was that an controller or action was not found.
if ($exception instanceof DispatcherException) {
switch ($exception->getCode()) {
case Dispatcher::EXCEPTION_HANDLER_NOT_FOUND :
case Dispatcher::EXCEPTION_ACTION_NOT_FOUND :
// in this case, forward to 404 page.
$dispatcher->forward($this->_route_notfound);
return false;
}
}
$dispatcher->forward($this->_route_error);
return false;
}
}