Skip to content
This repository has been archived by the owner on Jul 6, 2024. It is now read-only.

Latest commit

 

History

History
37 lines (28 loc) · 1016 Bytes

AcceptAndContentTypeMiddleware.md

File metadata and controls

37 lines (28 loc) · 1016 Bytes

AcceptAndContentTypeMiddleware

<?php

use Chubbyphp\ApiHttp\Manager\ResponseManagerInterface;
use Chubbyphp\ApiHttp\Middleware\AcceptAndContentTypeMiddleware;
use Chubbyphp\Negotiation\AcceptNegotiatorInterface;
use Chubbyphp\Negotiation\ContentTypeNegotiatorInterface;
use Psr\Http\Message\ResponseInterface;
use Psr\Http\Message\ServerRequestInterface;
use Psr\Http\Server\RequestHandlerInterface;

/** @var ServerRequestInterface $request */
$request = ...;

/** @var RequestHandlerInterface $handler */
$handler = ...;

/** @var AcceptNegotiatorInterface $acceptNegotiator */
$acceptNegotiator = ...;

/** @var ContentTypeNegotiatorInterface $contentTypeNegotiator */
$contentTypeNegotiator = ...;

/** @var ResponseManagerInterface $responseManager */
$responseManager = ...;

$middleware = new AcceptAndContentTypeMiddleware(
    $acceptNegotiator,
    $contentTypeNegotiator,
    $responseManager
);

/** @var ResponseInterface $response */
$response = $middleware->process($request, $handler);