You are here

class FormatSetter in Services 8.4

Same name and namespace in other branches
  1. 9.0.x src/StackMiddleware/FormatSetter.php \Drupal\services\StackMiddleware\FormatSetter

Class which extracts accept headers and sets Request formats accordingly to at least allow for accept header variation when needed. This class respects core's usage of request format and attempts to communicate it generically. It should leave the Request format NULL when an unrecognized header is submitted. Drupal core will later set a default of html. If a recognized format comes through, it's set at this point to allow the PageCache http_middleware to properly cache by format.

Hierarchy

  • class \Drupal\services\StackMiddleware\FormatSetter implements \Symfony\Component\HttpKernel\HttpKernelInterface

Expanded class hierarchy of FormatSetter

1 string reference to 'FormatSetter'
services.services.yml in ./services.services.yml
services.services.yml
1 service uses FormatSetter
http_middleware.format_setter in ./services.services.yml
Drupal\services\StackMiddleware\FormatSetter

File

src/StackMiddleware/FormatSetter.php, line 17

Namespace

Drupal\services\StackMiddleware
View source
class FormatSetter implements HttpKernelInterface {

  /**
   * The wrapped HTTP kernel.
   *
   * @var \Symfony\Component\HttpKernel\HttpKernelInterface
   */
  protected $httpKernel;

  /**
   * Constructs a PageCache 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) {
    if ($request->headers
      ->has('Accept')) {
      $request
        ->setRequestFormat($request
        ->getFormat($request->headers
        ->get('Accept')));
    }
    return $this->httpKernel
      ->handle($request, $type, $catch);
  }

}

Members

Namesort descending Modifiers Type Description Overrides
FormatSetter::$httpKernel protected property The wrapped HTTP kernel.
FormatSetter::handle public function Handles a Request to convert it to a Response.
FormatSetter::__construct public function Constructs a PageCache object.