You are here

InjectContentTypeTrait.php in Zircon Profile 8

File

vendor/zendframework/zend-diactoros/src/Response/InjectContentTypeTrait.php
View source
<?php

/**
 * Zend Framework (http://framework.zend.com/)
 *
 * @see       http://github.com/zendframework/zend-diactoros for the canonical source repository
 * @copyright Copyright (c) 2015 Zend Technologies USA Inc. (http://www.zend.com)
 * @license   https://github.com/zendframework/zend-diactoros/blob/master/LICENSE.md New BSD License
 */
namespace Zend\Diactoros\Response;

trait InjectContentTypeTrait {

  /**
   * Inject the provided Content-Type, if none is already present.
   *
   * @param string $contentType
   * @param array $headers
   * @return array Headers with injected Content-Type
   */
  private function injectContentType($contentType, array $headers) {
    $hasContentType = array_reduce(array_keys($headers), function ($carry, $item) {
      return $carry ?: strtolower($item) === 'content-type';
    }, false);
    if (!$hasContentType) {
      $headers['content-type'] = [
        $contentType,
      ];
    }
    return $headers;
  }

}

Traits