code/base/observable.php
public function attach($observer)
	{
		if (is_array($observer))
		{
			if (!isset($observer['handler']) || !isset($observer['event']) || !is_callable($observer['handler']))
			{
				return;
			}

			// Make sure we haven't already attached this array as an observer
			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;
			}

			// Make sure we haven't already attached this object as an observer
			$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;
			}

			// Make sure we haven't already attached this array as an observer
			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;
			}

			// Make sure we haven't already attached this object as an observer
			$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 ; } // Make sure we haven't already attached this array as an observer 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 ; } // Make sure we haven't already attached this object as an observer $ 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

@return  void

@since   11.1
@deprecated  12.3
Attach an observer object