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.
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(array $cookies): array
Convert an array of cookies into header lines.
Parameters
-
array
$cookies The cookies to serialize.
Returns
array
collapseHeaders() ¶ protected static
collapseHeaders(Psr\Http\Message\ResponseInterface $response): Cake\Network\Response
Convert a PSR7 Response headers into a flat array
Parameters
-
Psr\Http\Message\ResponseInterface
$response The response to convert.
Returns
Cake\Network\Response
getBody() ¶ protected static
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
getStream() ¶ protected static
getStream(Cake\Network\Response $response): Psr\Http\Message\StreamInterface|string
Get the stream for the new response.
Parameters
-
Cake\Network\Response
$response The cake response to extract the body from.
Returns
Psr\Http\Message\StreamInterface|string
parseCookies() ¶ protected static
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
setContentType() ¶ protected static
setContentType(array $headers, Cake\Network\Response $response): array
Add in the Content-Type header if necessary.
Parameters
-
array
$headers The headers to update
-
Cake\Network\Response
$response The CakePHP response to convert
Returns
array
toCake() ¶ public static
toCake(Psr\Http\Message\ResponseInterface $response): Cake\Network\Response
Convert a PSR7 Response into a CakePHP one.
Parameters
-
Psr\Http\Message\ResponseInterface
$response The response to convert.
Returns
Cake\Network\Response
toPsr() ¶ public static
toPsr(Cake\Network\Response $response): Psr\Http\Message\ResponseInterface
Convert a CakePHP response into a PSR7 one.
Parameters
-
Cake\Network\Response
$response The CakePHP response to convert
Returns
Psr\Http\Message\ResponseInterface