/**
  * Request listener.
  *
  * @param ResponseEvent $event
  */
 public function onRequest(ResponseEvent $event)
 {
     $router = new Router($this->collection);
     $request = $event->getRequest();
     $this->kernel = $event->getKernel();
     $this->container = $this->kernel->getContainer();
     $this->middleware = $this->kernel->getMiddleware();
     $this->responseEvent = $event;
     $this->container->register('router', $router, true);
     $router->setHandler($this);
     $router->listen(new RequestContext($request->getUri()->getPathInfo(), $request->getMethod(), $request->getQueryString(), $request->getSchemaHost()->getHost(), $request->getSchemaHost()->getSchema(), $request->getSchemaHost()->getPort()));
 }
 /**
  * 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;
 }
 /**
  * {@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'));
     }
 }