4f2caf842f681959b6b51b206ee7895ff16fdf3b
[yaffs-website] / 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 trait InjectContentTypeTrait
13 {
14     /**
15      * Inject the provided Content-Type, if none is already present.
16      *
17      * @param string $contentType
18      * @param array $headers
19      * @return array Headers with injected Content-Type
20      */
21     private function injectContentType($contentType, array $headers)
22     {
23         $hasContentType = array_reduce(array_keys($headers), function ($carry, $item) {
24             return $carry ?: (strtolower($item) === 'content-type');
25         }, false);
26
27         if (! $hasContentType) {
28             $headers['content-type'] = [$contentType];
29         }
30
31         return $headers;
32     }
33 }