alexpts/psr15-middlewares

View on GitHub
src/StaticHeaderDefault.php

Summary

Maintainability
A
0 mins
Test Coverage
<?php
declare(strict_types=1);

namespace PTS\PSR15\Middlewares;

use InvalidArgumentException;
use Psr\Http\Message\ResponseInterface;

class StaticHeaderDefault extends StaticHeader
{
    /**
     * @param ResponseInterface $response
     * @param array $headers
     *
     * @return ResponseInterface
     *
     * @throws InvalidArgumentException
     */
    protected function withStaticHeaders(ResponseInterface $response, array $headers): ResponseInterface
    {
        foreach ($headers as $name => $header) {
            if (!$response->hasHeader($name)) {
                $response = $response->withHeader($name, $header);
            }
        }

        return $response;
    }
}