/** * Returns view instance. * * @return View_Interface * @todo Think about registerView */ public function getView() { if (!$this->view) { /* $data = new Deepelopment_EventData( array('class' => 'View_HTML') ); if (!$this->_skip) { $this->_evt->fire('bebeetle_on_get_view', $data); } $this->_view = new $data->class($this->_settings); */ $this->view = new View_HTML($this->settings); /* if (!($this->_view instanceof View_Interface)){ throw new Exception( $data->class . " must implement View_Interface interface", Exception::INVALID_CLASS_INTERFACE ); } */ $this->view->setTab($this->tab); } return $this->view; }
private function handle(Request_Abstract $request, Response_Abstract $response, View_Interface $view) { $request->setDispatched(true); $app = $this->getApplication(); $appDir = $app->getAppDirectory(); if ($appDir == '') { throw new Exception\StartupError('Yaf_Dispatcher requires ' . 'Yaf_Application(which set the application.directory) ' . 'to be initialized first.'); } $module = $request->getModuleName(); if (empty($module)) { throw new Exception\DispatchFailed('Unexcepted an empty module name'); } if (!Application::isModuleName($module)) { throw new Exception\LoadFailed\Module('There is no module ' . $module); } $controllerName = $request->getControllerName(); if (empty($controllerName)) { throw new Exception\DispatchFailed('Unexcepted an empty controller name'); } $className = $this->getController($appDir, $module, $controllerName); if (!$className) { return false; } $controller = new $className($request, $response, $view); if (!$controller instanceof Controller_Abstract) { throw new Exception\TypeError('Controller must be an instance of Yaf_Controller_Abstract'); } $viewDir = $view->getScriptPath(); //template dir might be set from the __construct if (empty($viewDir)) { $templateDir = ''; if ($this->_default_module == $module) { $templateDir = $appDir . DIRECTORY_SEPARATOR . Loader::YAF_VIEW_DIRECTORY_NAME; } else { $templateDir = $appDir . DIRECTORY_SEPARATOR . Loader::YAF_MODULE_DIRECTORY_NAME . DIRECTORY_SEPARATOR . $module . DIRECTORY_SEPARATOR . Loader::YAF_VIEW_DIRECTORY_NAME; } $view->setScriptPath($templateDir); unset($templateDir); } $action = $request->getActionName(); $actionMethod = $action . 'Action'; if (method_exists($controller, $actionMethod)) { //Get all action method parameters $methodParams = $this->getActionParams($className, $actionMethod); if (null == $methodParams) { $ret = call_user_func(array($controller, $actionMethod)); } else { $ret = call_user_func_array(array($controller, $actionMethod), $this->prepareActionParams($request, $methodParams)); } if (is_bool($ret) && $ret == false) { return true; } } elseif (($actionController = $this->getAction($appDir, $controller, $action, $module)) != null) { //check if not in actions vars we have the action $actionMethod = 'execute'; if (method_exists($actionController, $actionMethod)) { //Get all action method parameters $methodParams = $this->getActionParams(get_class($actionController), $actionMethod); $ret = null; if (null == $methodParams) { $ret = call_user_func(array($actionController, $actionMethod)); } else { $ret = call_user_func_array(array($actionController, $actionMethod), $this->prepareActionParams($request, $methodParams)); } if (is_bool($ret) && $ret == false) { return true; } } else { throw new Exception\LoadFailed\Action('There is no method ' . $actionMethod . ' in ' . get_class($controller) . '::$actions'); } } else { return false; } if ($this->_auto_render == true) { if ($this->_instantly_flush == true) { $controller->display($action); } else { $ret = $controller->render($action); $response->setBody($ret); } } $controller = null; }