[ Index ]

PHP Cross Reference of WordPress Trunk (Updated Daily)

Search

title

Body

[close]

/wp-includes/php-ai-client/third-party/Nyholm/Psr7/ -> ServerRequest.php (source)

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


Generated : Sat Jun 13 09:38:55 2026 Cross-referenced by PHPXref