public function setUp() { $this->locator = ControllerLocator::getInstance(); $this->locator->reset(); }
public function boot(AbstractApplication $app) { # Setting environment options $app['debug'] = $this->environment == self::ENVIRONMENT_DEBUG ? true : false; # Compiling controllers $locator = ControllerLocator::getInstance($app); foreach ($this->controllers_path as $path) { if (is_dir(realpath($path))) { $iterator = new \FilesystemIterator($path); $locator->scanControllers($iterator); } } $this->controllers->addAll($locator->getStack()); $reader = new Reader(); $this->controllers->rewind(); foreach ($this->controllers as $controller) { $baseRoute = $reader->getAnnotation(new \ReflectionClass($controller), 'route'); if (!is_null($baseRoute)) { $app->mount($baseRoute, $controller::compile($app)); } } # Configuring Doctrine DBAL if (isset($this->configuration['doctrine'])) { $app->register(new DoctrineServiceProvider(), array('db.options' => $this->configuration['doctrine'])); } # Configuring cache if (isset($this->configuration['zend_cache'])) { $app->register(new ZendCacheServiceProvider(), array('cache.options' => array('zendcache' => $this->configuration['zend_cache']))); } # Configuring Monolog if (isset($this->configuration['monolog'])) { $app['monolog.factory'] = $app->protect(function ($name, array $options) { $logger = new Logger($name); $handlerClass = 'Monolog\\Handler\\' . $options['handler']; if (!class_exists($handlerClass)) { throw new BootstrapException(sprintf('The handler %s specified does not exists and cannot be loaded', $handlerClass)); } if (class_exists($handlerClass)) { $reflector = new \ReflectionClass($handlerClass); $handler = $reflector->newInstanceArgs($options['options']); } else { throw new BootstrapException(sprintf('Invalid Monolog Handler specified')); } $logger->pushHandler($handler); return $logger; }); # Compiling loggers foreach ($this->configuration['monolog'] as $channel => $options) { $app['monolog.' . $channel] = $app['monolog.factory']($channel, $options); } } # Configuring Twig if (isset($this->configuration['twig'])) { if (!is_array($this->configuration['twig'])) { $this->configuration['twig'] = array(); } $app->register(new TwigServiceProvider(), $this->configuration['twig']); } # Configuring Routing component $app->register(new RoutingServiceProvider()); # Setting configurations $app['config'] = $this->configuration; $this->application = $app; $this->application->boot(); return $this->application; }