class FormatSetter in Services 8.4
Same name and namespace in other branches
- 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'
1 service uses FormatSetter
File
- src/
StackMiddleware/ FormatSetter.php, line 17
Namespace
Drupal\services\StackMiddlewareView 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
Name![]() |
Modifiers | Type | Description | Overrides |
---|---|---|---|---|
FormatSetter:: |
protected | property | The wrapped HTTP kernel. | |
FormatSetter:: |
public | function | Handles a Request to convert it to a Response. | |
FormatSetter:: |
public | function | Constructs a PageCache object. |