/** * @param \Janeiro\Di\Container $container */ public function __construct(Container $container) { $this->container = $container->set('dispatcher', $this); $this->router = $container->resolve('Janeiro\\Mvc\\Router', 'router'); $this->view = $this->container->resolve('Janeiro\\Mvc\\View', 'view'); $this->response = new Response(); }
/** * @param string $name service identifier * @param \Janeiro\Di\Container $container */ public function register($name, Container $container) { $session = new Session(hash('MD5', uniqid('', true))); if (isset($_SERVER[self::HEADER_SESSION_HASH])) { $hash = $_SERVER[self::HEADER_SESSION_HASH]; if (preg_match(self::MATCH_MD5, $hash)) { $session->setHash($hash)->start(); } } $container->set($name, $session); }
/** * @param string $name service identifier * @param \Janeiro\Di\Container $container */ public function register($name, Container $container) { $container->set($name, function () use($container, $name) { /** @var \Janeiro\Mvc\View $service */ $service = $container->resolve('\\Janeiro\\Mvc\\View'); foreach ($container['registry']->get('views') as $class => $suffixes) { $service->registerEngine($class, $suffixes); } return $service; }); }
/** * @param string $name service identifier * @param \Janeiro\Di\Container $container */ public function register($name, Container $container) { $container->set($name, function () use($container, $name) { $service = new Router(); $service->setNamespace($container['registry']->get('routing.namespace')); $service->setRoute(['module' => $container['registry']->get('routing.default.module'), 'controller' => $container['registry']->get('routing.default.controller'), 'action' => $container['registry']->get('routing.default.action')]); foreach ($container['registry']->get('routing.table') as $route) { foreach ($route as $pattern => $configuration) { $service->addRoute($pattern, $configuration); } } return $service; }); }
public function setup() { $container = new Container(); $container->set('view', function () use($container) { $view = new View($container); $view->registerEngine('Janeiro\\Mvc\\View\\Standard', '.php'); return $view; }, true)->set('router', function () use($container) { $router = new Router($container); $router->addRoute('/:module/:controller', ['module' => 1, 'controller' => 2, 'action' => 'index']); $router->addRoute('/:module/:controller/:action', ['module' => 1, 'controller' => 2, 'action' => 3]); $router->addRoute('/test/parameter/variable/:integer', ['module' => 'test', 'controller' => 'parameter', 'parameters' => ['variable' => 1]]); return $router; }, true); $this->dispatcher = new Dispatcher($container); $this->container = $container; }
public function testWhetherContainerHasService() { $this->assertEquals(false, $this->container->has('foobar')); $this->container->set('foobar', new \stdClass()); $this->assertEquals(true, $this->container->has('foobar')); }