Location: PHPKode > scripts > SigSlots > sigslots/signals.php
<?php

require_once("signal.php");

/**
 * Singleton class to manage the signals.
 *
 */
class Signals
{
	/// Singleton ///
	public static $m_Singleton = null; ///< Singleton object
	
	/// Properties ///
	
	private $m_aSignals = array(); ///< Array of signals.
	
	/// Constructor / Destructor ///
	
	private function __construct() { } ///< private constructor cause this is a singleton object
	public function __destruct() { } ///< blank deconstructor [place holder]
	
	/// Methods ///
	
	/**
	 * Singleton accessor method.
	 *
	 * @return Signals&
	 */
	public static function &GetInstance()
	{
		if (is_null(self::$m_Singleton))
		{
			self::$m_Singleton = new self;
		}
		return self::$m_Singleton;
	}
	
	/**
	 * This will register a slot 
	 *
	 * @param string $Signal
	 * @param callback $Callback
	 * @param Object $Object
	 */
	public function RegisterSlot($Signal,$Callback,$Object)
	{
		if ($this->_IsSignal($Signal))
		{
			$this->m_aSignals[$Signal]->AddSlot($Callback,$Object);
		}
	}
	
	/**
	 * This will register a signal.
	 *
	 * @param string $Signal
	 */
	public function RegisterSignal($Signal)
	{
		if (!$this->_IsSignal($Signal))
		{
			$NewSignal = new Signal($Signal);
			$this->m_aSignals[$Signal] = $NewSignal;	
		}
	}
	
	/**
	 * Unregisters a signal.
	 *
	 * @param string $Signal
	 */
	public function Unregister($Signal)
	{
		unset($this->m_aSignals[$Signal]);
	}
	
	/**
	 * Core method to emit a signal and pass in arguments
	 *
	 * @param string $Signal
	 * @param array $arguments
	 */
	public function Emit($Signal,$arguments)
	{
		if ($this->_IsSignal($Signal))
		{
			$this->m_aSignals[$Signal]->Execute($arguments);
		}
	}
	
	/**
	 * Disables a signal
	 *
	 * @param string $Signal
	 */
	public function Disable($Signal)
	{
		if ($this->_IsSignal($Signal))
		{
			$this->m_aSignals[$Signal]->Disable();
		}
	}
	
	/**
	 * Enables a signal
	 *
	 * @param string $Signal
	 */	
	public function Enable($Signal)
	{
		if ($this->_IsSignal($Signal))
		{
			$this->m_aSignals[$Signal]->Enable();
		}
	}	
	
	/**
	 * Returns a boolean value of true if the signal exists or false if it doesn't.
	 *
	 * @param string $Signal
	 * @return bool
	 */
	private function _IsSignal($Signal)
	{
		return isset($this->m_aSignals[$Signal]);
	}
}
?>
Return current item: SigSlots