We have moved our forum to GitHub Discussions. For questions about Phalcon v3/v4/v5 you can visit here and for Phalcon v6 here.

Invo NotFoundPlugin - why abstract dispatcher class is used?

Hi in the NotFoundPlugin of the Invo app is besides Mvc\Dispatcher also the abstract base class used. Could somebody explain please for what reason this is done?

    ...
    use Phalcon\Dispatcher;
    use Phalcon\Mvc\Dispatcher as MvcDispatcher;
    ...
    if ($exception instanceof DispatcherException) {
        switch ($exception->getCode()) {
            case Dispatcher::EXCEPTION_HANDLER_NOT_FOUND:
            case Dispatcher::EXCEPTION_ACTION_NOT_FOUND:
                $dispatcher->forward(
                    [
                        'controller' => 'errors',
                        'action'     => 'show404'
                    ]
                );
                return false;
        }
    }


77.7k
Accepted
answer
edited Mar '18

Because the plugin is only accessing two constant variables from that class, and not instantiating it.

It COULD use the MvcDispatcher to access those constants, since it inherits from abstract dispatcher.



1.5k

Yeah, that is what I don't get - why not simply the child class was used here.

I dont think there's a specific reason for it... either will work, but yeah, it is superfluous the way it's written now.