[ Index ]

PHP Cross Reference of Joomla 4.2.2 documentation

title

Body

[close]

/libraries/vendor/laminas/laminas-diactoros/src/ -> Request.php (source)

   1  <?php
   2  
   3  /**
   4   * @see       https://github.com/laminas/laminas-diactoros for the canonical source repository
   5   * @copyright https://github.com/laminas/laminas-diactoros/blob/master/COPYRIGHT.md
   6   * @license   https://github.com/laminas/laminas-diactoros/blob/master/LICENSE.md New BSD License
   7   */
   8  
   9  declare(strict_types=1);
  10  
  11  namespace Laminas\Diactoros;
  12  
  13  use Psr\Http\Message\RequestInterface;
  14  use Psr\Http\Message\StreamInterface;
  15  use Psr\Http\Message\UriInterface;
  16  
  17  use function strtolower;
  18  
  19  /**
  20   * HTTP Request encapsulation
  21   *
  22   * Requests are considered immutable; all methods that might change state are
  23   * implemented such that they retain the internal state of the current
  24   * message and return a new instance that contains the changed state.
  25   */
  26  class Request implements RequestInterface
  27  {
  28      use RequestTrait;
  29  
  30      /**
  31       * @param null|string|UriInterface $uri URI for the request, if any.
  32       * @param null|string $method HTTP method for the request, if any.
  33       * @param string|resource|StreamInterface $body Message body, if any.
  34       * @param array $headers Headers for the message, if any.
  35       * @throws Exception\InvalidArgumentException for any invalid value.
  36       */
  37      public function __construct($uri = null, string $method = null, $body = 'php://temp', array $headers = [])
  38      {
  39          $this->initialize($uri, $method, $body, $headers);
  40      }
  41  
  42      /**
  43       * {@inheritdoc}
  44       */
  45      public function getHeaders() : array
  46      {
  47          $headers = $this->headers;
  48          if (! $this->hasHeader('host')
  49              && $this->uri->getHost()
  50          ) {
  51              $headers['Host'] = [$this->getHostFromUri()];
  52          }
  53  
  54          return $headers;
  55      }
  56  
  57      /**
  58       * {@inheritdoc}
  59       */
  60      public function getHeader($header) : array
  61      {
  62          if (! $this->hasHeader($header)) {
  63              if (strtolower($header) === 'host'
  64                  && $this->uri->getHost()
  65              ) {
  66                  return [$this->getHostFromUri()];
  67              }
  68  
  69              return [];
  70          }
  71  
  72          $header = $this->headerNames[strtolower($header)];
  73  
  74          return $this->headers[$header];
  75      }
  76  }


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