[ Index ]

PHP Cross Reference of Joomla 4.2.2 documentation

title

Body

[close]

/libraries/vendor/laminas/laminas-diactoros/src/Response/ -> InjectContentTypeTrait.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\Response;
  12  
  13  use function array_keys;
  14  use function array_reduce;
  15  use function strtolower;
  16  
  17  trait InjectContentTypeTrait
  18  {
  19      /**
  20       * Inject the provided Content-Type, if none is already present.
  21       *
  22       * @return array Headers with injected Content-Type
  23       */
  24      private function injectContentType(string $contentType, array $headers) : array
  25      {
  26          $hasContentType = array_reduce(array_keys($headers), function ($carry, $item) {
  27              return $carry ?: (strtolower($item) === 'content-type');
  28          }, false);
  29  
  30          if (! $hasContentType) {
  31              $headers['content-type'] = [$contentType];
  32          }
  33  
  34          return $headers;
  35      }
  36  }


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