This repository has been archived by the owner on Jan 8, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2.5k
RFC Send Response Workflow #3105
Merged
Merged
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
bebaea6
WIP for RFC Send Response Workflow
prolic 170dc62
cs fixes
prolic c2cf0be
updated send response workflow
prolic e01df53
removed debug calls
prolic 011ecde
refactored send response workflow
prolic 2d48e88
added phpdoc
prolic 80dc333
reverted changes in Console Response
prolic 4ad81bd
added tests, some cleanup
prolic a18deed
cleanup in SendResponseListener
prolic File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
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,56 @@ | ||
<?php | ||
/** | ||
* Zend Framework (http://framework.zend.com/) | ||
* | ||
* @link http://github.com/zendframework/zf2 for the canonical source repository | ||
* @copyright Copyright (c) 2005-2012 Zend Technologies USA Inc. (http://www.zend.com) | ||
* @license http://framework.zend.com/license/new-bsd New BSD License | ||
* @package Zend_Mvc | ||
*/ | ||
|
||
namespace Zend\Mvc\ResponseSender; | ||
|
||
use Zend\Console\Response; | ||
|
||
/** | ||
* @category Zend | ||
* @package Zend_Mvc | ||
* @subpackage ResponseSender | ||
*/ | ||
class ConsoleResponseSender implements ResponseSenderInterface | ||
{ | ||
/** | ||
* Send content | ||
* | ||
* @param SendResponseEvent $event | ||
* @return ConsoleResponseSender | ||
*/ | ||
public function sendContent(SendResponseEvent $event) | ||
{ | ||
if ($event->contentSent()) { | ||
return $this; | ||
} | ||
$response = $event->getResponse(); | ||
echo $response->getContent(); | ||
$event->setContentSent(); | ||
return $this; | ||
} | ||
|
||
/** | ||
* Send the response | ||
* | ||
* @param SendResponseEvent $event | ||
* @return void | ||
*/ | ||
public function __invoke(SendResponseEvent $event) | ||
{ | ||
$response = $event->getResponse(); | ||
if ($response instanceof Response) { | ||
$this->sendContent($response); | ||
$errorLevel = (int) $response->getMetadata('errorLevel',0); | ||
$event->stopPropagation(true); | ||
exit($errorLevel); | ||
} | ||
} | ||
|
||
} |
84 changes: 84 additions & 0 deletions
84
library/Zend/Mvc/ResponseSender/PhpEnvironmentResponseSender.php
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,84 @@ | ||
<?php | ||
/** | ||
* Zend Framework (http://framework.zend.com/) | ||
* | ||
* @link http://github.com/zendframework/zf2 for the canonical source repository | ||
* @copyright Copyright (c) 2005-2012 Zend Technologies USA Inc. (http://www.zend.com) | ||
* @license http://framework.zend.com/license/new-bsd New BSD License | ||
* @package Zend_Mvc | ||
*/ | ||
|
||
namespace Zend\Mvc\ResponseSender; | ||
|
||
use Zend\Mvc\ResponseSender\SendResponseEvent; | ||
use Zend\Http\Header\MultipleHeaderInterface; | ||
use Zend\Http\PhpEnvironment\Response; | ||
|
||
/** | ||
* @category Zend | ||
* @package Zend_Mvc | ||
* @subpackage ResponseSender | ||
*/ | ||
class PhpEnvironmentResponseSender implements ResponseSenderInterface | ||
{ | ||
/** | ||
* Send HTTP headers | ||
* | ||
* @param SendResponseEvent $event | ||
* @return PhpEnvironmentResponseSender | ||
*/ | ||
public function sendHeaders(SendResponseEvent $event) | ||
{ | ||
$response = $event->getResponse(); | ||
if ($response->headersSent() || $event->headersSent()) { | ||
return $this; | ||
} | ||
$status = $response->renderStatusLine(); | ||
header($status); | ||
/* @var \Zend\Http\Header\HeaderInterface $header */ | ||
foreach ($response->getHeaders() as $header) { | ||
if ($header instanceof MultipleHeaderInterface) { | ||
header($header->toString(), false); | ||
continue; | ||
} | ||
header($header->toString()); | ||
} | ||
$event->setHeadersSent(); | ||
return $this; | ||
} | ||
|
||
/** | ||
* Send content | ||
* | ||
* @param SendResponseEvent $event | ||
* @return PhpEnvironmentResponseSender | ||
*/ | ||
public function sendContent(SendResponseEvent $event) | ||
{ | ||
if ($event->contentSent()) { | ||
return $this; | ||
} | ||
$response = $event->getResponse(); | ||
echo $response->getContent(); | ||
$event->setContentSent(); | ||
return $this; | ||
} | ||
|
||
/** | ||
* Send HTTP response | ||
* | ||
* @param SendResponseEvent $event | ||
* @return PhpEnvironmentResponseSender | ||
*/ | ||
public function __invoke(SendResponseEvent $event) | ||
{ | ||
$response = $event->getResponse(); | ||
if ($response instanceof Response) { | ||
$this->sendHeaders($event) | ||
->sendContent($event); | ||
$event->stopPropagation(true); | ||
} | ||
return $this; | ||
} | ||
|
||
} |
30 changes: 30 additions & 0 deletions
30
library/Zend/Mvc/ResponseSender/ResponseSenderInterface.php
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,30 @@ | ||
<?php | ||
/** | ||
* Zend Framework (http://framework.zend.com/) | ||
* | ||
* @link http://github.com/zendframework/zf2 for the canonical source repository | ||
* @copyright Copyright (c) 2005-2012 Zend Technologies USA Inc. (http://www.zend.com) | ||
* @license http://framework.zend.com/license/new-bsd New BSD License | ||
* @package Zend_Mvc | ||
*/ | ||
|
||
namespace Zend\Mvc\ResponseSender; | ||
|
||
use Zend\Mvc\ResponseSender\SendResponseEvent;; | ||
|
||
/** | ||
* @category Zend | ||
* @package Zend_Mvc | ||
* @subpackage ResponseSender | ||
*/ | ||
interface ResponseSenderInterface | ||
{ | ||
/** | ||
* Send the response | ||
* | ||
* @param SendResponseEvent $event | ||
* @return void | ||
*/ | ||
public function __invoke(SendResponseEvent $event); | ||
|
||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The changes in this file are backwards incompatible and cannot be made in ZF2.