You are here

class ContainerAwareHttpKernel in Zircon Profile 8.0

Same name and namespace in other branches
  1. 8 vendor/symfony/http-kernel/DependencyInjection/ContainerAwareHttpKernel.php \Symfony\Component\HttpKernel\DependencyInjection\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

Deprecated

since version 2.7, to be removed in 3.0.

1 file declares its use of ContainerAwareHttpKernel
ContainerAwareHttpKernelTest.php in vendor/symfony/http-kernel/Tests/DependencyInjection/ContainerAwareHttpKernelTest.php

File

vendor/symfony/http-kernel/DependencyInjection/ContainerAwareHttpKernel.php, line 31

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
   * @param RequestStack                $requestStack       A stack for master/sub requests
   * @param bool                        $triggerDeprecation Whether or not to trigger the deprecation warning for the ContainerAwareHttpKernel
   */
  public function __construct(EventDispatcherInterface $dispatcher, ContainerInterface $container, ControllerResolverInterface $controllerResolver, RequestStack $requestStack = null, $triggerDeprecation = true) {
    parent::__construct($dispatcher, $controllerResolver, $requestStack);
    if ($triggerDeprecation) {
      @trigger_error('The ' . __CLASS__ . ' class is deprecated since version 2.7 and will be removed in 3.0. Use the Symfony\\Component\\HttpKernel\\HttpKernel class instead.', E_USER_DEPRECATED);
    }
    $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) {
    $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 Handles a Request to convert it to a Response. Overrides HttpKernel::handle
ContainerAwareHttpKernel::__construct public function Constructor. Overrides HttpKernel::__construct
HttpKernel::$dispatcher protected property
HttpKernel::$requestStack protected property
HttpKernel::$resolver protected property
HttpKernel::filterResponse private function Filters a response object.
HttpKernel::finishRequest private function Publishes the finish request event, then pop the request from the stack.
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 Terminates a request/response cycle. Overrides TerminableInterface::terminate
HttpKernel::terminateWithException public function @internal
HttpKernel::varToString private function
HttpKernelInterface::MASTER_REQUEST constant
HttpKernelInterface::SUB_REQUEST constant