/** * This is a factory method for creating instances implementing the {@link __IView} * * @param string $view_code The view code * @return __IView an instance of a class implementing the {@link __IView} */ private function _createView($view_code) { $return_value = null; $path = null; if (!empty($view_code)) { $view_code_search_key = strtoupper(trim($view_code)); //check static rules: if (key_exists($view_code_search_key, $this->_view_definitions['static_rules'])) { try { $view_definition = $this->_view_definitions['static_rules'][$view_code_search_key]; $return_value = $view_definition->getView(); } catch (Exception $e) { throw __ExceptionFactory::getInstance()->createException('ERR_VIEW_NON_LOADABLE', array($view_code_search_key, $e->getMessage())); } } else { foreach ($this->_view_definitions['dynamic_rules'] as $view_definition) { if ($return_value == null && $view_definition->isValidForViewCode($view_code_search_key)) { $return_value = $view_definition->getView($view_code); } } } } if ($return_value == null) { throw __ExceptionFactory::getInstance()->createException('ERR_CAN_NOT_RESOLVE_VIEW', array($view_code_search_key)); } else { if (!$return_value instanceof __IView) { throw __ExceptionFactory::getInstance()->createException('ERR_WRONG_VIEW_CLASS', array(get_class($return_value))); } else { $return_value->setCode($view_code); } } return $return_value; }
public static function createState($state_type) { $return_value = null; switch ((int) $state_type) { case self::ACTION_STATE: $return_value = new __ActionFlowState(); break; case self::START_STATE: $return_value = new __StartFlowState(); break; case self::END_STATE: $return_value = new __EndFlowState(); break; case self::DECISION_STATE: $return_value = new __DecisionFlowState(); break; case self::SUBFLOW_STATE: $return_value = new __SubFlowState(); break; default: throw __ExceptionFactory::getInstance()->createException('Unknow flow state type: ' . $state_type); break; } return $return_value; }
public function __construct($id) { if (empty($id)) { throw __ExceptionFactory::getInstance()->createException('A valid id is required to instantiate a __ResponseWriter object'); } $this->_id = $id; }
public function &getView($view_code = null) { $return_value = null; $view_code_substring = null; if (strpos($this->_view_code, '*') !== false) { if ($view_code != null) { if (preg_match('/^' . str_replace('*', '(.+?)', $this->_view_code) . '$/', $view_code, $view_code_substring_array)) { $view_code_substring = $view_code_substring_array[1]; } else { $return_value = null; return $return_value; } } } $view_class_name = $this->getViewClass(); $return_value = new $view_class_name(); $return_value->setCode($view_code ? $view_code : $this->_view_code); foreach ($this->_properties as $property_name => $property_value) { if ($view_code_substring != null) { $property_value = str_replace('*', $view_code_substring, $property_value); } $method_name = 'set' . ucfirst($property_name); if (method_exists($return_value, $method_name)) { $return_value->{$method_name}($property_value); } else { throw __ExceptionFactory::getInstance()->createException('ERR_SETTER_NOT_FOUND_FOR_PROPERTY', array($view_class_name, $property_name)); } } return $return_value; }
/** * Create a child configuration component. * * @param integer $type Type of configuration component to be created * @param string $name Component name to be created * @param string $content Component content * @param array $attributes Component attributes * @param string $where Choose a position 'bottom', 'top', 'after', 'before' where the new component will be added * @param __ConfigurationComponent $target needed if you choose 'before' or 'after' for where * * @return __ConfigurationComponent A reference to the new component */ protected function &createComponent($type, $name, $content, array $attributes = array(), $where = 'bottom', __ConfigurationComponent $target = null) { switch ($type) { case __ConfigurationComponentType::SECTION: $component = new __ConfigurationSection($name, $content, $attributes); $section_handler = __SectionHandlerFactory::getInstance()->createSectionHandler($name); if ($section_handler != null) { $component->registerSectionHandler($section_handler); } break; case __ConfigurationComponentType::PROPERTY: $component = new __ConfigurationProperty($name, $content, $attributes); break; case __ConfigurationComponentType::COMMENT: $component = new __ConfigurationComment($name, $content, $attributes); break; case __ConfigurationComponentType::BLANK: $component = new __ConfigurationBlank($name, $content, $attributes); break; default: throw __ExceptionFactory::getInstance()->createException('ERR_UNKNOW_CONFIGURATION_COMPONENT_TYPE', array($type)); break; } $return_value =& $this->addComponent($component, $where, $target); return $return_value; }
public function &createResponse($request_type = null) { $return_value = null; if ($request_type == null) { $request_type = __Client::getInstance()->getRequestType(); } switch ($request_type) { case REQUEST_TYPE_COMMAND_LINE: $response_class = __CurrentContext::getInstance()->getPropertyContent('COMMAND_LINE_RESPONSE_CLASS'); break; case REQUEST_TYPE_XMLHTTP: $response_class = __CurrentContext::getInstance()->getPropertyContent('XML_HTTP_RESPONSE_CLASS'); break; default: $response_class = __CurrentContext::getInstance()->getPropertyContent('HTTP_RESPONSE_CLASS'); break; } if (class_exists($response_class)) { $return_value = new $response_class(); } if (!$return_value instanceof __IResponse) { __ExceptionFactory::getInstance()->createException('Wrong response class: ' . $response_class . '. The response class must implement the __IResponse'); } return $return_value; }
public static function loadView($view_code) { try { $url = unserialize(base64_decode($view_code)); $request = __RequestFactory::getInstance()->createRequest(REQUEST_TYPE_HTTP); $response = __ResponseFactory::getInstance()->createResponse(REQUEST_TYPE_HTTP); $url_components = parse_url($url); if (is_array($url_components) && key_exists('query', $url_components)) { $query = $url_components['query']; $get_pairs = explode('&', $query); foreach ($get_pairs as $get_pair) { $get_pair_array = explode('=', $get_pair); $request->addParameter($get_pair_array[0], $get_pair_array[1], REQMETHOD_GET); } } $uri = __UriFactory::getInstance()->createUri($url_components['path']); $request->setUri($uri); $request->setRequestMethod(REQMETHOD_GET); $front_controller = new __ComponentLazyLoaderFrontController(); $front_controller->dispatch($request, $response); //dispatch the request } catch (Exception $e) { __ExceptionFactory::getInstance()->createException('Can not load view for view code ' . $view_code . ': ' . $e->getMessage()); } }
/** * Updates client end-point with values received from request: * * @param __IRequest $request * @param __IResponse $response */ public function preFilter(__IRequest &$request, __IResponse &$response) { //update client end-points with values received from request: $request_component_values = __ContextManager::getInstance()->getApplicationContext()->getPropertyContent('REQUEST_CLIENT_ENDPOINT_VALUES'); if ($request->hasParameter($request_component_values)) { $values = $request->getParameter($request_component_values); if (function_exists('get_magic_quotes_gpc') && get_magic_quotes_gpc()) { $scape_chars = array('\\n', '\\r', '\\t'); $double_scape_chars = array('\\\\n', '\\\\r', '\\\\t'); $values = str_replace($scape_chars, $double_scape_chars, $values); $values = stripslashes($values); } $client_values = json_decode($values, true); if (is_array($client_values)) { $ui_binding_manager = __UIBindingManager::getInstance(); foreach ($client_values as $id => $value) { if ($ui_binding_manager->hasUIBinding($id)) { $ui_binding_manager->getUIBinding($id)->getClientEndPoint()->setValue($value); } else { if ($request->hasParameter('viewCode')) { $view_code = $request->getParameter('viewCode'); __ComponentLazyLoader::loadView($view_code); if ($ui_binding_manager->hasUIBinding($id)) { $ui_binding_manager->getUIBinding($id)->getClientEndPoint()->setValue($value); } else { throw __ExceptionFactory::getInstance()->createException('Can not sync component status between client and server'); } } } } } } }
/** * Persist a given collection into the data source * * @param __Collection|VirtualProxy $collection */ public function save(&$collection) { if (!$collection instanceof IPersistent) { throw __ExceptionFactory::getInstance()->createException('A collection implementing the IPersistent was expected. It was given a ' . get_class($collection) . ' instance.'); } if ($collection instanceof VirtualProxy) { if ($collection->isDirty()) { $collection = $collection->getReceiver(); } else { return; } } if (!$collection instanceof $this->_collection_class) { throw __ExceptionFactory::getInstance()->createException('Can not save instances of type ' . get_class($collection) . ' by ussing ' . get_class($this) . '. A ' . $this->_collection_class . ' instance was expected'); } __DaoManager::getInstance()->beginTransaction($this); try { $dao = __DaoManager::getInstance()->getDao($this->_class); $iterator = $collection->getIterator(); $iterator->first(); while (!$iterator->isDone()) { $item = $iterator->currentItem(); $dao->save($item); $iterator->next(); } $collection->setDirty(false); $collection->setTransient(false); } catch (Exception $e) { __DaoManager::getInstance()->rollbackTransaction(); throw $e; } __DaoManager::getInstance()->commitTransaction(); }
public function setMaximumValue($maximum_value) { if (!is_numeric($maximum_value)) { throw __ExceptionFactory::getInstance()->createException('Can not set non-numerical value for minimumValue attribute at RangeValidator component'); } $this->_maximum_value = $maximum_value; }
public function setKey($key) { $this->_key = $key; //If the key is already defined as constant, it will be the error code: $this->setErrorCode(__ExceptionFactory::getInstance()->getErrorTable()->getErrorCode($key)); return $this; }
/** * This method receives a path to access to an instance and returns a reference to the instance. * * i.e., <emphasis>authenticationManager.authenticatedUser.username</emphasis> will be resolved as: * <code> * * $authentication_manager = __CurrentContext::getInstance() * ->getInstance('authenticationManager'); * * $authenticated_user = $authentication_manager * ->getAuthenticatedUser(); * * $username = $authenticated_user->getUsername(); * * </code> * * @param unknown_type $instance_dir * @return unknown */ public function &resolveInstance($instance_dir) { if (strpos($instance_dir, '.') !== false) { $root_instance_name = trim(substr($instance_dir, 0, strpos($instance_dir, '.'))); if (!__CurrentContext::getInstance()->hasInstance($root_instance_name)) { throw __ExceptionFactory::getInstance()->createException('ERR_INSTANCE_ID_NOT_FOUND', array($root_instance_name)); } $current_instance = __CurrentContext::getInstance()->getContextInstance($root_instance); $instance_dir = trim(substr($instance_dir, strpos($instance_dir, '.') + 1)); while (strpos($instance_dir, '.') !== false) { $property_name = trim(substr($instance_dir, 0, strpos($instance_dir, '.'))); $getter_method = 'get' . ucfirst($property_name); if (method_exists($current_instance, $getter_method)) { $current_instance = $current_instance->{$getter_method}(); } else { throw __ExceptionFactory::getInstance()->createException('ERR_GETTER_NOT_FOUND_FOR_PROPERTY', array(get_class($current_instance), $property_name)); } } } else { $root_instance_name = trim($instance_dir); if (!__CurrentContext::getInstance()->hasInstance($current_instance_name)) { throw __ExceptionFactory::getInstance()->createException('ERR_INSTANCE_NOT_FOUND', array($root_instance_name)); } $current_instance = __CurrentContext::getInstance()->getInstance($root_instance_name); } return $current_instance; }
public function &getRole($role_id) { if (key_exists($role_id, $this->_roles)) { return $this->_roles[$role_id]; } else { throw __ExceptionFactory::getInstance()->createException('ERR_UNKNOW_ROLE', array($role_id)); } }
/** * This method is executed each time the system resource is tried to be accessed without having the associated permission. * It can be overwritted by the child class in order to execute some custom actions (i.e. redirect the user to the login page). * The default behavior is to raise a __SecurityException * */ public function onAccessError(Exception $exception = null) { if ($exception == null) { $exception = __ExceptionFactory::getInstance()->createException('ERR_ACCESS_PERMISSION_ERROR', array('system_resource_class' => get_class($this))); $exception->setExtraInfo(array('system_resource' => $this)); } throw $exception; }
/** * Overwriten from __UIComponent in order to ensure that the parent component is a {@link __ItemListComponent} instance * * @param __IContainer $container The container component */ public function setContainer(__IContainer &$container) { if ($container instanceof __ItemListComponent) { parent::setContainer($container); } else { throw __ExceptionFactory::getInstance()->createException('Wrong container component for an __ItemComponent. An __ItemListComponent was expected.'); } }
public function setEventName($event_name) { if (!empty($event_name)) { $this->_event_name = $event_name; } else { throw __ExceptionFactory::getInstance()->createException('Need an event name (an empty value as the event name has been received)'); } }
public function setFrontControllerCallback(&$front_controller, $method_name) { if ($front_controller instanceof __IFrontController) { $this->_front_controller_callback = new __Callback($front_controller, $method_name); } else { throw __ExceptionFactory::getInstance()->createException('ERR_WRONG_FRONT_CONTROLLER_INSTANCE', array(get_class($front_controller))); } }
public function connect() { $connection = new PDO('sqlite:' . $this->_file); if ($connection) { $this->_connection =& $connection; } else { throw __ExceptionFactory::getInstance()->createException('Can not connect to database (' . $this->getConnectionString() . ')'); } }
private static function _validatePHP() { if (version_compare(PHP_VERSION, '5.2.0', '<')) { throw __ExceptionFactory::getInstance()->createException('Lion requires PHP 5.2.0 or greater in order to work. Current PHP version is ' . PHP_VERSION . '.'); } $php_extensions = get_loaded_extensions(); if (in_array('domxml', $php_extensions) || in_array('php_domxml', $php_extensions)) { throw __ExceptionFactory::getInstance()->createException('php_domxml extension detected: Need to be disabled.'); } }
public function defaultAction() { $return_value = null; $request = __FrontController::getInstance()->getRequest(); $application_context = __ApplicationContext::getInstance(); $request_flow_execution_key = $application_context->getPropertyContent('REQUEST_FLOW_EXECUTION_KEY'); if ($request->hasParameter($request_flow_execution_key)) { $flow_execution_key = $request->getParameter($request_flow_execution_key); $request_flow_event_id = $application_context->getPropertyContent('REQUEST_FLOW_EVENT_ID'); $request_flow_state_id = $application_context->getPropertyContent('REQUEST_FLOW_STATE_ID'); $flow_executor = __FlowExecutor::getInstance(); //sync with the current state sent from client: if ($request->hasParameter($request_flow_state_id)) { $flow_execution = $flow_executor->getActiveFlowExecution(); if ($flow_execution != null) { $flow_state_id = $request->getParameter($request_flow_state_id); if ($flow_execution->isStateVisited($flow_state_id)) { $current_state = $flow_execution->getCurrentState(); if ($current_state != null && $current_state->getId() != $flow_state_id) { $state = $flow_execution->goToState($flow_state_id); if ($state != null && !$request->hasParameter($request_flow_event_id)) { $application_context = __ApplicationContext::getInstance(); $request_flow_execution_key = $application_context->getPropertyContent('REQUEST_FLOW_EXECUTION_KEY'); $flow_execution_key = $request->getParameter($request_flow_execution_key); $this->_executeControllerAssociatedToState($state, $flow_executor, $flow_execution_key); } } } else { throw __ExceptionFactory::getInstance()->createException('Flow state not yet visited: ' . $flow_state_id); } } } //checks flow event: if ($request->hasParameter($request_flow_event_id)) { $flow_event_id = $request->getParameter($request_flow_event_id); $state = $flow_executor->resume($flow_execution_key, $flow_event_id); if ($state != null) { $this->_executeControllerAssociatedToState($state, $flow_executor, $flow_execution_key); } } else { if ($flow_executor->hasFlowExecution($flow_execution_key)) { $return_value = $flow_executor->getResponse($flow_execution_key); $return_value->setBufferControl(true); //let also the browser cache the page $return_value->addHeader('Cache-Control: private, max-age=10800, pre-check=10800'); $return_value->addHeader('Pragma: private'); $return_value->addHeader("Expires: " . date(DATE_RFC822, strtotime("+2 day"))); } else { //start a new flow and redirect the user to the very first step: $this->startFlowAction(); } } } return $return_value; }
public function getActionController($action_controller_code) { $controller_definition = $this->getActionControllerDefinition($action_controller_code); if ($controller_definition instanceof __ActionControllerDefinition) { $action_controller = __ActionControllerFactory::createActionController($controller_definition, $action_controller_code); } if ($action_controller == null) { throw __ExceptionFactory::getInstance()->createException('ERR_CAN_NOT_RESOLVE_CONTROLLER', array($action_controller_code)); } return $action_controller; }
public function addState(__IFlowState &$state) { $this->_states[$state->getId()] =& $state; if ($state instanceof __StartFlowState) { if ($this->_start_state == null) { $this->_start_state =& $state; } else { throw __ExceptionFactory::getInstance()->createException('Multiple start states in flow ' . $this->_id); } } }
public static function createFlowExecution($flow_id) { $return_value = null; $flow_definition = __WebFlowManager::getInstance()->getFlowDefinition($flow_id); if ($flow_definition != null) { $return_value = new __FlowExecution($flow_definition); } else { throw __ExceptionFactory::getInstance()->createException('Unknown flow for id ' . $flow_id); } return $return_value; }
/** * Constructor. * * @param string $tag_name The UI tag * @param string $component_class The component class */ public function __construct($tag_name, $component_class) { if (!class_exists($component_class)) { throw __ExceptionFactory::getInstance()->createException('ERR_CLASS_NOT_FOUND', array($component_class)); } if (!is_subclass_of($component_class, '__IComponent')) { throw __ExceptionFactory::getInstance()->createException('ERR_UNEXPECTED_CLASS', array($component_class, '__IComponent')); } $this->_tag = $tag_name; $this->_class = $component_class; }
/** * Returns a {@link __Role} instance that correspond with the specified role id * * @param string $role_id The role id * @return __Role The requested {@link __Role} instance */ public function &getRole($role_id) { $return_value = null; $role_id = strtoupper($role_id); if (key_exists($role_id, $this->_roles)) { $return_value =& $this->_roles[$role_id]; } else { throw __ExceptionFactory::getInstance()->createException('ERR_UNKNOW_ROLE_ID', array($role_id)); } return $return_value; }
public function onAccessError() { if (__ApplicationContext::getInstance()->getPropertyContent('LION_ADMIN_AUTH_REQUIRED') == true) { //logout the user: __AuthenticationManager::getInstance()->logout(); $uri = __UriFactory::getInstance()->createUri()->setRoute('lion')->setController('login'); __FrontController::getInstance()->forward($uri); } else { throw __ExceptionFactory::getInstance()->createException('ERR_ACTION_PERMISSION_ERROR', array('action_code' => $this->getCode())); } }
public function setAuthenticators(array &$authenticators) { foreach ($authenticators as &$authenticator) { if (!$authenticator instanceof __IAuthenticator) { throw __ExceptionFactory::getInstance()->createException('ERR_WRONG_AUTHENTICATOR_CLASS', array(get_class($authenticator))); } } $this->_authenticators = $authenticators; if ($this->_user == null) { $this->logonAsAnonymous(); } }
/** * Get the component to be validated by the current validator * * @return __IComponent */ public function getCaptcha() { $return_value = null; $component_handler = __ComponentHandlerManager::getInstance()->getComponentHandler($this->_view_code); if ($component_handler != null) { if ($component_handler->hasComponent($this->_captcha_image_component)) { $return_value = $component_handler->getComponent($this->_captcha_image_component, $this->_captcha_component_index); } else { throw __ExceptionFactory::getInstance()->createException('Component to validate not found: ' . $this->_component); } } return $return_value; }
public function setResponse(__IResponse $response) { $active_flow_execution = $this->getActiveFlowExecution(); if ($active_flow_execution != null) { $flow_execution_key = $active_flow_execution->getKey(); $response_to_save = clone $response; //save the response $response_to_save->prepareToSleep(); $this->_responses[$flow_execution_key] = $response_to_save; } else { throw __ExceptionFactory::getInstance()->createException('There is not any active flow to set response to'); } }
public function endRender(__IComponent &$component) { $return_value = $this->_component_writer->endRender($component); $spinner = $component->spinner; if (empty($spinner)) { $spinner = true; //by default } else { $spinner = $this->_toBool($spinner); } if ($spinner) { $component_id = $component->getId(); $spinner_id = $component_id . '_spinner'; $javascript_rw = __ResponseWriterManager::getInstance()->getResponseWriter('javascript'); //setup spinner if ($component->hasProperty('spinnerTargetComponent')) { $target_component_name = $component->getProperty('spinnerTargetComponent'); $view_code = $component->getViewCode(); $component_handler = __ComponentHandlerManager::getInstance()->getComponentHandler($view_code); if ($component_handler != null && $component_handler->hasComponent($target_component_name)) { $spinner_target = $component_handler->getComponent($target_component_name)->getId(); } else { throw __ExceptionFactory::getInstance()->createException('Target spinner component not found: ' . $target_component_name); } } else { if ($component->hasProperty('spinnerTargetElement')) { $spinner_target = $component->getProperty('spinnerTargetElement'); } else { $spinner_target = $component_id; } } $spinner_target = $javascript_rw->addJsCode($spinner_id . ' = new __Spinner("' . $spinner_target . '");'); //setup waiting message: $waiting_message = $component->waitingMessage; if (!empty($waiting_message)) { $javascript_rw->addJsCode($spinner_id . '.setWaitingMessage("' . nl2br(stripslashes($waiting_message)) . '");'); } //setup progress bar: $show_progress = $this->_toBool($component->showProgress); if ($show_progress) { $js_code = <<<CODE var progressHandler = (__ProgressBroadcaster.getInstance()).getProgressHandler("{$component_id}"); if(typeof(progressHandler) != "undefined") { progressHandler.registerUiProgressIndicator({$spinner_id}); } CODE; $javascript_rw->addJsCode($js_code); } } return $return_value; }