Created
June 29, 2011 12:12
-
-
Save jhartikainen/1053718 to your computer and use it in GitHub Desktop.
ZF controller plugin which fakes dojo.io.iframe requests into XMLHttpRequests
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 | |
/** | |
* This plugin automatically converts requests made with GET parameter "dojo_io_iframe" into XMLHttpRequests | |
* | |
* This allows transparent handling of iframe transport requests with code that handles XHR requests, since they're | |
* both essentially the same anyway - only the transport is different. | |
*/ | |
class Wantlet_Controller_Plugin_IframeRequestHandler extends Zend_Controller_Plugin_Abstract { | |
private $isIframe = false; | |
public function dispatchLoopStartup(Zend_Controller_Request_Abstract $request) { | |
if($request->getQuery('dojo_io_iframe')) { | |
//hacky hack... | |
//Triggers Ajax mode handling in request, $request->isXmlHttpRequest() | |
$_SERVER['HTTP_X_REQUESTED_WITH'] = 'XMLHttpRequest'; | |
$this->isIframe = true; | |
} | |
} | |
public function dispatchLoopShutdown() { | |
if(!$this->isIframe) { | |
return; | |
} | |
//Wrap result in dojo.io.iframe requested format | |
$response = $this->getResponse(); | |
$response->setBody( | |
'<html><body><textarea>' . $response->getBody() . '</textarea></body></html>' | |
); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment