I managed to solve the issue by essentually creating my own NotFoundPlugin
that would execute beforeDispatchLoop
<?php
use Phalcon\Text;
use Phalcon\Events\Event;
use Phalcon\Mvc\Dispatcher;
use Phalcon\Mvc\User\Plugin;
use Phalcon\Mvc\Dispatcher\Exception as DispatcherException;
Class ExistsPlugin extends Plugin {
/**
* @param Event $event
* @param Dispatcher $dispatcher
* @throws DispatcherException
*/
public function beforeDispatchLoop(Event $event, Dispatcher $dispatcher) {
$controller = empty($dispatcher->getControllerName()) ? "" : (APP_PATH . Text::camelize($dispatcher->getControllerName()) . 'Controller') ;
$action = empty($dispatcher->getActionName()) ? "" : (Text::camelize($dispatcher->getActionName()) . 'Action');
try {
// Is the controller defined in the url?
if ($controller) {
// Does the defined controller exist?
if (file_exists($controller)) {
// Is the action defined in the url?
if ($action) {
// Does the defined action exist in the controller?
if (method_exists($controller, $action)) {
} else {
throw new DispatcherException;
}
}
} else {
throw new DispatcherException;
}
}
}
catch (Exception $exception) {
if ($exception instanceof DispatcherException) {
$dispatcher->forward([
'controller' => 'errors',
'action' => 'error404'
]);
}
else {
$dispatcher->forward([
'controller' => 'errors',
'action' => 'error500'
]);
}
}
}
}
Unfortunately it renders NotFoundPlugin
almost useless but does however avoid the need for SecurityPlugin from checking the ACL for non-existant controllers/actions.
Could you please critique my code?