Ejemplo n.º 1
0
 /**
  * Gets a reference to the singleton {@link __ComponentPool} instance
  *
  * @return __ComponentPool
  */
 public static function &getInstance()
 {
     if (self::$_instance == null) {
         self::$_instance = new __ComponentPool();
     }
     return self::$_instance;
 }
Ejemplo n.º 2
0
 public function &getComponent()
 {
     $return_value = null;
     if (!empty($this->_component_id)) {
         $return_value = __ComponentPool::getInstance()->getComponent($this->_component_id);
     }
     return $return_value;
 }
Ejemplo n.º 3
0
 public function restoreView()
 {
     if ($this->_component_handler != null) {
         __ComponentHandlerManager::getInstance()->addComponentHandler($this->_component_handler);
         __EventHandlerManager::getInstance()->addEventHandler($this->_event_handler);
         $component_pool = __ComponentPool::getInstance();
         foreach ($this->_components as $component) {
             $component_pool->registerComponent($component);
             unset($component);
         }
     }
 }
 public function defaultAction()
 {
     $request = __ActionDispatcher::getInstance()->getRequest();
     if ($request->hasParameter('component_id')) {
         $component_id = $request->getParameter('component_id');
         $component_pool = __ComponentPool::getInstance();
         if ($component_pool->hasComponent($component_id)) {
             $component = $component_pool->getComponent($component_id);
             $response = $component->handleCallback($request);
             print $response;
         }
     }
 }
Ejemplo n.º 5
0
 public function resolveEvent()
 {
     if ($this->_event == null) {
         $request = __FrontController::getInstance()->getRequest();
         if ($request->hasParameter('event')) {
             $event_json_string = stripslashes($request->getParameter('event'));
             $event = json_decode($event_json_string, true);
             $component_id = $event['componentId'];
             $event_name = $event['eventName'];
             $extra_info = $event['extraInfo'];
             if (__ComponentPool::getInstance()->hasComponent($component_id)) {
                 $component = __ComponentPool::getInstance()->getComponent($component_id);
                 //create the event instance:
                 $this->_event = new __UIEvent($event_name, $extra_info, $component);
             }
         }
     }
     return $this->_event;
 }
Ejemplo n.º 6
0
 /**
  * Handles an UI event by executing a method associated to the given event
  *
  * @param __UIEvent $event The event to handle
  * @return mixed
  */
 public function handleEvent(__UIEvent &$event)
 {
     $return_value = null;
     //get event info:
     $component = $event->getComponent();
     $event_name = $event->getEventName();
     $extra_info = $event->getExtraInfo();
     if ($event_name != 'beforeRender' && $event_name != 'afterRender' && $event_name != 'create') {
         __ComponentHandlerManager::getInstance()->getComponentHandler($this->_view_code)->setDirty(true);
     }
     try {
         //handle an event associated to a component:
         if ($component != null) {
             //get component name:
             $component_name = $component->getName();
             //if the component can handle the event, will call to the component event handler
             if ($component->isEventHandled($event_name)) {
                 $component->handleEvent($event);
             }
             //after that, even if the component has handle the event, will execute the event handler method:
             //1. resolve the concrete handler method:
             $event_handler_method = $this->_getEventHandlerMethod($event_name, $component_name);
             //2. call to the concrete handler method:
             if (method_exists($this, $event_handler_method)) {
                 $return_value = call_user_func(array($this, $event_handler_method), $event);
                 switch (strtoupper($event_name)) {
                     case 'VALIDATE':
                         //first, let's return true if no __ValidationException has been sent
                         $return_value = true;
                         //and reset in case of, any validation component associated to the event's component
                         if (is_array($extra_info) && key_exists('validationRule', $extra_info)) {
                             $validation_rule = __ComponentPool::getInstance()->getComponent($extra_info['validationRule']);
                             $validation_rule->setErrorMessage(null);
                         }
                         break;
                 }
             }
         }
     } catch (__ValidationException $validation_exception) {
         $return_value = false;
         //set to false, because a validation exception has been raised
         if (is_array($extra_info) && key_exists('validationRule', $extra_info)) {
             $validation_rule = __ComponentPool::getInstance()->getComponent($extra_info['validationRule']);
             $validation_rule->setErrorMessage($validation_exception->getMessage());
         }
     }
     return $return_value;
 }
 /**
  * Resets values for components implementing {@link __IValueHolder}
  * Also reset any validation against them
  *
  */
 public function resetValueHolders()
 {
     foreach ($this->_component_names as $component) {
         if (is_array($component)) {
             foreach ($component as $component_item) {
                 $component = __ComponentPool::getInstance()->getComponent($component_item);
                 if ($component instanceof __IValueHolder) {
                     $component->reset();
                 }
                 unset($component);
             }
         } else {
             if (is_string($component)) {
                 $component = __ComponentPool::getInstance()->getComponent($component);
                 if ($component instanceof __IValueHolder) {
                     $component->reset();
                 }
                 unset($component);
             }
         }
     }
 }
 /**
  * Gets the component
  *
  * @return __IComponent The component
  */
 public function &getComponent()
 {
     return __ComponentPool::getInstance()->getComponent($this->_component_id);
 }
Ejemplo n.º 9
0
 public function validate()
 {
     $return_value = true;
     if (count($this->_validator_ids) > 0) {
         foreach ($this->_validator_ids as $validator_id => $dummy) {
             if (__ComponentPool::getInstance()->hasComponent($validator_id)) {
                 $validator = __ComponentPool::getInstance()->getComponent($validator_id);
                 $return_value = $return_value && $validator->validate();
             }
         }
     } else {
         $event_handler = __EventHandlerManager::getInstance()->getEventHandler($this->_view_code);
         if ($event_handler->isEventHandled('validate', $this->getName())) {
             $validate_event = new __UIEvent('validate', null, $this);
             $return_value = $event_handler->handleEvent($validate_event);
         }
     }
     return $return_value;
 }