Location: PHPKode > scripts > RogePHP > RoguePHP-0.9.4/RoguePHP-0.9.4/types/Observer.php
<?php
/**
 * Interface for observable objects.
 *
 * Implementing this interface will create observable objects via
 * methods for adding and removing listeners.

 * @author Cory Marsh
 * @license http://www.opensource.org/licenses/bsd-license.php BSD License
 */

interface iObservable
{    
    public function addListener(Observer $observer);
    
    public function removeListener(Observer $observer);
}

/**
 * Interface for observer objects.
 *
 * Implementing this interface will create observer objects by
 * creating a means for notification of changes in objects
 * that are observed.
 */
interface iObserver
{
    public function notify($observedObject, array $arguments);
}

/**
 * Base class for observable objects.
 *
 * Extending this class provides the necessary methods to make
 * the child class observable.
 */
class Observable implements iObservable
{
    protected $_listeners;
    
    /**
     * Creates array to hold listeners.
     */
    protected function __construct()
    {
        $this->_listeners = array();
    }
    
    /**
     * @param observer $obs An object that will be listening to this object.
     */
    public function addListener(Observer $obs)
    {
        $this->listeners["$obs"] = $obs;
    }
    
    /**
     * @param observer $obs An object that has been listening to this object.
     */
    public function removeListener(Observer $obs)
    {
        unset($this->listeners["$obs"]);
    }
}
Return current item: RogePHP