Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Adds request and response stacking to the merge header listener (see #…
…1076).
- Loading branch information
Showing
7 changed files
with
360 additions
and
34 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,38 @@ | ||
<?php | ||
|
||
/* | ||
* This file is part of Contao. | ||
* | ||
* Copyright (c) 2005-2017 Leo Feyer | ||
* | ||
* @license LGPL-3.0+ | ||
*/ | ||
|
||
namespace Contao\CoreBundle\HttpKernel\Header; | ||
|
||
/** | ||
* Interface for HTTP header storage. | ||
* | ||
* @author Andreas Schempp <https://github.com/aschempp> | ||
*/ | ||
interface HeaderStorageInterface | ||
{ | ||
/** | ||
* Returns all headers. | ||
* | ||
* @return array | ||
*/ | ||
public function all(); | ||
|
||
/** | ||
* Adds a header to the storage. | ||
* | ||
* @param string $header | ||
*/ | ||
public function add($header); | ||
|
||
/** | ||
* Clears the storage. | ||
*/ | ||
public function clear(); | ||
} |
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,58 @@ | ||
<?php | ||
|
||
/* | ||
* This file is part of Contao. | ||
* | ||
* Copyright (c) 2005-2017 Leo Feyer | ||
* | ||
* @license LGPL-3.0+ | ||
*/ | ||
|
||
namespace Contao\CoreBundle\HttpKernel\Header; | ||
|
||
/** | ||
* Handles HTTP headers in memory (for unit tests). | ||
* | ||
* @author Andreas Schempp <https://github.com/aschempp> | ||
*/ | ||
class MemoryHeaderStorage implements HeaderStorageInterface | ||
{ | ||
/** | ||
* @var array | ||
*/ | ||
private $headers = []; | ||
|
||
/** | ||
* Constructor. | ||
* | ||
* @param array $headers | ||
*/ | ||
public function __construct(array $headers = []) | ||
{ | ||
$this->headers = $headers; | ||
} | ||
|
||
/** | ||
* {@inheritdoc} | ||
*/ | ||
public function all() | ||
{ | ||
return $this->headers; | ||
} | ||
|
||
/** | ||
* {@inheritdoc} | ||
*/ | ||
public function add($header) | ||
{ | ||
$this->headers[] = $header; | ||
} | ||
|
||
/** | ||
* {@inheritdoc} | ||
*/ | ||
public function clear() | ||
{ | ||
$this->headers = []; | ||
} | ||
} |
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,45 @@ | ||
<?php | ||
|
||
/* | ||
* This file is part of Contao. | ||
* | ||
* Copyright (c) 2005-2017 Leo Feyer | ||
* | ||
* @license LGPL-3.0+ | ||
*/ | ||
|
||
namespace Contao\CoreBundle\HttpKernel\Header; | ||
|
||
/** | ||
* Handles HTTP headers in PHP's native methods. | ||
* | ||
* @author Andreas Schempp <https://github.com/aschempp> | ||
*/ | ||
class NativeHeaderStorage implements HeaderStorageInterface | ||
{ | ||
/** | ||
* {@inheritdoc} | ||
*/ | ||
public function all() | ||
{ | ||
return headers_list(); | ||
} | ||
|
||
/** | ||
* {@inheritdoc} | ||
*/ | ||
public function add($header) | ||
{ | ||
header($header); | ||
} | ||
|
||
/** | ||
* {@inheritdoc} | ||
*/ | ||
public function clear() | ||
{ | ||
if ('cli' !== PHP_SAPI && !headers_sent()) { | ||
header_remove(); | ||
} | ||
} | ||
} |
Oops, something went wrong.