920fe9ad7c1de1a8e9133c608314c43b04356aeb
[GitHub/WoltLab/WCF.git] /
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 }