[ Index ]

PHP Cross Reference of Joomla 4.2.2 documentation

title

Body

[close]

/libraries/vendor/laminas/laminas-diactoros/src/ -> ServerRequestFactory.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\ServerRequestFactoryInterface;
  14  use Psr\Http\Message\ServerRequestInterface;
  15  
  16  use function array_key_exists;
  17  use function is_callable;
  18  
  19  /**
  20   * Class for marshaling a request object from the current PHP environment.
  21   *
  22   * Logic largely refactored from the Laminas Laminas\Http\PhpEnvironment\Request class.
  23   *
  24   * @copyright Copyright (c) 2005-2015 Laminas (https://www.zend.com)
  25   * @license   https://getlaminas.org/license/new-bsd New BSD License
  26   */
  27  class ServerRequestFactory implements ServerRequestFactoryInterface
  28  {
  29      /**
  30       * Function to use to get apache request headers; present only to simplify mocking.
  31       *
  32       * @var callable
  33       */
  34      private static $apacheRequestHeaders = 'apache_request_headers';
  35  
  36      /**
  37       * Create a request from the supplied superglobal values.
  38       *
  39       * If any argument is not supplied, the corresponding superglobal value will
  40       * be used.
  41       *
  42       * The ServerRequest created is then passed to the fromServer() method in
  43       * order to marshal the request URI and headers.
  44       *
  45       * @see fromServer()
  46       * @param array $server $_SERVER superglobal
  47       * @param array $query $_GET superglobal
  48       * @param array $body $_POST superglobal
  49       * @param array $cookies $_COOKIE superglobal
  50       * @param array $files $_FILES superglobal
  51       * @return ServerRequest
  52       */
  53      public static function fromGlobals(
  54          array $server = null,
  55          array $query = null,
  56          array $body = null,
  57          array $cookies = null,
  58          array $files = null
  59      ) : ServerRequest {
  60          $server = normalizeServer(
  61              $server ?: $_SERVER,
  62              is_callable(self::$apacheRequestHeaders) ? self::$apacheRequestHeaders : null
  63          );
  64          $files   = normalizeUploadedFiles($files ?: $_FILES);
  65          $headers = marshalHeadersFromSapi($server);
  66  
  67          if (null === $cookies && array_key_exists('cookie', $headers)) {
  68              $cookies = parseCookieHeader($headers['cookie']);
  69          }
  70  
  71          return new ServerRequest(
  72              $server,
  73              $files,
  74              marshalUriFromSapi($server, $headers),
  75              marshalMethodFromSapi($server),
  76              'php://input',
  77              $headers,
  78              $cookies ?: $_COOKIE,
  79              $query ?: $_GET,
  80              $body ?: $_POST,
  81              marshalProtocolVersionFromSapi($server)
  82          );
  83      }
  84  
  85      /**
  86       * {@inheritDoc}
  87       */
  88      public function createServerRequest(string $method, $uri, array $serverParams = []) : ServerRequestInterface
  89      {
  90          $uploadedFiles = [];
  91  
  92          return new ServerRequest(
  93              $serverParams,
  94              $uploadedFiles,
  95              $uri,
  96              $method,
  97              'php://temp'
  98          );
  99      }
 100  }


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