You are here

public function DiactorosFactory::createRequest in Zircon Profile 8

Same name and namespace in other branches
  1. 8.0 vendor/symfony/psr-http-message-bridge/Factory/DiactorosFactory.php \Symfony\Bridge\PsrHttpMessage\Factory\DiactorosFactory::createRequest()

Creates a PSR-7 Request instance from a Symfony one.

Parameters

Request $symfonyRequest:

Return value

ServerRequestInterface

Overrides HttpMessageFactoryInterface::createRequest

File

vendor/symfony/psr-http-message-bridge/Factory/DiactorosFactory.php, line 43

Class

DiactorosFactory
Builds Psr\HttpMessage instances using the Zend Diactoros implementation.

Namespace

Symfony\Bridge\PsrHttpMessage\Factory

Code

public function createRequest(Request $symfonyRequest) {
  $server = DiactorosRequestFactory::normalizeServer($symfonyRequest->server
    ->all());
  $headers = $symfonyRequest->headers
    ->all();
  try {
    $body = new DiactorosStream($symfonyRequest
      ->getContent(true));
  } catch (\LogicException $e) {
    $body = new DiactorosStream('php://temp', 'wb+');
    $body
      ->write($symfonyRequest
      ->getContent());
  }
  $request = new ServerRequest($server, DiactorosRequestFactory::normalizeFiles($this
    ->getFiles($symfonyRequest->files
    ->all())), $symfonyRequest
    ->getUri(), $symfonyRequest
    ->getMethod(), $body, $headers);
  $request = $request
    ->withCookieParams($symfonyRequest->cookies
    ->all())
    ->withQueryParams($symfonyRequest->query
    ->all())
    ->withParsedBody($symfonyRequest->request
    ->all());
  foreach ($symfonyRequest->attributes
    ->all() as $key => $value) {
    $request = $request
      ->withAttribute($key, $value);
  }
  return $request;
}