You are here

private function InjectContentTypeTrait::injectContentType 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::injectContentType()

Inject the provided Content-Type, if none is already present.

Parameters

string $contentType:

array $headers:

Return value

array Headers with injected Content-Type

2 calls to InjectContentTypeTrait::injectContentType()
HtmlResponse::__construct in vendor/zendframework/zend-diactoros/src/Response/HtmlResponse.php
Create an HTML response.
JsonResponse::__construct in vendor/zendframework/zend-diactoros/src/Response/JsonResponse.php
Create a JSON response with the given data.

File

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

Class

InjectContentTypeTrait

Namespace

Zend\Diactoros\Response

Code

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;
}