445e1324b3876fee4f9aa277230788321d00b11d
[yaffs-website] / vendor / zendframework / zend-diactoros / src / Response / InjectContentTypeTrait.php
1 <?php
2 /**
3  * Zend Framework (http://framework.zend.com/)
4  *
5  * @see       http://github.com/zendframework/zend-diactoros for the canonical source repository
6  * @copyright Copyright (c) 2015-2016 Zend Technologies USA Inc. (http://www.zend.com)
7  * @license   https://github.com/zendframework/zend-diactoros/blob/master/LICENSE.md New BSD License
8  */
9
10 namespace Zend\Diactoros\Response;
11
12 use function array_keys;
13 use function array_reduce;
14 use function strtolower;
15
16 trait InjectContentTypeTrait
17 {
18     /**
19      * Inject the provided Content-Type, if none is already present.
20      *
21      * @param string $contentType
22      * @param array $headers
23      * @return array Headers with injected Content-Type
24      */
25     private function injectContentType($contentType, array $headers)
26     {
27         $hasContentType = array_reduce(array_keys($headers), function ($carry, $item) {
28             return $carry ?: (strtolower($item) === 'content-type');
29         }, false);
30
31         if (! $hasContentType) {
32             $headers['content-type'] = [$contentType];
33         }
34
35         return $headers;
36     }
37 }