Archived
1
0
Fork 0

move app/plugins to app/listeners and give them the App\Listener namespace.

This commit is contained in:
Henrik Hautakoski 2018-04-02 23:25:05 +02:00
parent a72932a7ad
commit 6ed63d591f
5 changed files with 17 additions and 15 deletions

View file

@ -4,7 +4,7 @@ application:
modelsDir : ../app/models/
migrationsDir : ../app/migrations/
viewsDir : ../app/views/
pluginsDir : ../app/plugins/
listenersDir : ../app/listeners/
libraryDir : ../app/library/
formsDir : ../app/forms/
logDir : ../cache/log/

View file

@ -2,20 +2,14 @@
$loader = new \Phalcon\Loader();
/**
* We're a registering a set of directories taken from the configuration file
*/
$loader->registerDirs(
array(
$config->application->pluginsDir
)
)->register();
$loader->registerNamespaces(array(
'App\Controller' => $config->application->controllersDir,
'App\Listener' => $config->application->listenersDir,
'Model' => $config->application->modelsDir,
'Form' => $config->application->formsDir,
'Httpcb' => $config->application->libraryDir,
));
$loader->register();
require_once __DIR__ . '/../../vendor/autoload.php';

View file

@ -29,6 +29,9 @@ use Httpcb\Auth,
Httpcb\Navigation,
Httpcb\Menu;
use App\Listener\AclListener,
App\Listener\DispatchListener;
/**
* The FactoryDefault Dependency Injector automatically register the right services providing a full stack framework
*/
@ -54,10 +57,10 @@ $di->setShared('dispatcher', function() use ($di, $config) {
});
if ($config->application->debug == false) {
$eventsManager->attach('dispatch:beforeException', new \ExceptionHandlerPlugin());
$eventsManager->attach('dispatch:beforeException', new DispatchListener());
}
$eventsManager->attach('dispatch:beforeExecuteRoute', new \AclPlugin());
$eventsManager->attach('dispatch:beforeExecuteRoute', new AclListener());
$dispatcher = new \Phalcon\Mvc\Dispatcher();
$dispatcher->setEventsManager($eventsManager);

View file

@ -1,11 +1,14 @@
<?php
namespace App\Listener;
use Phalcon\Events\Event;
use Phalcon\Mvc\Dispatcher;
use Phalcon\Mvc\User\Plugin;
use Httpcb\Acl;
class AclPlugin extends Phalcon\Mvc\User\Plugin
class AclListener extends Plugin
{
public function beforeExecuteRoute(Event $event, Dispatcher $dispatcher)
{

View file

@ -1,17 +1,19 @@
<?php
namespace App\Listener;
use Phalcon\Events\Event;
use Phalcon\Mvc\User\Plugin;
use Phalcon\Mvc\Dispatcher;
use Phalcon\Mvc\Dispatcher\Exception as DispatcherException;
/**
* Class ExceptionHandlerPlugin
* Class DispatchListener
*
* Plugin for forwarding user to 404 (not found) page
* if a request could not be dispatched.
*/
class ExceptionHandlerPlugin extends Plugin
class DispatchListener extends Plugin
{
protected $_route_notfound = array(
'controller' => 'error',