english/libraries/joomla/base/observable.php
/**
	 * Attach an observer object
	 *
	 * @param   object   $observer  An observer object to attach
	 *
	 * @return  void
	 * @since   11.1
	 */
Attach an observer object
@param   object   $observer  An observer object to attach


Attach an observer object @param object $observer An observer object to attach
public function attach($observer)
	{
		if (is_array($observer)) {
			if (!isset($observer['handler']) || !isset($observer['event']) || !is_callable($observer['handler'])) {
				return;
			}
			foreach ($this->_observers as $check)
			{
				if (is_array($check) && $check['event']==$observer['event'] && $check['handler']==$observer['handler']) {
					return;
				}
			}
			$this->_observers[] = $observer;
			end($this->_observers);
			$methods = array($observer['event']);
		}
		else {
			if (!($observer instanceof JObserver)) {
				return;
			}
			$class = get_class($observer);
			foreach ($this->_observers as $check)
			{
				if ($check instanceof $class) {
					return;
				}
			}
			$this->_observers[] = $observer;
			$methods = array_diff(get_class_methods($observer), get_class_methods('JPlugin'));
		}
		$key = key($this->_observers);
		foreach($methods AS $method)
		{
			$method = strtolower($method);
			if (!isset($this->_methods[$method])) {
				$this->_methods[$method] = array();
			}
			$this->_methods[$method][] = $key;
		}
	}
public function attach ( $ observer ) { if ( is_array ( $ observer ) ) { if ( ! isset ( $ observer [ 'handler' ] ) || ! isset ( $ observer [ 'event' ] ) || ! is_callable ( $ observer [ 'handler' ] ) ) { return ; } foreach ( $ this -> _observers as $ check ) { if ( is_array ( $ check ) && $ check [ 'event' ] == $ observer [ 'event' ] && $ check [ 'handler' ] == $ observer [ 'handler' ] ) { return ; } } $ this -> _observers [ ] = $ observer ; end ( $ this -> _observers ) ; $ methods = array ( $ observer [ 'event' ] ) ; } else { if ( ! ( $ observer instanceof JObserver ) ) { return ; } $ class = get_class ( $ observer ) ; foreach ( $ this -> _observers as $ check ) { if ( $ check instanceof $ class ) { return ; } } $ this -> _observers [ ] = $ observer ; $ methods = array_diff ( get_class_methods ( $ observer ) , get_class_methods ( 'JPlugin' ) ) ; } $ key = key ( $ this -> _observers ) ; foreach ( $ methods AS $ method ) { $ method = strtolower ( $ method ) ; if ( ! isset ( $ this -> _methods [ $ method ] ) ) { $ this -> _methods [ $ method ] = array ( ) ; } $ this -> _methods [ $ method ] [ ] = $ key ; } }
Attach an observer object
 @param   object   $observer  An observer object to attach
Attach an observer object @param object $observer An observer object to attach
// Make sure we haven't already attached this array as an observer // Make sure we haven't already attached this object as an observer