You are here

FormTestMiddleware.php in Zircon Profile 8

File

core/modules/system/tests/modules/form_test/src/StackMiddleware/FormTestMiddleware.php
View source
<?php

/**
 * @file
 * Contains \Drupal\form_test\StackMiddleware\FormTestMiddleware.
 */
namespace Drupal\form_test\StackMiddleware;

use Symfony\Component\HttpFoundation\Request;
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::MASTER_REQUEST, $catch = TRUE) {
    $response = $this->httpKernel
      ->handle($request, $type, $catch);
    $response->headers
      ->set('X-Form-Test-Stack-Middleware', 'invoked');
    return $response;
  }

}

Classes

Namesort descending Description
FormTestMiddleware Provides a test middleware which sets a custom response header.