View Source

<ac:macro ac:name="unmigrated-inline-wiki-markup"><ac:plain-text-body><![CDATA[{zone-template-instance:ZFDEV:Zend Proposal Zone Template}

{zone-data:component-name}
Zend_Controller_Request Output Buffering
{zone-data}

{zone-data:proposer-list}
[Matthew Weier O'Phinney|mailto:matthew@zend.com]
{zone-data}

{zone-data:revision}
1.0 - 3 March 2007: Initial proposal
{zone-data}

{zone-data:overview}
Zend_Controller_Response should be aggregate all responses emitted by the controller chain. This has the benefit of ensuring that headers are always emitted prior to content, as well as allowing the developer to write unit tests against their front controller. A simple way to do so would be to use output buffering.
{zone-data}

{zone-data:references}
* [PHP Manual: output buffering|http://php.net/outcontrol]
* [Zend_Controller_Response documentation|http://framework.zend.com/manual/en/zend.controller.html#zend.controller.overview.response]
{zone-data}

{zone-data:requirements}
* Output buffering *will* happen at the dispatcher level, surrounding the call to an action method
* Content captured by output buffering *will* be *appended* to the body content of the response object
* Developers *will* be able to turn off the output buffering feature via a front controller parameter
{zone-data}

{zone-data:dependencies}
* Zend_Controller_Response_Abstract
* Zend_Controller_Dispatcher_Standard
* Zend_Controller_Front
{zone-data}

{zone-data:operation}
This feature will be on by default and transparent to the end-user.
{zone-data}

{zone-data:milestones}
* Milestone 1: proposal
* Milestone 2: working code committed to the repo and tested
* Milestone 3: documentation of the feature
{zone-data}

{zone-data:class-list}
* Zend_Controller_Dispatcher_Standard
{zone-data}

{zone-data:use-cases}
||UC-01||
{code:php}
// sample controller that echoes data
class IndexController extends Zend_Controller_Action
{
public function indexAction()
{
echo "In the index action of the index controller";
}
}

// in the bootstrap
$front->returnResponse(true);
$response = $front->dispatch();

// echoes "In the index action of the index controller"
echo $response->getBody();
{code}

||UC-02||
{code:php}
// same controller/action as above
$front->setParam('disableOutputBuffering', true);
$front->returnResponse(true);
$response = $front->dispatch();

// empty string
echo $response->getBody();
{code}
{zone-data}

{zone-data:skeletons}
{code:php}
class Zend_Controller_Dispatcher_Standard extends Zend_Controller_Dispatcher_Abstract
{
public function dispatch(Zend_Controller_Request_Abstract $request, Zend_Controller_Response_Abstract $response)
{
// ... determine controller and action, etc

// dispatching the method call:
$disableOb = $this->getParam('disableOutputBuffering');
$request->setDispatched(true);
if ($disableOb) {
$controller->dispatch($action);
} else {
ob_start();
$controller->dispatch($action);
$content = ob_get_flush();
if (!empty($content)) {
$response->appendBody($content);
}
}

// continue as normal...
}
}
{code}
{zone-data}

{zone-template-instance}]]></ac:plain-text-body></ac:macro>