<?php
include __DIR__ . '/../../../common/config/di.php';
$di->setShared('router', function () {
    return include __DIR__ . '/router.php';
});
$di->setShared('dispatcher', function () {
    //Create an EventsManager
    $eventsManager = new Phalcon\Events\Manager();
    //Attach a listener
    $eventsManager->attach("dispatch:beforeException", function ($event, $dispatcher, $exception) {
        //Handle 404 not found exceptions
        //Handle 404 not found exceptions
        if ($exception instanceof Phalcon\Mvc\Dispatcher\Exception) {
            $dispatcher->forward([
                'controller' => 'err',
                'action'     => 'notFound',
                'params'     => ['message' => $exception->getMessage()],
            ]);
            return false;
        }
    });
    $dispatcher = new Phalcon\Mvc\Dispatcher();
    $dispatcher->setDefaultNamespace('\SRVX\Api\Controllers');
    //Bind the EventsManager to the dispatcher
    $dispatcher->setEventsManager($eventsManager);
    return $dispatcher;
});