You are here

trait InjectContentTypeTrait in Zircon Profile 8

Same name and namespace in other branches
  1. 8.0 vendor/zendframework/zend-diactoros/src/Response/InjectContentTypeTrait.php \Zend\Diactoros\Response\InjectContentTypeTrait

Hierarchy

File

vendor/zendframework/zend-diactoros/src/Response/InjectContentTypeTrait.php, line 12

Namespace

Zend\Diactoros\Response
View source
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;
  }

}

Members

Namesort descending Modifiers Type Description Overrides
InjectContentTypeTrait::injectContentType private function Inject the provided Content-Type, if none is already present.