class ContainerAwareHttpKernel

Adds a managed request scope.

@author Fabien Potencier <fabien@symfony.com> @author Johannes M. Schmitt <schmittjoh@gmail.com>

Hierarchy

Expanded class hierarchy of ContainerAwareHttpKernel

1 file declares its use of ContainerAwareHttpKernel
ContainerAwareHttpKernelTest.php in drupal/core/vendor/symfony/http-kernel/Symfony/Component/HttpKernel/Tests/DependencyInjection/ContainerAwareHttpKernelTest.php

File

drupal/core/vendor/symfony/http-kernel/Symfony/Component/HttpKernel/DependencyInjection/ContainerAwareHttpKernel.php, line 29

Namespace

Symfony\Component\HttpKernel\DependencyInjection
View source
class ContainerAwareHttpKernel extends HttpKernel {
  protected $container;

  /**
   * Constructor.
   *
   * @param EventDispatcherInterface    $dispatcher         An EventDispatcherInterface instance
   * @param ContainerInterface          $container          A ContainerInterface instance
   * @param ControllerResolverInterface $controllerResolver A ControllerResolverInterface instance
   */
  public function __construct(EventDispatcherInterface $dispatcher, ContainerInterface $container, ControllerResolverInterface $controllerResolver) {
    parent::__construct($dispatcher, $controllerResolver);
    $this->container = $container;

    // the request scope might have been created before (see FrameworkBundle)
    if (!$container
      ->hasScope('request')) {
      $container
        ->addScope(new Scope('request'));
    }
  }

  /**
   * {@inheritdoc}
   */
  public function handle(Request $request, $type = HttpKernelInterface::MASTER_REQUEST, $catch = true) {
    $request->headers
      ->set('X-Php-Ob-Level', ob_get_level());
    $this->container
      ->enterScope('request');
    $this->container
      ->set('request', $request, 'request');
    try {
      $response = parent::handle($request, $type, $catch);
    } catch (\Exception $e) {
      $this->container
        ->set('request', null, 'request');
      $this->container
        ->leaveScope('request');
      throw $e;
    }
    $this->container
      ->set('request', null, 'request');
    $this->container
      ->leaveScope('request');
    return $response;
  }

}

Members

Namesort descending Modifiers Type Description Overrides
ContainerAwareHttpKernel::$container protected property
ContainerAwareHttpKernel::handle public function @api Overrides HttpKernel::handle
ContainerAwareHttpKernel::__construct public function Constructor. Overrides HttpKernel::__construct
HttpKernel::$dispatcher protected property
HttpKernel::$resolver protected property
HttpKernel::filterResponse private function Filters a response object.
HttpKernel::handleException private function Handles an exception by trying to convert it to a Response.
HttpKernel::handleRaw private function Handles a request to convert it to a response.
HttpKernel::terminate public function @api Overrides TerminableInterface::terminate
HttpKernel::varToString private function
HttpKernelInterface::MASTER_REQUEST constant
HttpKernelInterface::SUB_REQUEST constant