API16

JObservable/attach

< API16:JObservable

The "API16" namespace is an archived namespace. This page contains information for a Joomla! version which is no longer supported. It exists only as a historical reference, it will not be improved and its content may be incomplete and/or contain broken links.

Description

Attach an observer object



Syntax

attach(&$observer)
Parameter Name Default Value Description
&$observer $observer An observer object to attach

Returns

void

Defined in

libraries/joomla/base/observable.php

Importing

jimport( 'joomla.base.observable' );

Source Body

public function attach(&$observer)
{
        // Make sure we haven't already attached this object as an observer
        if (is_object($observer))
        {
                if (!$observer instanceof JObserver) {
                        return;
                }

                $class = get_class($observer);
                foreach ($this->_observers as $check) {
                        if ($check instanceof $class) {
                                return;
                        }
                }
                $this->_observers[] = &$observer;
                $methods = get_class_methods($observer);
        } else {
                if (!isset($observer['handler']) || !isset($observer['event']) || !is_callable($observer['handler'])) {
                        return;
                }
                $this->_observers[] = &$observer;
                $methods = array($observer['event']);
        }
        end($this->_observers);
        $key = key($this->_observers);
        foreach($methods AS $method) {
                $method = strtolower($method);
                if (!isset($this->_methods[$method])) {
                        $this->_methods[$method] = array();
                }
                $this->_methods[$method][] = $key;
        }
}



Examples

Code Examples


Advertisement