api/app/plugins/NotFoundPlugin.php
2023-04-07 19:05:18 +08:00

45 lines
1.2 KiB
PHP

<?php
use Phalcon\Events\Event;
use Phalcon\Mvc\User\Plugin;
use Phalcon\Dispatcher;
use Phalcon\Mvc\Dispatcher\Exception as DispatcherException;
use Phalcon\Mvc\Dispatcher as MvcDispatcher;
/**
* NotFoundPlugin
*
* Handles not-found controller/actions
*/
class NotFoundPlugin extends Plugin {
public $config = array ();
/**
* This action is executed before execute any action in the application
*
* @param Event $event
* @param MvcDispatcher $dispatcher
* @param Exception $exception
* @return boolean
*/
public function beforeException(Event $event, MvcDispatcher $dispatcher, Exception $exception) {
error_log ( $exception->getMessage () . PHP_EOL . $exception->getTraceAsString () );
if ($exception instanceof DispatcherException) {
switch ($exception->getCode ()) {
case Dispatcher::EXCEPTION_HANDLER_NOT_FOUND :
case Dispatcher::EXCEPTION_ACTION_NOT_FOUND :
$dispatcher->forward ( array (
'controller' => 'errors',
'action' => 'show404'
) );
return false;
}
}
if ($this->config->setting->debug > 1) {
throw $exception;
}
$dispatcher->forward ( array (
'controller' => 'errors',
'action' => 'show500'
) );
return false;
}
}
?>