/** * Initialize * * @param type $stdout * @param type $stderr * @param type $stdin */ public function __construct($stdout = null, $stderr = null, $stdin = null) { parent::__construct($stdout, $stderr, $stdin); $this->_CroogoPlugin = new CroogoPlugin(); $this->_CroogoTheme = new CroogoTheme(); $CakeRequest = new CakeRequest(); $CakeResponse = new CakeResponse(); $this->_Controller = new AppController($CakeRequest, $CakeResponse); $this->_Controller->constructClasses(); $this->_Controller->startupProcess(); $this->_CroogoPlugin->setController($this->_Controller); $this->initialize(); }
protected function _createController($data) { $request = new CakeRequest(); $request->data = $data; $controller = new Controller($request); $controller->components = array('Croogo.BulkProcess'); $controller->constructClasses(); $controller->startupProcess(); return $controller; }
/** * Initializes the components and models a controller will be using. * Triggers the controller action, and invokes the rendering if Controller::$autoRender is true and echo's the output. * Otherwise the return value of the controller action are returned. * * Works like {@see Dispatcher::_invoke()} but returns the full response instead the body only. * * Bancha needs to overwrite this method because we need the full response object not only the body of the response * object on return. * * @param Controller $controller Controller to invoke * @param CakeRequest $request The request object to invoke the controller for. * @param CakeResponse $response The response object to receive the output * @return CakeResponse te resulting response object */ protected function _invoke(Controller $controller, CakeRequest $request, CakeResponse $response) { $controller->constructClasses(); $controller->startupProcess(); $render = true; $result = $controller->invokeAction($request); if ($result instanceof CakeResponse) { $render = false; $response = $result; } if ($render && $controller->autoRender) { $response = $controller->render(); } elseif ($response->body() === null) { $response->body($result); } $controller->shutdownProcess(); if (isset($request->params['return'])) { return $response; // <-------------- only this line is changed, original: return $response->body(); } $response->send(); }
/** * Initializes the components and models a controller will be using. * Triggers the controller action, and invokes the rendering if Controller::$autoRender is true and echo's the output. * Otherwise the return value of the controller action are returned. * * @param Controller $controller Controller to invoke * @param CakeRequest $request The request object to invoke the controller for. * @param CakeResponse $response The response object to receive the output * @return CakeResponse the resulting response object */ protected function _invoke(Controller $controller, CakeRequest $request, CakeResponse $response) { $controller->constructClasses(); $controller->startupProcess(); $render = true; $result = $controller->invokeAction($request); if ($result instanceof CakeResponse) { $render = false; $response = $result; } if ($render && $controller->autoRender) { $response = $controller->render(); } elseif (!$result instanceof CakeResponse && $response->body() === null) { $response->body($result); } $controller->shutdownProcess(); return $response; }
/** * testGenerateFileFileExists * * Running the shell should only add missing translations, * Without removing or corrupting existing translations. * * @return void */ public function testGenerateFileFileExists() { $expected = <<<END <?php /** * Example CRUD Component translations */ __d('crud', 'Some other translation'); __d('crud', 'Invalid id'); __d('crud', 'Not found'); __d('crud', 'Method not allowed. This action permits only {methods}'); __d('crud', 'Successfully created example'); __d('crud', 'Could not create example'); __d('crud', 'Successfully updated example'); __d('crud', 'Could not update example'); __d('crud', 'Successfully deleted example'); END; $path = TMP . 'crud_translations_shell_test.php'; file_put_contents($path, $expected); $controller = new Controller(new CakeRequest()); $controller->Example = new StdClass(); // dummy $controller->Example->name = 'Example'; $controller->modelClass = 'Example'; $controller->components = array('Crud.Crud' => array('actions' => array('index', 'add', 'edit', 'view', 'delete'))); $controller->constructClasses(); $controller->startupProcess(); $this->Shell->expects($this->once())->method('_loadController')->will($this->returnValue($controller)); $this->Shell->expects($this->once())->method('_getControllers')->will($this->returnValue(array('Example'))); $this->Shell->path($path); $this->Shell->generate(); $this->assertFileExists($path); $onlyNewTranslation = "\n__d('crud', 'Could not delete example');"; $expected .= $onlyNewTranslation; $contents = file_get_contents($path); $this->assertTextEquals(trim($expected), trim($contents), "Only expected one translation to be added"); unlink($path); }
/** * Initializes the components and models a controller will be using. * Triggers the controller action, and invokes the rendering if Controller::$autoRender is true and echo's the output. * Otherwise the return value of the controller action are returned. * * @param Controller $controller Controller to invoke * @param CakeRequest $request The request object to invoke the controller for. * @return string Output as sent by controller * @throws MissingActionException when the action being called is missing. */ protected function _invoke(Controller $controller, CakeRequest $request) { $controller->constructClasses(); $controller->startupProcess(); $methods = array_flip($controller->methods); if (!isset($methods[$request->params['action']])) { if ($controller->scaffold !== false) { App::import('Controller', 'Scaffold', false); return new Scaffold($controller, $request); } throw new MissingActionException(array('controller' => Inflector::camelize($request->params['controller']) . "Controller", 'action' => $request->params['action'])); } $result = call_user_func_array(array(&$controller, $request->params['action']), $request->params['pass']); $response = $controller->getResponse(); if ($controller->autoRender) { $controller->render(); } elseif ($response->body() === null) { $response->body($result); } $controller->shutdownProcess(); if (isset($request->params['return'])) { return $response->body(); } $response->send(); }
/** * Método que se encarga de invocar a la acción del controlador y * entregar la respuesta * @author Esteban De La Fuente Rubio, DeLaF (esteban[at]delaf.cl) * @version 2014-03-22 */ private static function _invoke(Controller $controller, Network_Request $request, Network_Response $response) { // Iniciar el proceso $controller->startupProcess(); // Ejecutar acción $result = $controller->invokeAction(); // Renderizar proceso if ($controller->autoRender) { $response = $controller->render(); } elseif ($response->body() === null) { $response->body($result); } // Detener el proceso $controller->shutdownProcess(); // Retornar respuesta al cliente if (isset($request->params['return'])) { return $response->body(); } // Enviar respuesta al cliente $response->send(); }