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
9 declare(strict_types=1);
11 namespace Laminas\Diactoros\Response;
13 use function array_keys;
14 use function array_reduce;
15 use function strtolower;
17 trait InjectContentTypeTrait
20 * Inject the provided Content-Type, if none is already present.
22 * @return array Headers with injected Content-Type
24 private function injectContentType(string $contentType, array $headers) : array
26 $hasContentType = array_reduce(array_keys($headers), function ($carry, $item) {
27 return $carry ?: (strtolower($item) === 'content-type');
30 if (! $hasContentType) {
31 $headers['content-type'] = [$contentType];