You are here

private function RequestTrait::initialize in Zircon Profile 8

Same name and namespace in other branches
  1. 8.0 vendor/zendframework/zend-diactoros/src/RequestTrait.php \Zend\Diactoros\RequestTrait::initialize()

Initialize request state.

Used by constructors.

Parameters

null|string $uri URI for the request, if any.:

null|string $method HTTP method for the request, if any.:

string|resource|StreamInterface $body Message body, if any.:

array $headers Headers for the message, if any.:

Throws

InvalidArgumentException for any invalid value.

File

vendor/zendframework/zend-diactoros/src/RequestTrait.php, line 61

Class

RequestTrait
Trait with common request behaviors.

Namespace

Zend\Diactoros

Code

private function initialize($uri = null, $method = null, $body = 'php://memory', array $headers = []) {
  if (!$uri instanceof UriInterface && !is_string($uri) && null !== $uri) {
    throw new InvalidArgumentException('Invalid URI provided; must be null, a string, or a Psr\\Http\\Message\\UriInterface instance');
  }
  $this
    ->validateMethod($method);
  if (!is_string($body) && !is_resource($body) && !$body instanceof StreamInterface) {
    throw new InvalidArgumentException('Body must be a string stream resource identifier, ' . 'an actual stream resource, ' . 'or a Psr\\Http\\Message\\StreamInterface implementation');
  }
  if (is_string($uri)) {
    $uri = new Uri($uri);
  }
  $this->method = $method ?: '';
  $this->uri = $uri ?: new Uri();
  $this->stream = $body instanceof StreamInterface ? $body : new Stream($body, 'wb+');
  list($this->headerNames, $headers) = $this
    ->filterHeaders($headers);
  $this
    ->assertHeaders($headers);
  $this->headers = $headers;
}