FormTestMiddleware.php

Same filename in other branches
  1. 9 core/modules/system/tests/modules/form_test/src/StackMiddleware/FormTestMiddleware.php
  2. 8.9.x core/modules/system/tests/modules/form_test/src/StackMiddleware/FormTestMiddleware.php
  3. 11.x core/modules/system/tests/modules/form_test/src/StackMiddleware/FormTestMiddleware.php

Namespace

Drupal\form_test\StackMiddleware

File

core/modules/system/tests/modules/form_test/src/StackMiddleware/FormTestMiddleware.php

View source
<?php

namespace Drupal\form_test\StackMiddleware;

use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\HttpKernel\HttpKernelInterface;

/**
 * Provides a test middleware which sets a custom response header.
 */
class FormTestMiddleware implements HttpKernelInterface {
    
    /**
     * The decorated kernel.
     *
     * @var \Symfony\Component\HttpKernel\HttpKernelInterface
     */
    protected $httpKernel;
    
    /**
     * Constructs a FormTestMiddleware object.
     *
     * @param \Symfony\Component\HttpKernel\HttpKernelInterface $http_kernel
     *   The decorated kernel.
     */
    public function __construct(HttpKernelInterface $http_kernel) {
        $this->httpKernel = $http_kernel;
    }
    
    /**
     * {@inheritdoc}
     */
    public function handle(Request $request, $type = self::MAIN_REQUEST, $catch = TRUE) : Response {
        $response = $this->httpKernel
            ->handle($request, $type, $catch);
        $response->headers
            ->set('X-Form-Test-Stack-Middleware', 'invoked');
        return $response;
    }

}

Classes

Title Deprecated Summary
FormTestMiddleware Provides a test middleware which sets a custom response header.

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.