Skip to content

Latest commit

 

History

History
73 lines (51 loc) · 2.17 KB

File metadata and controls

73 lines (51 loc) · 2.17 KB

response-interop/impl

PDS Skeleton PDS Composer Script Names

Reference implementations of the Response-Interop interfaces for PHP 8.4+.

Installation

composer require response-interop/impl

Usage

Build a ResponseStruct, populate it, and hand it to a ResponseSenderService:

use ResponseInterop\Impl\Response;
use ResponseInterop\Impl\ResponseSender;

$response = new Response();
$response->headers->setHeader('content-type', 'text/plain');
$response->body = 'Hello, world!';

(new ResponseSender())->sendResponse($response);

Set a cookie:

$response->headers->setCookie('session', 'abc123', [
    'path' => '/',
    'httponly' => true,
    'samesite' => 'Lax',
]);

Send a JSON body:

use ResponseInterop\Impl\JsonResponseBody;

$response->body = new JsonResponseBody(['hello' => 'world']);

Send a file:

use ResponseInterop\Impl\FileResponseBody;

$response->body = new FileResponseBody(new SplFileObject('/path/to/file.pdf'));

Classes

Interface Implementation
ResponseStruct Response
ResponseHeadersCollection ResponseHeaders
ResponseBodyHandler FileResponseBody, JsonResponseBody
ResponseCookieHelperService ResponseCookieHelper
ResponseSenderService ResponseSender
ResponseBodySenderService ResponseSender
ResponseThrowable ResponseException

All classes are in the ResponseInterop\Impl namespace.

See the Response-Interop interface package for the full specification.