-
-
Notifications
You must be signed in to change notification settings - Fork 125
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
c694d94
commit 4986805
Showing
7 changed files
with
166 additions
and
40 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
<?php declare(strict_types=1); | ||
|
||
namespace League\Route\Strategy; | ||
|
||
use Psr\Http\Message\ResponseInterface; | ||
|
||
abstract class AbstractStrategy implements StrategyInterface | ||
{ | ||
/** @var array */ | ||
protected $defaultResponseHeaders = []; | ||
|
||
/** | ||
* Get current default response headers | ||
* | ||
* @return array | ||
*/ | ||
public function getDefaultResponseHeaders() : array | ||
{ | ||
return $this->defaultResponseHeaders; | ||
} | ||
|
||
/** | ||
* Add or replace a default response header | ||
* | ||
* @param string $name | ||
* @param string $value | ||
* @return static | ||
*/ | ||
public function addDefaultResponseHeader(string $name, string $value) : AbstractStrategy | ||
{ | ||
$this->defaultResponseHeaders[strtolower($name)] = $value; | ||
|
||
return $this; | ||
} | ||
|
||
/** | ||
* Add multiple default response headers | ||
* | ||
* @param array $headers | ||
* @return static | ||
*/ | ||
public function addDefaultResponseHeaders(array $headers) : AbstractStrategy | ||
{ | ||
foreach ($headers as $name => $value) { | ||
$this->addDefaultResponseHeader($name, $value); | ||
} | ||
|
||
return $this; | ||
} | ||
|
||
/** | ||
* Apply default response headers | ||
* | ||
* Headers that already exist on the response will NOT be replaced. | ||
* | ||
* @param \Psr\Http\Message\ResponseInterface $response | ||
* @return \Psr\Http\Message\ResponseInterface | ||
*/ | ||
protected function applyDefaultResponseHeaders(ResponseInterface $response) : ResponseInterface | ||
{ | ||
foreach ($this->defaultResponseHeaders as $name => $value) { | ||
if (! $response->hasHeader($name)) { | ||
$response = $response->withHeader($name, $value); | ||
} | ||
} | ||
|
||
return $response; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters