[ Index ]

PHP Cross Reference of Joomla 4.2.2 documentation

title

Body

[close]

/libraries/vendor/nyholm/psr7/src/ -> ServerRequest.php (source)

   1  <?php
   2  
   3  declare(strict_types=1);
   4  
   5  namespace Nyholm\Psr7;
   6  
   7  use Psr\Http\Message\{ServerRequestInterface, StreamInterface, UploadedFileInterface, UriInterface};
   8  
   9  /**
  10   * @author Michael Dowling and contributors to guzzlehttp/psr7
  11   * @author Tobias Nyholm <[email protected]>
  12   * @author Martijn van der Ven <[email protected]>
  13   *
  14   * @final This class should never be extended. See https://github.com/Nyholm/psr7/blob/master/doc/final.md
  15   */
  16  class ServerRequest implements ServerRequestInterface
  17  {
  18      use MessageTrait;
  19      use RequestTrait;
  20  
  21      /** @var array */
  22      private $attributes = [];
  23  
  24      /** @var array */
  25      private $cookieParams = [];
  26  
  27      /** @var array|object|null */
  28      private $parsedBody;
  29  
  30      /** @var array */
  31      private $queryParams = [];
  32  
  33      /** @var array */
  34      private $serverParams;
  35  
  36      /** @var UploadedFileInterface[] */
  37      private $uploadedFiles = [];
  38  
  39      /**
  40       * @param string $method HTTP method
  41       * @param string|UriInterface $uri URI
  42       * @param array $headers Request headers
  43       * @param string|resource|StreamInterface|null $body Request body
  44       * @param string $version Protocol version
  45       * @param array $serverParams Typically the $_SERVER superglobal
  46       */
  47      public function __construct(string $method, $uri, array $headers = [], $body = null, string $version = '1.1', array $serverParams = [])
  48      {
  49          $this->serverParams = $serverParams;
  50  
  51          if (!($uri instanceof UriInterface)) {
  52              $uri = new Uri($uri);
  53          }
  54  
  55          $this->method = $method;
  56          $this->uri = $uri;
  57          $this->setHeaders($headers);
  58          $this->protocol = $version;
  59  
  60          if (!$this->hasHeader('Host')) {
  61              $this->updateHostFromUri();
  62          }
  63  
  64          // If we got no body, defer initialization of the stream until ServerRequest::getBody()
  65          if ('' !== $body && null !== $body) {
  66              $this->stream = Stream::create($body);
  67          }
  68      }
  69  
  70      public function getServerParams(): array
  71      {
  72          return $this->serverParams;
  73      }
  74  
  75      public function getUploadedFiles(): array
  76      {
  77          return $this->uploadedFiles;
  78      }
  79  
  80      public function withUploadedFiles(array $uploadedFiles)
  81      {
  82          $new = clone $this;
  83          $new->uploadedFiles = $uploadedFiles;
  84  
  85          return $new;
  86      }
  87  
  88      public function getCookieParams(): array
  89      {
  90          return $this->cookieParams;
  91      }
  92  
  93      public function withCookieParams(array $cookies)
  94      {
  95          $new = clone $this;
  96          $new->cookieParams = $cookies;
  97  
  98          return $new;
  99      }
 100  
 101      public function getQueryParams(): array
 102      {
 103          return $this->queryParams;
 104      }
 105  
 106      public function withQueryParams(array $query)
 107      {
 108          $new = clone $this;
 109          $new->queryParams = $query;
 110  
 111          return $new;
 112      }
 113  
 114      public function getParsedBody()
 115      {
 116          return $this->parsedBody;
 117      }
 118  
 119      public function withParsedBody($data)
 120      {
 121          if (!\is_array($data) && !\is_object($data) && null !== $data) {
 122              throw new \InvalidArgumentException('First parameter to withParsedBody MUST be object, array or null');
 123          }
 124  
 125          $new = clone $this;
 126          $new->parsedBody = $data;
 127  
 128          return $new;
 129      }
 130  
 131      public function getAttributes(): array
 132      {
 133          return $this->attributes;
 134      }
 135  
 136      /**
 137       * @return mixed
 138       */
 139      public function getAttribute($attribute, $default = null)
 140      {
 141          if (false === \array_key_exists($attribute, $this->attributes)) {
 142              return $default;
 143          }
 144  
 145          return $this->attributes[$attribute];
 146      }
 147  
 148      public function withAttribute($attribute, $value): self
 149      {
 150          $new = clone $this;
 151          $new->attributes[$attribute] = $value;
 152  
 153          return $new;
 154      }
 155  
 156      public function withoutAttribute($attribute): self
 157      {
 158          if (false === \array_key_exists($attribute, $this->attributes)) {
 159              return $this;
 160          }
 161  
 162          $new = clone $this;
 163          unset($new->attributes[$attribute]);
 164  
 165          return $new;
 166      }
 167  }


Generated: Wed Sep 7 05:41:13 2022 Chilli.vc Blog - For Webmaster,Blog-Writer,System Admin and Domainer