Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix incompatibility in response->body(callable) & PSR7 stack
The old response->body() interface doesn't involve returning a string, so it isn't going to work with CallbackStream. Furthermore there is an incompatibility with CallbackStream and SapiStreamEmitter. These changes work around both of those issues by creating a more permissive CallbackStream and only using SapiStreamEmitter on seekable streams. Refs #9408
- Loading branch information
Showing
5 changed files
with
88 additions
and
1 deletion.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
<?php | ||
/** | ||
* CakePHP(tm) : Rapid Development Framework (http://cakephp.org) | ||
* Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org) | ||
* | ||
* Licensed under The MIT License | ||
* For full copyright and license information, please see the LICENSE.txt | ||
* Redistributions of files must retain the above copyright notice. | ||
* | ||
* @copyright Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org) | ||
* @link http://cakephp.org CakePHP(tm) Project | ||
* @since 3.3.4 | ||
* @license http://www.opensource.org/licenses/mit-license.php MIT License | ||
*/ | ||
namespace Cake\Http; | ||
|
||
use Zend\Diactoros\CallbackStream as BaseCallbackStream; | ||
|
||
/** | ||
* Implementation of PSR HTTP streams. | ||
* | ||
* This differs from Zend\Diactoros\Callback stream in that | ||
* it allows the use of `echo` inside the callback, and gracefully | ||
* handles the callback not returning a string. | ||
* | ||
* Ideally we can amend/update diactoros, but we need to figure | ||
* that out with the diactoros project. Until then we'll use this shim | ||
* to provide backwards compatiblity with existing CakePHP apps. | ||
* | ||
* @internal | ||
*/ | ||
class CallbackStream extends BaseCallbackStream | ||
{ | ||
/** | ||
* {@inheritdoc} | ||
*/ | ||
public function getContents() | ||
{ | ||
$callback = $this->detach(); | ||
$result = $callback ? $callback() : ''; | ||
if (!is_string($result)) { | ||
return ''; | ||
} | ||
return $result; | ||
} | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
<?php | ||
namespace Zend\Diactoros\Response; | ||
|
||
function headers_sent() | ||
{ | ||
return false; | ||
} | ||
|
||
function header($header) | ||
{ | ||
$GLOBALS['mockedHeaders'][] = $header; | ||
} |