[ Index ]

PHP Cross Reference of Joomla 4.2.2 documentation

title

Body

[close]

/libraries/vendor/laminas/laminas-diactoros/src/functions/ -> normalize_server.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 function is_callable;
  14  
  15  /**
  16   * Marshal the $_SERVER array
  17   *
  18   * Pre-processes and returns the $_SERVER superglobal. In particularly, it
  19   * attempts to detect the Authorization header, which is often not aggregated
  20   * correctly under various SAPI/httpd combinations.
  21   *
  22   * @param null|callable $apacheRequestHeaderCallback Callback that can be used to
  23   *     retrieve Apache request headers. This defaults to
  24   *     `apache_request_headers` under the Apache mod_php.
  25   * @return array Either $server verbatim, or with an added HTTP_AUTHORIZATION header.
  26   */
  27  function normalizeServer(array $server, callable $apacheRequestHeaderCallback = null) : array
  28  {
  29      if (null === $apacheRequestHeaderCallback && is_callable('apache_request_headers')) {
  30          $apacheRequestHeaderCallback = 'apache_request_headers';
  31      }
  32  
  33      // If the HTTP_AUTHORIZATION value is already set, or the callback is not
  34      // callable, we return verbatim
  35      if (isset($server['HTTP_AUTHORIZATION'])
  36          || ! is_callable($apacheRequestHeaderCallback)
  37      ) {
  38          return $server;
  39      }
  40  
  41      $apacheRequestHeaders = $apacheRequestHeaderCallback();
  42      if (isset($apacheRequestHeaders['Authorization'])) {
  43          $server['HTTP_AUTHORIZATION'] = $apacheRequestHeaders['Authorization'];
  44          return $server;
  45      }
  46  
  47      if (isset($apacheRequestHeaders['authorization'])) {
  48          $server['HTTP_AUTHORIZATION'] = $apacheRequestHeaders['authorization'];
  49          return $server;
  50      }
  51  
  52      return $server;
  53  }


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