\Cake\HttpResponseTransformer

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.

Summary

Methods
Properties
Constants
toCake()
toPsr()
No public properties found
No constants found
getBody()
parseCookies()
collapseHeaders()
setContentType()
buildCookieHeader()
getStream()
No protected properties found
N/A
No private methods found
No private properties found
N/A

Methods

toCake()

toCake(\Psr\Http\Message\ResponseInterface  $response) : \Cake\Http\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()

toPsr(\Cake\Http\Response  $response) : \Psr\Http\Message\ResponseInterface

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.

getBody()

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

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'

parseCookies()

parseCookies(array  $cookieHeader) : array

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.

collapseHeaders()

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

Convert a PSR7 Response headers into a flat array

Parameters

\Psr\Http\Message\ResponseInterface $response

The response to convert.

Returns

array —

Headers.

setContentType()

setContentType(array  $headers, \Cake\Http\Response  $response) : array

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.

buildCookieHeader()

buildCookieHeader(array  $cookies) : array

Convert an array of cookies into header lines.

Parameters

array $cookies

The cookies to serialize.

Returns

array —

A list of cookie header values.

getStream()

getStream(\Cake\Http\Response  $response) : \Psr\Http\Message\StreamInterface|string

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.