public function testCustomHelperFromPath()
 {
     $this->front->setControllerDirectory(dirname(dirname(__FILE__)) . DIRECTORY_SEPARATOR . '_files');
     $request = new Zend_Controller_Request_Http('http://framework.zend.com/helper-broker/test-custom-helper/');
     $this->front->setResponse(new Zend_Controller_Response_Cli());
     $this->front->returnResponse(true);
     Zend_Controller_Action_HelperBroker::addPath(dirname(dirname(__FILE__)) . DIRECTORY_SEPARATOR . '_files' . DIRECTORY_SEPARATOR . 'Helpers', 'MyApp');
     $response = $this->front->dispatch($request);
     $this->assertEquals('MyApp_TestHelper', $response->getBody());
 }
 public function testUsingFrontController()
 {
     $controller = new Zend_Controller_Front();
     $controller->setControllerDirectory(dirname(dirname(__FILE__)) . DIRECTORY_SEPARATOR . '_files');
     $request = new Zend_Controller_Request_Http('http://framework.zend.com/empty');
     $controller->setResponse(new Zend_Controller_Response_Cli());
     $controller->setRouter(new Zend_Controller_Router());
     $plugin = new Zend_Controller_Plugin_BrokerTest_TestPlugin();
     $controller->registerPlugin($plugin);
     $response = $controller->dispatch($request);
     $this->assertEquals('123456', $response->getBody());
     $this->assertEquals('123456', $plugin->getResponse()->getBody());
 }
Beispiel #3
0
 /**
  * Sets up all the initial required pieces of the app.
  * 
  * @param string $environment
  * @param string $appPath
  * @param string $moduleDir
  */
 public function __construct($environment, $appPath = APPLICATION_PATH, $moduleDir = 'modules')
 {
     // set the environment
     $this->_environment = (string) $environment;
     // set the application path
     $this->_appPath = $appPath;
     // set the modules dir path
     $this->_moduleDir = $this->_appPath . DIRECTORY_SEPARATOR . $moduleDir;
     // initiate autoloader
     require_once 'Zend/Loader/Autoloader.php';
     $this->_autoloader = Zend_Loader_Autoloader::getInstance();
     // set up module autoloading
     $this->_autoloader->pushAutoloader(array($this, 'moduleAutoload'));
     // set front controller
     $this->_front = Zend_Controller_Front::getInstance();
     // add module directory
     $this->_front->addModuleDirectory($this->_moduleDir);
     // initiate request
     if ($this->_request === null) {
         $this->_request = new Zend_Controller_Request_Http();
     }
     // initiate response
     if ($this->_response === null) {
         $this->_response = new Zend_Controller_Response_Http();
     }
     // initiate router (Zend_Controller_Router_Rwrite)
     $this->_router = $this->_front->getRouter();
     // get application.ini options
     $appOptions = $this->_getApplicationOptions();
     // set routes in router from application.ini (if any)
     $this->_addRoutesFromConfig($appOptions);
     // update request with routes
     $this->_route($this->_request);
     // get module options
     $moduleOptions = $this->_getModuleOptions();
     // merge application and module options into one array
     $options = $this->mergeOptions($appOptions, $moduleOptions);
     // set options
     $this->setOptions($options);
     // update front controller request
     $this->_front->setRequest($this->_request);
     // update front controller response
     $this->_front->setResponse($this->_response);
     // to be used in dispatch
     $this->_front->setRouter($this->_router);
 }
Beispiel #4
0
 /**
  * Processes the requestStack and merges their responses into $response.
  *
  * @param Zend_Controller_Front $front
  * @param Zend_Controller_Response_Abstract $response
  *
  */
 protected function _processRequestStack($front, Zend_Controller_Response_Abstract $response)
 {
     $stack =& $this->_requestStack;
     $config =& $this->_config;
     $i = count($stack) - 1;
     $responseStack = array();
     $front->returnResponse(true);
     do {
         $myResponse = new Zend_Controller_Response_Http();
         $nextRequest = array_pop($stack);
         $nextRequest->setParam($config['indexKey'], $i);
         $this->_resetHelper();
         $this->_resetPlugins();
         $this->_resetParams($nextRequest->getParams());
         $front->setRequest($nextRequest);
         $front->setResponse($myResponse);
         $responseStack[] = $front->dispatch($nextRequest, $myResponse);
     } while ($i--);
     $front->returnResponse(false);
     $bodies = array();
     for ($i = 0, $len = count($responseStack); $i < $len; $i++) {
         $bodies[] = $responseStack[$i]->getBody();
     }
     $body = implode(',', $bodies);
     $response->setBody('[' . $body . ']');
 }