Skip to main content
Drupal API
User account menu
  • Log in

Breadcrumb

  1. Drupal Core 11.1.x
  2. StackedHttpKernel.php

class StackedHttpKernel

Provides a stacked HTTP kernel.

Copied from https://github.com/stackphp/builder/ with added compatibility for Symfony 6.

Hierarchy

  • class \Drupal\Core\StackMiddleware\StackedHttpKernel implements \Symfony\Component\HttpKernel\HttpKernelInterface, \Symfony\Component\HttpKernel\TerminableInterface

Expanded class hierarchy of StackedHttpKernel

See also

\Drupal\Core\DependencyInjection\Compiler\StackedKernelPass

1 file declares its use of StackedHttpKernel
StackedKernelPass.php in core/lib/Drupal/Core/DependencyInjection/Compiler/StackedKernelPass.php

File

core/lib/Drupal/Core/StackMiddleware/StackedHttpKernel.php, line 18

Namespace

Drupal\Core\StackMiddleware
View source
class StackedHttpKernel implements HttpKernelInterface, TerminableInterface {
    
    /**
     * The decorated kernel.
     *
     * @var \Symfony\Component\HttpKernel\HttpKernelInterface
     */
    private $kernel;
    
    /**
     * A set of middlewares that are wrapped around this kernel.
     *
     * @var array
     */
    private $middlewares = [];
    
    /**
     * Constructs a stacked HTTP kernel.
     *
     * @param \Symfony\Component\HttpKernel\HttpKernelInterface $kernel
     *   The decorated kernel.
     * @param array $middlewares
     *   An array of previous middleware services.
     */
    public function __construct(HttpKernelInterface $kernel, array $middlewares) {
        $this->kernel = $kernel;
        $this->middlewares = $middlewares;
    }
    
    /**
     * {@inheritdoc}
     */
    public function handle(Request $request, $type = HttpKernelInterface::MAIN_REQUEST, $catch = TRUE) : Response {
        return $this->kernel
            ->handle($request, $type, $catch);
    }
    
    /**
     * {@inheritdoc}
     */
    public function terminate(Request $request, Response $response) : void {
        $previous = NULL;
        foreach ($this->middlewares as $kernel) {
            // If the previous kernel was terminable we can assume this middleware
            // has already been called.
            if (!$previous instanceof TerminableInterface && $kernel instanceof TerminableInterface) {
                $kernel->terminate($request, $response);
            }
            $previous = $kernel;
        }
    }

}

Members

Title Sort descending Modifiers Object type Summary Overriden Title
HttpKernelInterface::MAIN_REQUEST public constant
HttpKernelInterface::SUB_REQUEST public constant
StackedHttpKernel::$kernel private property The decorated kernel.
StackedHttpKernel::$middlewares private property A set of middlewares that are wrapped around this kernel.
StackedHttpKernel::handle public function Handles a Request to convert it to a Response. Overrides HttpKernelInterface::handle
StackedHttpKernel::terminate public function Terminates a request/response cycle. Overrides TerminableInterface::terminate
StackedHttpKernel::__construct public function Constructs a stacked HTTP kernel.
RSS feed
Powered by Drupal