/** * This method dispatch the current request * * @param __IRequest &$request The request to process to * @param __IResponse &$response The instance to set the response to * */ public function processRequest(__IRequest &$request, __IResponse &$response) { //resolve action identity from request $action_identity = $request->getActionIdentity(); //resolve the action controller associated to the given action identity $controller_definition = __ActionControllerResolver::getInstance()->getActionControllerDefinition($action_identity->getControllerCode()); //check if action controller is requestable if ($controller_definition instanceof __ActionControllerDefinition && $controller_definition->isRequestable()) { __HistoryManager::getInstance()->addRequest($request); //last, execute the action controller __ActionDispatcher::getInstance()->dispatch($action_identity); } else { throw __ExceptionFactory::getInstance()->createException('ERR_ACTION_NON_REQUESTABLE'); } }
/** * This method dispatch the current request * */ public function processRequest(__IRequest &$request, __IResponse &$response) { $action_identity = $request->getActionIdentity(); $controller_code = $action_identity->getControllerCode(); //in case we haven't define any controller, will use the commandline controller from lion admin: if (empty($controller_code)) { //switch to lion admin area: __ContextManager::getInstance()->createContext("LION_ADMIN_AREA", ADMIN_DIR); __ContextManager::getInstance()->switchContext("LION_ADMIN_AREA"); //execute the commandline controller: $action_identity->setControllerCode('commandline'); } $controller_definition = __ActionControllerResolver::getInstance()->getActionControllerDefinition($action_identity->getControllerCode()); //check if action controller is requestable if ($controller_definition instanceof __ActionControllerDefinition && $controller_definition->isRequestable()) { __ActionDispatcher::getInstance()->dispatch($action_identity); } else { throw __ExceptionFactory::getInstance()->createException('ERR_ACTION_NON_REQUESTABLE'); } }
/** * Checks if current user has access to a given url. This method just check if the * action controller that will be executed as consequence of the url is accessible * by the current user. * * @param string $url The url to check access to * @return boolean true if the user has access to the given url */ public function hasAccessToUrl($url) { $return_value = true; //by default $uri = __UriFactory::getInstance()->createUri($url); $action_identity = $uri->getActionIdentity(); $controller_code = $action_identity->getControllerCode(); $controller_definition = __ActionControllerResolver::getInstance()->getActionControllerDefinition($controller_code); if ($controller_definition instanceof __ActionControllerDefinition) { $required_permission = __PermissionManager::getInstance()->getPermission($controller_definition->getRequiredPermissionId()); if (!$required_permission->isJuniorPermissionOf($this->_user_session->getActiveRoles()->getEquivalentPermission())) { $return_value = false; } } return $return_value; }
/** * Dispatch an action. If the action code is not specified, it will be used the default (ACTION_CODE_ON_ACTION_NOT_SPECIFIED). * * If the default one does not correspond with any action controller method (remember that the method name is the action code * with the suffix 'Action'), the ACTION_CODE_ON_ACTION_NOT_FOUND will be used instead of.<br> * <br> * The dispatch method, once has the action controller, performes the following tasks:<br> * <p>1. Call to {@link __ActionController::preProcess} method in order to execute a 'pre-logic' before the execution of the action controller logic (i.e. check preconditions, execute another action, ...)<br> * <p>2. Call to the action method in order to execute the action logic. The action method should return a {@link __ModelAndView} instance. * In that case, the __ActionDispatcher will resolve a {@link __View} and will execute it (by calling to the {@link __View::execute} method).<br> * <p>3. Finally, call to {@link __ActionController::postProcess} method in order to execute a 'post-logic' (i.e. check postconditions, execute another action, ...)<br> * <br> * The {@link preProcess} and {@link postProcess} methods can be specialized in subclasses in order to define concrete actions and behaviors.<br> * * * @param string $action_controller The action controller code (aka the module code) * @param string $action_code The action to execute. * @param __IRequest &$request The request * @param __IResponse &$response The response * @return mixed The response or the value returned by the controller if it's not a {@link __ModelAndView} */ public function &dispatch(__ActionIdentity $action_identity, __IRequest &$request = null, __IResponse &$response = null) { $return_value =& $response; //by default we'll return the response $this->_pushRequest($request); $this->_pushResponse($response); $this->_pushActionIdentity($action_identity); //get the __ActionController class: $controller_code = $action_identity->getControllerCode(); $action_code = $action_identity->getActionCode(); $action_controller = __ActionControllerResolver::getInstance()->getActionController($controller_code); if ($action_controller instanceof __IActionController) { $resource_manager = __ApplicationContext::getInstance()->getResourceManager(); $action_controller_I18n_resources = $resource_manager->loadActionResources($action_identity); $front_controller_request = __FrontController::getInstance()->getRequest(); if ($front_controller_request != null) { $valid_request_method = $action_controller->getValidRequestMethod(); if (($valid_request_method & $front_controller_request->getMethod()) == 0) { throw __ExceptionFactory::getInstance()->createException('ERR_INVALID_REQUEST_METHOD', array($action_identity->getControllerCode())); } } //1. Execute the action's pre-logic: $action_controller->preExecute(); //2. Execute the action logic: $controller_result = $action_controller->execute($action_code); if ($controller_result instanceof __ModelAndView) { $view = $controller_result->getView(); if ($view == null) { $view_code = $controller_result->getViewCode(); if ($view_code == null) { $view_code = $action_code ? $action_code : $controller_code; } $view = __ViewResolver::getInstance()->getView($view_code); } if ($view instanceof __View) { $model = $controller_result->getModel(); //assign the model $view->assign($model->toArray()); //assign I18n resources $view->assign($action_controller_I18n_resources); $response = $this->getResponse(); $response->appendContent($view->execute()); } } else { $return_value =& $controller_result; } //3. Finally will execute the action's post-logic: $action_controller->postExecute(); } $this->_popActionIdentity(); $this->_popResponse(); $this->_popRequest(); return $return_value; }
public function loadActionResources(__ActionIdentity $action_identity, $language_iso_code = null) { if ($language_iso_code == null) { $language_iso_code = __I18n::getInstance()->getLocale()->getLanguageIsoCode(); } $controller_code = $action_identity->getControllerCode(); $cache = __ApplicationContext::getInstance()->getCache(); $action_resources_key = '__ActionResources__' . $language_iso_code . '__' . $controller_code; $action_resources = $cache->getData($action_resources_key); if ($action_resources == null) { $action_resources = array(); $action_controller_definition = __ActionControllerResolver::getInstance()->getActionControllerDefinition($controller_code); $I18n_resource_groups = $action_controller_definition->getI18nResourceGroups(); if (count($I18n_resource_groups) == 0) { $I18n_resource_groups[] = $controller_code; } foreach ($I18n_resource_groups as $I18n_resource_group) { $resources_group_to_load = new __ActionIdentity($I18n_resource_group); foreach ($this->_resource_providers[PERSISTENCE_LEVEL_ACTION] as &$resource_provider) { $action_resources = $resource_provider->loadResources($language_iso_code, $resources_group_to_load) + $action_resources; } } $cache->setData($action_resources_key, $action_resources); } if (!key_exists($controller_code, $this->_loaded_action_codes)) { $this->_resource_table->addActionResources($action_resources, $action_identity, $language_iso_code); $this->_loaded_action_codes[$controller_code] = true; } return $action_resources; }