return new Flash\Session(array('error' => 'alert-box alert', 'notice' => 'alert-box', 'warning' => 'alert-box warning', 'success' => 'alert-box success')); }, true); $services->set('session', function () { $session = new Session\Adapter\Files(); $session->start(); return $session; }, true); $services->set('router', function () { $router = new Mvc\Router(); foreach (json_decode(file_get_contents(sprintf('%s/route.json', ROOT_PATH))) as $rule) { $router->add($rule->url, (array) $rule->param)->setName($rule->name); } return $router; }, true); $services->set('dispatcher', function () { $manager = new Events\Manager(); $manager->attach('dispatch:beforeException', function ($event, $dispatcher, $exception) { $dispatcher->forward(array('controller' => 'errors', 'action' => 'PageNotFound')); return false; }); $dispatcher = new Mvc\Dispatcher(); $dispatcher->setEventsManager($manager); $dispatcher->setDefaultNamespace('Controllers'); return $dispatcher; }, true); $services->set('container', function () { return new \Plugins\Container(); }, true); /** Application */ $application = new Mvc\Application($services); echo $application->handle()->getContent();
<?php require '../loader/Loader.php'; $loader = new Loader(); $loader->registerNamespaces(array('Events' => getcwd()))->register(); $manager = new Events\Manager(); $a = function () { echo "A"; }; $manager->attach('test:hello', $a); $b = function (Events\Event $event) { echo "B"; }; $manager->attach('test:hello', $b); var_dump($manager->fire('test:hello', null)); var_dump($manager->getListeners('test:hello'));