You are here

final class FormatSetter in JSON:API 8.2

Same name and namespace in other branches
  1. 8 src/StackMiddleware/FormatSetter.php \Drupal\jsonapi\StackMiddleware\FormatSetter

Sets the 'api_json' for requests with a JSON:API Content-Type header.

@internal JSON:API maintains no PHP API since its API is the HTTP API. This class may change at any time and this will break any dependencies on it.

Hierarchy

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

Expanded class hierarchy of FormatSetter

See also

https://www.drupal.org/project/jsonapi/issues/3032787

jsonapi.api.php

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

File

src/StackMiddleware/FormatSetter.php, line 18

Namespace

Drupal\jsonapi\StackMiddleware
View source
final class FormatSetter implements HttpKernelInterface {

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

  /**
   * Constructs a FormatSetter 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) {
    $accepted = AcceptHeader::fromString($request->headers
      ->get('Accept'));
    if ($accepted
      ->get('application/vnd.api+json')) {
      $request
        ->setRequestFormat('api_json');
    }
    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 FormatSetter object.