10 defined(
'JPATH_PLATFORM') or die;
30 protected $_observers = array();
39 protected $_state = null;
48 protected $_methods = array();
57 public function __construct()
59 $this->_observers = array();
70 public function getState()
83 public function notify()
86 foreach ($this->_observers as $observer)
88 $return[] = $observer->update();
104 public function attach($observer)
106 if (is_array($observer))
108 if (!isset($observer[
'handler']) || !isset($observer[
'event']) || !is_callable($observer[
'handler']))
114 foreach ($this->_observers as $check)
116 if (is_array($check) && $check[
'event'] == $observer[
'event'] && $check[
'handler'] == $observer[
'handler'])
122 $this->_observers[] = $observer;
123 end($this->_observers);
124 $methods = array($observer[
'event']);
134 $class = get_class($observer);
136 foreach ($this->_observers as $check)
138 if ($check instanceof $class)
144 $this->_observers[] = $observer;
145 $methods = array_diff(get_class_methods($observer), get_class_methods(
'JPlugin'));
148 $key = key($this->_observers);
150 foreach ($methods as $method)
152 $method = strtolower($method);
154 if (!isset($this->_methods[$method]))
156 $this->_methods[$method] = array();
159 $this->_methods[$method][] = $key;
173 public function detach($observer)
177 $key = array_search($observer, $this->_observers);
181 unset($this->_observers[$key]);
184 foreach ($this->_methods as &$method)
186 $k = array_search($key, $method);