/**
  * Get default services.
  *
  * @param KernelInterface $kernel
  *
  * @return array
  */
 private function getDefaultServices(KernelInterface $kernel)
 {
     $services = array('kernel' => $kernel, 'config' => $this->configuration, 'extension_manager' => $this->extension, 'middleware' => $kernel->getMiddleware(), 'resource' => $this->resource, 'event_dispatcher' => new EventDispatcher());
     if (null !== ($request = $kernel->getRequest())) {
         $services['request'] = $request;
     }
     return $services;
 }
 /**
  * Load console from extension.
  *
  * @param KernelInterface $kernel
  */
 private function loadConsoles(KernelInterface $kernel)
 {
     foreach ($kernel->getBundleManager()->all() as $bundle) {
         foreach ((array) $bundle->getContainerExtensions() as $extension) {
             if ($extension instanceof LoadConsoleInterface) {
                 $this->add((array) $extension->loadConsole(), $kernel->getContainer());
             }
         }
     }
 }
 /**
  * Register exception handler.
  */
 private function registerExceptionHandler()
 {
     $namespace = $this->reflection->getNamespaceName();
     $handlerClass = $namespace . '\\ExceptionHandler';
     if (class_exists($handlerClass)) {
         $handler = new $handlerClass($this->kernel);
         if (!$handler instanceof AbstractExceptionHandler) {
             throw new RuntimeException(sprintf('Exception handler "%s" should implement ' . '"Borobudur\\Bundle\\FrameworkBundle\\Environment\\AbstractExceptionHandler".', $handlerClass));
         }
         $this->kernel->addListenerOnce(KernelEvents::EXCEPTION, array($handler, 'handle'));
     }
 }
 /**
  * @return LoggerInterface|null
  */
 protected function getLogger()
 {
     if (!$this->kernel->getContainer()->has('log')) {
         return null;
     }
     return $this->kernel->getContainer()->get('log');
 }
 /**
  * {@inheritdoc}
  */
 public function initialize(KernelInterface $kernel)
 {
     $env = $kernel->getEnvironmentManager()->getEnv();
     if (empty($this->environments)) {
         foreach ($kernel->registerEnvironments() as $environment) {
             $name = $environment->getName();
             $this->assertUnregisteredEnvironment($name);
             $this->environments[$name] = $environment;
         }
     }
     if (!isset($this->environments[$env])) {
         throw new RuntimeException(sprintf('Environment "%s" is not registered.', $env));
     }
     $env = $this->environments[$env];
     $env->build($kernel);
     $kernel->getEnvironmentManager()->setEnvInstance($env);
 }
 /**
  * {@inheritdoc}
  */
 public function initialize(KernelInterface $kernel)
 {
     $this->container = $kernel->getContainer();
     $this->serviceLocator = $kernel->getServiceLocator();
     $env = $kernel->getEnvironmentManager()->getEnvInstance();
     $resolver = $this->container->getParameterBag()->getResolver();
     $configs = (array) $env->registerConfigurations();
     $configs = $this->getResource()->process(new FileLoader(), $configs);
     $this->loadParametersFromConfig($configs);
     $this->loadServicesFromConfig($configs);
     // Append configuration by extension
     foreach ($resolver->resolveValue($configs) as $alias => $config) {
         if (!$this->getExtension()->has($alias)) {
             throw new RuntimeException(sprintf('Extension with alias "%s" not found.', $alias));
         }
         $extension = $this->getExtension()->get($alias);
         $this->getConfiguration()->prepend($extension->getConfigDefinition(), array($config));
     }
 }
 /**
  * {@inheritdoc}
  */
 public function initialize(KernelInterface $kernel)
 {
     $middlewareContainer = $kernel->getMiddleware();
     $container = $kernel->getContainer();
     $env = $kernel->getEnvironmentManager()->getEnvInstance();
     $middlewareContainer->setContainer($container);
     $bundleMiddlewares = (array) $kernel->registerMiddlewares();
     $envMiddlewares = (array) $env->registerMiddlewares();
     foreach (array_merge($bundleMiddlewares, $envMiddlewares) as $middleware) {
         if ($middleware instanceof MiddlewareInterface) {
             if ($middleware instanceof ContainerAwareInterface) {
                 $middleware->setContainer($container);
             }
             $middlewareContainer->set($middleware);
             continue;
         }
         throw new InvalidArgumentException(sprintf('Class "%s" should implement "%s".', get_class($middleware), 'Borobudur\\Kernel\\Middleware\\MiddlewareInterface'));
     }
 }
 /**
  * Build response from controller.
  *
  * @param string $bundleName
  * @param string $controller
  * @param array  $parameters
  *
  * @return mixed
  */
 private function getBundleController($bundleName, $controller, array $parameters)
 {
     $bundleManager = $this->kernel->getBundleManager();
     if (null !== ($bundle = $bundleManager->get($bundleName))) {
         $class = $bundle->getNamespace() . '\\' . $this->prefix . '\\' . $controller . 'Controller';
         if (!class_exists($class)) {
             throw new RuntimeException(sprintf('Controller "%s" is undefined.', $class));
         }
         return $this->container->getDi()->createInstance($class, $parameters);
     }
     throw new RuntimeException(sprintf('Bundle "%s" is undefined.', $bundleName));
 }
 /**
  * Initialize process process.
  *
  * @param KernelInterface $kernel
  */
 public function initialize(KernelInterface $kernel)
 {
     $serviceLocator = $kernel->getServiceLocator();
     $serviceLocator->getExtension()->load($serviceLocator->getConfiguration(), $kernel->getContainer());
 }
 /**
  * Get bundles.
  *
  * @param KernelInterface $kernel
  *
  * @return array
  */
 private function getBundles(KernelInterface $kernel)
 {
     $env = $kernel->getEnvironmentManager()->getEnvInstance();
     return array_merge((array) $kernel->registerBundles(), (array) $env->registerBundles());
 }