Changeset 636
- Timestamp:
- 11/09/07 12:45:14 (1 year ago)
- Files:
-
- trunk/build/manifests/jelix-no-opt.mn (modified) (1 diff)
- trunk/build/manifests/jelix-no-opt.mn (modified) (1 diff)
- trunk/lib/jelix/events/jEvent.class.php (modified) (4 diffs)
- trunk/lib/jelix/events/jEvent.class.php (modified) (4 diffs)
- trunk/lib/jelix/events/jEventListenerFactory.class.php (deleted)
- trunk/lib/jelix/events/jEventListenerFactory.class.php (deleted)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
trunk/build/manifests/jelix-no-opt.mn
r477 r636 19 19 cd lib/jelix/events 20 20 jEventListener.class.php 21 * jEventListenerFactory.class.php22 21 23 22 cd lib/jelix/dao trunk/build/manifests/jelix-no-opt.mn
r477 r636 19 19 cd lib/jelix/events 20 20 jEventListener.class.php 21 * jEventListenerFactory.class.php22 21 23 22 cd lib/jelix/dao trunk/lib/jelix/events/jEvent.class.php
r582 r636 6 6 * @contributor Laurent Jouanneau 7 7 * @copyright 2001-2005 CopixTeam, 2005-2007 Laurent Jouanneau 8 #if ENABLE_OPTIMIZED_SOURCE9 8 * This classes were get originally from the Copix project 10 * (CopixEvent*, CopixListener* ,Copix 2.3dev20050901, http://www.copix.org)9 * (CopixEvent*, CopixListener* from Copix 2.3dev20050901, http://www.copix.org) 11 10 * Some lines of code are copyrighted 2001-2005 CopixTeam (LGPL licence). 12 11 * Initial authors of this Copix classes are Gerald Croes and Patrice Ferlet, … … 16 15 * @licence http://www.gnu.org/licenses/lgpl.html GNU Lesser General Public Licence, see LICENCE file 17 16 */ 17 18 #if ENABLE_OPTIMIZED_SOURCE 18 19 #includephp jEventListener.class.php 19 #includephp jEventListenerFactory.class.php20 21 20 #else 22 * This class was get originally from the Copix project23 * (CopixEvent, CopixEventNotifier, CopixEventResponse, Copix 2.3dev20050901, http://www.copix.org)24 * Some lines of code are copyrighted 2001-2005 CopixTeam (LGPL licence).25 * Initial authors of this Copix class are Gerald Croes and Patrice Ferlet,26 * and this class was adapted/improved for Jelix by Laurent Jouanneau27 *28 * @link http://www.jelix.org29 * @licence http://www.gnu.org/licenses/lgpl.html GNU Lesser General Public Licence, see LICENCE file30 */31 32 21 /** 33 22 * 34 23 */ 35 24 require_once (JELIX_LIB_EVENTS_PATH . 'jEventListener.class.php'); 36 require_once (JELIX_LIB_EVENTS_PATH . 'jEventListenerFactory.class.php');37 25 #endif 38 26 … … 44 32 */ 45 33 class jEvent { 46 /**47 * The name of the event.48 * @var string name49 */50 protected $_name = null;34 /** 35 * The name of the event. 36 * @var string name 37 */ 38 protected $_name = null; 51 39 52 /**53 * the event parameters54 */55 protected $_params = null;40 /** 41 * the event parameters 42 */ 43 protected $_params = null; 56 44 57 /** 58 * the listeners list. 59 */ 60 protected static $_listeners = array (); 61 62 /** 63 * New event. 64 */ 65 function __construct ($name, $params=array()){ 66 $this->_name = $name; 67 $this->_params = & $params; 68 } 69 70 /** 71 * gets the name of the event 72 * will be used internally for optimisations 73 */ 74 public function getName (){ 75 return $this->_name; 76 } 77 78 /** 79 * gets the given param 80 * @param string $name the param name 81 */ 82 public function getParam ($name){ 83 if (isset ($this->_params[$name])){ 84 $ret = $this->_params[$name]; 85 }else{ 86 $ret = null; 87 } 88 return $ret; 89 } 90 91 /** 92 * send a notification to all modules 93 * @param $event string the event name 94 * @return jEvent 95 */ 96 public static function notify ($eventname, $params=array()) { 97 98 $event = new jEvent($eventname, $params); 99 100 if(!isset(jEvent::$_listeners[$eventname])){ 101 jEvent::$_listeners[$eventname] = jEventListenerFactory::getListenersOf ($eventname); 102 } 103 104 if (isset (jEvent::$_listeners[$eventname])){ 105 foreach (array_keys (jEvent::$_listeners[$eventname]) as $key) { 106 jEvent::$_listeners[$eventname][$key]->performEvent ($event); 107 } 108 } 109 return $event; 110 } 111 112 113 /** 45 /** 114 46 * @var array of array 115 47 */ 116 protected $_responses = array ();48 protected $_responses = array (); 117 49 118 /** 119 * add a response in the list 120 * @param array response a single response 50 /** 51 * New event. 52 * @param string $name the event name 53 * @param array $params an associative array which contains parameters for the listeners 121 54 */ 122 public function add ($response) { 123 $this->_responses[] = & $response; 124 } 55 function __construct ($name, $params=array()){ 56 $this->_name = $name; 57 $this->_params = & $params; 58 } 125 59 126 /** 60 /** 61 * gets the name of the event 62 * will be used internally for optimisations 63 */ 64 public function getName (){ 65 return $this->_name; 66 } 67 68 /** 69 * gets the given param 70 * @param string $name the param name 71 */ 72 public function getParam ($name){ 73 if (isset ($this->_params[$name])){ 74 $ret = $this->_params[$name]; 75 }else{ 76 $ret = null; 77 } 78 return $ret; 79 } 80 81 /** 82 * adds datas in the responses list 83 * @param array $response a single response 84 */ 85 public function add ($response) { 86 $this->_responses[] = & $response; 87 } 88 89 /** 127 90 * look in all the responses if we have a parameter having value as its answer 128 91 * eg, we want to know if we have failed = true, we do … … 132 95 * @return boolean wether or not we have founded the response value 133 96 */ 134 public function inResponse ($responseName, $value, & $response){135 $founded = false;136 $response = array ();97 public function inResponse ($responseName, $value, & $response){ 98 $founded = false; 99 $response = array (); 137 100 138 foreach ($this->_responses as $key=>$listenerResponse){139 if (isset ($listenerResponse[$responseName]) && $listenerResponse[$responseName] == $value){140 $founded = true;141 $response[] = & $this->_responses[$key];142 }143 }101 foreach ($this->_responses as $key=>$listenerResponse){ 102 if (isset ($listenerResponse[$responseName]) && $listenerResponse[$responseName] == $value){ 103 $founded = true; 104 $response[] = & $this->_responses[$key]; 105 } 106 } 144 107 145 return $founded;146 }108 return $founded; 109 } 147 110 148 /**111 /** 149 112 * gets all the responses 150 113 * @return array of associative array 151 114 */ 152 public function getResponse () { 153 return $this->_responses; 115 public function getResponse () { 116 return $this->_responses; 117 } 118 119 120 //------------------------------------- static methods 121 122 123 /** 124 * send a notification to all modules 125 * @param $event string the event name 126 * @return jEvent 127 */ 128 public static function notify ($eventname, $params=array()) { 129 130 $event = new jEvent($eventname, $params); 131 132 if(!isset(self::$hashListened[$eventname])){ 133 self::loadListenersFor ($eventname); 134 } 135 136 $methodName = 'on'.$event->getName (); 137 $list = & self::$hashListened[$eventname]; 138 foreach (array_keys ($list) as $key) { 139 $list[$key]->$methodName ($event); 140 } 141 142 return $event; 154 143 } 144 145 protected static $compilerDatas = array('jEventCompiler', 146 'events/jEventCompiler.class.php', 147 'events.xml', 148 'events.php' 149 ); 150 151 /** 152 * because a listener can listen several events, we should 153 * create only one instancy of a listener for performance, and 154 * $hashListened will contains only reference to this listener. 155 * @var array of jEventListener 156 */ 157 protected static $listenersSingleton = array (); 158 159 /** 160 * hash table for event listened. 161 * $_hash['eventName'] = array of events (by reference) 162 * @var associative array of object 163 */ 164 protected static $hashListened = array (); 165 166 /** 167 * return the list of all listener corresponding to an event 168 * @param string $eventName the event name we wants the listeners for. 169 * @return array of objects 170 */ 171 protected static function loadListenersFor ($eventName) { 172 if (!isset($GLOBALS['JELIX_EVENTS'])) { 173 jIncluder::incAll(self::$compilerDatas); 174 } 175 176 $inf = & $GLOBALS['JELIX_EVENTS']; 177 self::$hashListened[$eventName] = array(); 178 if(isset($inf[$eventName])){ 179 foreach ($inf[$eventName] as $listener){ 180 list($module,$listenerName) = $listener; 181 if (! isset (self::$listenersSingleton[$module][$listenerName])){ 182 require_once ($GLOBALS['gJConfig']->_modulesPathList[$module].'classes/'.strtolower ($listenerName).'.listener.php'); 183 $className = $listenerName.'Listener'; 184 #if ENABLE_OLD_CLASS_NAMING 185 if(!class_exists($className,false)){ 186 $className = 'Listener'.$listenerName; 187 } 188 #endif 189 self::$listenersSingleton[$module][$listenerName] = new $className (); 190 } 191 self::$hashListened[$eventName][] = self::$listenersSingleton[$module][$listenerName]; 192 } 193 } 194 } 155 195 } 156 196 ?> trunk/lib/jelix/events/jEvent.class.php
r582 r636 6 6 * @contributor Laurent Jouanneau 7 7 * @copyright 2001-2005 CopixTeam, 2005-2007 Laurent Jouanneau 8 #if ENABLE_OPTIMIZED_SOURCE9 8 * This classes were get originally from the Copix project 10 * (CopixEvent*, CopixListener* ,Copix 2.3dev20050901, http://www.copix.org)9 * (CopixEvent*, CopixListener* from Copix 2.3dev20050901, http://www.copix.org) 11 10 * Some lines of code are copyrighted 2001-2005 CopixTeam (LGPL licence). 12 11 * Initial authors of this Copix classes are Gerald Croes and Patrice Ferlet, … … 16 15 * @licence http://www.gnu.org/licenses/lgpl.html GNU Lesser General Public Licence, see LICENCE file 17 16 */ 17 18 #if ENABLE_OPTIMIZED_SOURCE 18 19 #includephp jEventListener.class.php 19 #includephp jEventListenerFactory.class.php20 21 20 #else 22 * This class was get originally from the Copix project23 * (CopixEvent, CopixEventNotifier, CopixEventResponse, Copix 2.3dev20050901, http://www.copix.org)24 * Some lines of code are copyrighted 2001-2005 CopixTeam (LGPL licence).25 * Initial authors of this Copix class are Gerald Croes and Patrice Ferlet,26 * and this class was adapted/improved for Jelix by Laurent Jouanneau27 *28 * @link http://www.jelix.org29 * @licence http://www.gnu.org/licenses/lgpl.html GNU Lesser General Public Licence, see LICENCE file30 */31 32 21 /** 33 22 * 34 23 */ 35 24 require_once (JELIX_LIB_EVENTS_PATH . 'jEventListener.class.php'); 36 require_once (JELIX_LIB_EVENTS_PATH . 'jEventListenerFactory.class.php');37 25 #endif 38 26 … … 44 32 */ 45 33 class jEvent { 46 /**47 * The name of the event.48 * @var string name49 */50 protected $_name = null;34 /** 35 * The name of the event. 36 * @var string name 37 */ 38 protected $_name = null; 51 39 52 /**53 * the event parameters54 */55 protected $_params = null;40 /** 41 * the event parameters 42 */ 43 protected $_params = null; 56 44 57 /** 58 * the listeners list. 59 */ 60 protected static $_listeners = array (); 61 62 /** 63 * New event. 64 */ 65 function __construct ($name, $params=array()){ 66 $this->_name = $name; 67 $this->_params = & $params; 68 } 69 70 /** 71 * gets the name of the event 72 * will be used internally for optimisations 73 */ 74 public function getName (){ 75 return $this->_name; 76 } 77 78 /** 79 * gets the given param 80 * @param string $name the param name 81 */ 82 public function getParam ($name){ 83 if (isset ($this->_params[$name])){ 84 $ret = $this->_params[$name]; 85 }else{ 86 $ret = null; 87 } 88 return $ret; 89 } 90 91 /** 92 * send a notification to all modules 93 * @param $event string the event name 94 * @return jEvent 95 */ 96 public static function notify ($eventname, $params=array()) { 97 98 $event = new jEvent($eventname, $params); 99 100 if(!isset(jEvent::$_listeners[$eventname])){ 101 jEvent::$_listeners[$eventname] = jEventListenerFactory::getListenersOf ($eventname); 102 } 103 104 if (isset (jEvent::$_listeners[$eventname])){ 105 foreach (array_keys (jEvent::$_listeners[$eventname]) as $key) { 106 jEvent::$_listeners[$eventname][$key]->performEvent ($event); 107 } 108 } 109 return $event; 110 } 111 112 113 /** 45 /** 114 46 * @var array of array 115 47 */ 116 protected $_responses = array ();48 protected $_responses = array (); 117 49 118 /** 119 * add a response in the list 120 * @param array response a single response 50 /** 51 * New event. 52 * @param string $name the event name 53 * @param array $params an associative array which contains parameters for the listeners 121 54 */ 122 public function add ($response) { 123 $this->_responses[] = & $response; 124 } 55 function __construct ($name, $params=array()){ 56 $this->_name = $name; 57 $this->_params = & $params; 58 } 125 59 126 /** 60 /** 61 * gets the name of the event 62 * will be used internally for optimisations 63 */ 64 public function getName (){ 65 return $this->_name; 66 } 67 68 /** 69 * gets the given param 70 * @param string $name the param name 71 */ 72 public function getParam ($name){ 73 if (isset ($this->_params[$name])){ 74 $ret = $this->_params[$name]; 75 }else{ 76 $ret = null; 77 } 78 return $ret; 79 } 80 81 /** 82 * adds datas in the responses list 83 * @param array $response a single response 84 */ 85 public function add ($response) { 86 $this->_responses[] = & $response; 87 } 88 89 /** 127 90 * look in all the responses if we have a parameter having value as its answer 128 91 * eg, we want to know if we have failed = true, we do … … 132 95 * @return boolean wether or not we have founded the response value 133 96 */ 134 public function inResponse ($responseName, $value, & $response){135 $founded = false;136 $response = array ();97 public function inResponse ($responseName, $value, & $response){ 98 $founded = false; 99 $response = array (); 137 100 138 foreach ($this->_responses as $key=>$listenerResponse){139 if (isset ($listenerResponse[$responseName]) && $listenerResponse[$responseName] == $value){140 $founded = true;141 $response[] = & $this->_responses[$key];142 }143 }101 foreach ($this->_responses as $key=>$listenerResponse){ 102 if (isset ($listenerResponse[$responseName]) && $listenerResponse[$responseName] == $value){ 103 $founded = true; 104 $response[] = & $this->_responses[$key]; 105 } 106 } 144 107 145 return $founded;146 }108 return $founded; 109 } 147 110 148 /**111 /** 149 112 * gets all the responses 150 113 * @return array of associative array 151 114 */ 152 public function getResponse () { 153 return $this->_responses; 115 public function getResponse () { 116 return $this->_responses; 117 } 118 119 120 //------------------------------------- static methods 121 122 123 /** 124 * send a notification to all modules 125 * @param $event string the event name 126 * @return jEvent 127 */ 128 public static function notify ($eventname, $params=array()) { 129 130 $event = new jEvent($eventname, $params); 131 132 if(!isset(self::$hashListened[$eventname])){ 133 self::loadListenersFor ($eventname); 134 } 135 136 $methodName = 'on'.$event->getName (); 137 $list = & self::$hashListened[$eventname]; 138 foreach (array_keys ($list) as $key) { 139 $list[$key]->$methodName ($event); 140 } 141 142 return $event; 154 143 } 144 145 protected static $compilerDatas = array('jEventCompiler', 146 'events/jEventCompiler.class.php', 147 'events.xml', 148 'events.php' 149 ); 150 151 /** 152 * because a listener can listen several events, we should 153 * create only one instancy of a listener for performance, and 154 * $hashListened will contains only reference to this listener. 155 * @var array of jEventListener 156 */ 157 protected static $listenersSingleton = array (); 158 159 /** 160 * hash table for event listened. 161 * $_hash['eventName'] = array of events (by reference) 162 * @var associative array of object 163 */ 164 protected static $hashListened = array (); 165 166 /** 167 * return the list of all listener corresponding to an event 168 * @param string $eventName the event name we wants the listeners for. 169 * @return array of objects 170 */ 171 protected static function loadListenersFor ($eventName) { 172 if (!isset($GLOBALS['JELIX_EVENTS'])) { 173 jIncluder::incAll(self::$compilerDatas); 174 } 175 176 $inf = & $GLOBALS['JELIX_EVENTS']; 177 self::$hashListened[$eventName] = array(); 178 if(isset($inf[$eventName])){ 179 foreach ($inf[$eventName] as $listener){ 180 list($module,$listenerName) = $listener; 181 if (! isset (self::$listenersSingleton[$module][$listenerName])){ 182 require_once ($GLOBALS['gJConfig']->_modulesPathList[$module].'classes/'.strtolower ($listenerName).'.listener.php'); 183 $className = $listenerName.'Listener'; 184 #if ENABLE_OLD_CLASS_NAMING 185 if(!class_exists($className,false)){ 186 $className = 'Listener'.$listenerName; 187 } 188 #endif 189 self::$listenersSingleton[$module][$listenerName] = new $className (); 190 } 191 self::$hashListened[$eventName][] = self::$listenersSingleton[$module][$listenerName]; 192 } 193 } 194 } 155 195 } 156 196 ?>
