Created
October 18, 2011 09:04
-
-
Save ashleydw/1294985 to your computer and use it in GitHub Desktop.
Zend Framework Controller Plugin to allow post output processing
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
<?php | |
/** | |
* Zend Framework Controller Plugin to allow post output processing | |
* | |
* @version 1 | |
* @author Ashley White, http://www.needathinkle.com/ | |
* @license http://creativecommons.org/licenses/by-sa/3.0/ | |
*/ | |
final class Thinkle_Controller_Plugin_PostProcess extends Zend_Controller_Plugin_Abstract { | |
public function dispatchLoopShutdown() { | |
$calls = Zend_Registry::isRegistered('PostProcess')?Zend_Registry::get('PostProcess'):array(); | |
if(count($calls)) { | |
$response = $this->getResponse(); | |
if($response->isException()) | |
return; | |
if(function_exists('fastcgi_finish_request')) { | |
$response->sendResponse(); | |
fastcgi_finish_request(); | |
} else { | |
$response->setHeader('Connection', 'close'); | |
ob_start(); | |
$response->outputBody(); | |
$size = ob_get_length(); | |
$response->setHeader('Content-length', $size); | |
$response->sendHeaders(); | |
ob_end_flush(); | |
flush(); | |
} | |
$this->_run(); | |
} | |
} | |
private function _run() { | |
foreach(Zend_Registry::get('PostProcess') as $func) { | |
if(!is_array($func)) | |
return call_user_func($func); | |
else | |
return call_user_func_array($func[0], $func[1]); | |
} | |
$this->_functionCalls = array(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment