Class ResponseTransformer

This class converts PSR7 responses into CakePHP ones and back again.

By bridging the CakePHP and PSR7 responses together, applications can be embedded as PSR7 middleware in a fully compatible way.

Namespace: Cake\Http

Method Summary

  • buildCookieHeader() protected static

    Convert an array of cookies into header lines.

  • collapseHeaders() protected static

    Convert a PSR7 Response headers into a flat array

  • getBody() protected static

    Get the response body from a PSR7 Response.

  • getStream() protected static

    Get the stream for the new response.

  • parseCookies() protected static

    Parse the Set-Cookie headers in a PSR7 response into the format CakePHP expects.

  • setContentType() protected static

    Add in the Content-Type header if necessary.

  • toCake() public static

    Convert a PSR7 Response into a CakePHP one.

  • toPsr() public static

    Convert a CakePHP response into a PSR7 one.

Method Detail

buildCookieHeader() protected static

buildCookieHeader(mixed $cookies)

Convert an array of cookies into header lines.

Parameters

array $cookies

The cookies to serialize.

Returns

array

A list of cookie header values.

collapseHeaders() protected static

collapseHeaders(\Psr\Http\Message\ResponseInterface $response)

Convert a PSR7 Response headers into a flat array

Parameters

\Psr\Http\Message\ResponseInterface $response

The response to convert.

Returns

array

Headers.

getBody() protected static

getBody(\Psr\Http\Message\ResponseInterface $response)

Get the response body from a PSR7 Response.

Parameters

\Psr\Http\Message\ResponseInterface $response

The response to convert.

Returns

array

A hash of 'body' and 'file'

getStream() protected static

getStream(mixed $response)

Get the stream for the new response.

Parameters

\Cake\Http\Response $response

The cake response to extract the body from.

Returns

\Psr\Http\Message\StreamInterface|string

The stream.

parseCookies() protected static

parseCookies(array $cookieHeader)

Parse the Set-Cookie headers in a PSR7 response into the format CakePHP expects.

Parameters

array $cookieHeader

A list of Set-Cookie headers.

Returns

array

Parsed cookie data.

setContentType() protected static

setContentType(mixed $headers, mixed $response)

Add in the Content-Type header if necessary.

Parameters

array $headers

The headers to update

\Cake\Http\Response $response

The CakePHP response to convert

Returns

array

The updated headers.

toCake() public static

toCake(\Psr\Http\Message\ResponseInterface $response)

Convert a PSR7 Response into a CakePHP one.

Parameters

\Psr\Http\Message\ResponseInterface $response

The response to convert.

Returns

\Cake\Http\Response

The equivalent CakePHP response

toPsr() public static

toPsr(\Cake\Http\Response $response)

Convert a CakePHP response into a PSR7 one.

Parameters

\Cake\Http\Response $response

The CakePHP response to convert

Returns

\Psr\Http\Message\ResponseInterface

$response The equivalent PSR7 response.

© 2005–present The Cake Software Foundation, Inc.
Licensed under the MIT License.
CakePHP is a registered trademark of Cake Software Foundation, Inc.
We are not endorsed by or affiliated with CakePHP.
https://api.cakephp.org/3.9/class-Cake.Http.ResponseTransformer.html