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

require_once("slot.php");

/**
 * This is the base Signal class it shares a 1:* relationship with the Slot class.
 *
 */
class Signal
{
	private $m_aSlots = array(); ///< The array of slots to execute when this signal is emitted.
	private $m_sName = ""; ///< The name of this signal.
	private $m_bEnabled = true; ///< Flag to determine if this signal is enabled or not.
	
	public function __construct($sName)
	{
		$this->m_sName = $sName;
	}
	
	public function __destruct()
	{
	}
	
	/**
	 * Adds a slot to execute when this signal is emitted.
	 *
	 * @param callback $Callback
	 * @param Object $Object
	 */
	public function AddSlot($Callback,$Object)
	{
		$Slot = new Slot($Callback,$Object);
		$this->m_aSlots[] = $Slot;
	}
	
	/**
	 * This method is called when this signal is emitted it will iterate through all the registered Slots and call execute on them.
	 *
	 * @param array $arguments
	 */
	public function Execute($arguments)
	{
		if ($this->m_bEnabled)
		{
			foreach ($this->m_aSlots as $Slot)
			{
				$Slot->Execute($arguments);
			}
		}
	}
	
	/**
	 * Disables this Signal
	 *
	 */
	public function Disable()
	{
		$this->m_bEnabled = false;	
	}
	
	/**
	 * Enables this Signal
	 *
	 */
	public function Enable()
	{
		$this->m_bEnabled = true;
	}
	
	/**
	 * Accessor function for the name of this signal
	 *
	 * @return string
	 */
	public function Name()
	{
		return $this->m_sName;
	}
}


?>
Return current item: SigSlots