getBody()->getMetadata('uri'); if ($uri === static::URI_TEMP || $uri === static::URI_MEMORY) { $response = sprintf( "HTTP/%s %d %s\r\n%s\r\n%s", $psr7Response->getProtocolVersion(), $psr7Response->getStatusCode(), $psr7Response->getReasonPhrase(), self::psr7HeadersToString($psr7Response), (string)$psr7Response->getBody() ); return ZendResponse::fromString($response); } $response = new ZendResponse\Stream(); $zendHeaders = Headers::fromString(self::psr7HeadersToString($psr7Response)); $response->setStatusCode($psr7Response->getStatusCode()); $response->setHeaders($zendHeaders); $response->setStream(fopen($uri, 'rb')); return $response; } /** * Convert a Zend\Http\Response in a PSR-7 response, using zend-diactoros * * @param ZendResponse $zendResponse * * @return Response */ public static function fromZend(ZendResponse $zendResponse) { $body = new Stream('php://temp', 'wb+'); $body->write($zendResponse->getBody()); return new Response( $body, $zendResponse->getStatusCode(), $zendResponse->getHeaders()->toArray() ); } /** * Convert the PSR-7 headers to string * * @param ResponseInterface $psr7Response * * @return string */ private static function psr7HeadersToString(ResponseInterface $psr7Response) { $headers = ''; foreach ($psr7Response->getHeaders() as $name => $value) { $headers .= $name . ": " . implode(", ", $value) . "\r\n"; } return $headers; } /** * Do not allow instantiation. */ private function __construct() { } }