Requests are considered immutable; all methods that might change state are implemented such that they retain the internal state of the current message and return a new instance that contains the changed state.
Наследование: implements Psr\Http\Message\RequestInterface, use trait MessageTrait, use trait RequestTrait
Пример #1
0
 /**
  * @group 39
  */
 public function testGetHostHeaderLineReturnsNullIfUriDoesNotContainHost()
 {
     $request = new Request(new Uri());
     $this->assertNull($request->getHeaderLine('host'));
 }
Пример #2
0
 /**
  * @group 39
  */
 public function testGetHostHeaderLinesReturnsEmptyArrayIfUriDoesNotContainHost()
 {
     $request = new Request(new Uri());
     $header = $request->getHeaderLines('host');
     $this->assertSame([], $header);
 }
Пример #3
0
 /**
  * Build PSR Request.
  *
  * @return Psr\Http\Message\RequestInterface;
  */
 public function getRequest()
 {
     // Handle path parameters.
     $path_replacements = array();
     foreach ($this->parameters['path'] as $name => $value) {
         // We could coerce the value into a string, but it's not
         // clearly defined how we should do it.
         if (!is_scalar($value)) {
             throw new \RuntimeException('Path parameter "' . $name . '" not scalar.');
         }
         $path_replacements['{' . $name . '}'] = $value;
     }
     $url = $this->endpoint . strtr(ltrim($this->path, '/'), $path_replacements);
     // Handle query parameters.
     $query = $this->buildQuery($this->parameters['query']);
     $url = $url . '?' . $query;
     // There can only be one body.
     $body = reset($this->parameters['body']);
     if (!is_string($body)) {
         // Serialize if it's not a simple string.
         $body = $this->serializer->serialize($body);
     }
     $request = new Request($url, $this->method, new Stream('php://memory', 'w'), array());
     $request->getBody()->write($body);
     return $request;
 }
Пример #4
0
 /**
  * @param null|string|\Psr\Http\Message\UriInterface            $uri        The request uri.
  * @param null|string                                           $method     The request method.
  * @param string|resource|\Psr\Http\Message\StreamableInterface $body       The request body.
  * @param array                                                 $headers    The request headers.
  * @param array                                                 $parameters The request parameters.
  */
 public function __construct($uri = null, $method = null, $body = 'php://memory', array $headers = array(), array $parameters = array())
 {
     parent::__construct($uri, $method, $body, $headers);
     $this->parameters = $parameters;
 }