00001 <?php 00002 /** 00003 * Magento 00004 * 00005 * NOTICE OF LICENSE 00006 * 00007 * This source file is subject to the Open Software License (OSL 3.0) 00008 * that is bundled with this package in the file LICENSE.txt. 00009 * It is also available through the world-wide-web at this URL: 00010 * http://opensource.org/licenses/osl-3.0.php 00011 * If you did not receive a copy of the license and are unable to 00012 * obtain it through the world-wide-web, please send an email 00013 * to license@magentocommerce.com so we can send you a copy immediately. 00014 * 00015 * DISCLAIMER 00016 * 00017 * Do not edit or add to this file if you wish to upgrade Magento to newer 00018 * versions in the future. If you wish to customize Magento for your 00019 * needs please refer to http://www.magentocommerce.com for more information. 00020 * 00021 * @category Varien 00022 * @package Varien_Event 00023 * @copyright Copyright (c) 2008 Irubin Consulting Inc. DBA Varien (http://www.varien.com) 00024 * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) 00025 */ 00026 00027 00028 /** 00029 * Event object and dispatcher 00030 * 00031 * @category Varien 00032 * @package Varien_Event 00033 * @author Magento Core Team <core@magentocommerce.com> 00034 */ 00035 class Varien_Event extends Varien_Object 00036 { 00037 /** 00038 * Observers collection 00039 * 00040 * @var Varien_Event_Observer_Collection 00041 */ 00042 protected $_observers; 00043 00044 /** 00045 * Constructor 00046 * 00047 * Initializes observers collection 00048 * 00049 * @param array $data 00050 */ 00051 public function __construct(array $data=array()) 00052 { 00053 $this->_observers = new Varien_Event_Observer_Collection(); 00054 parent::__construct($data); 00055 } 00056 00057 /** 00058 * Returns all the registered observers for the event 00059 * 00060 * @return Varien_Event_Observer_Collection 00061 */ 00062 public function getObservers() 00063 { 00064 return $this->_observers; 00065 } 00066 00067 /** 00068 * Register an observer for the event 00069 * 00070 * @param Varien_Event_Observer $observer 00071 * @return Varien_Event 00072 */ 00073 public function addObserver(Varien_Event_Observer $observer) 00074 { 00075 $this->getObservers()->addObserver($observer); 00076 return $this; 00077 } 00078 00079 /** 00080 * Removes an observer by its name 00081 * 00082 * @param string $observerName 00083 * @return Varien_Event 00084 */ 00085 public function removeObserverByName($observerName) 00086 { 00087 $this->getObservers()->removeObserverByName($observerName); 00088 return $this; 00089 } 00090 00091 /** 00092 * Dispatches the event to registered observers 00093 * 00094 * @return Varien_Event 00095 */ 00096 public function dispatch() 00097 { 00098 $this->getObservers()->dispatch($this); 00099 return $this; 00100 } 00101 00102 /** 00103 * Retrieve event name 00104 * 00105 * @return string 00106 */ 00107 public function getName() 00108 { 00109 return isset($this->_data['name']) ? $this->_data['name'] : null; 00110 } 00111 00112 public function setName($data) 00113 { 00114 $this->_data['name'] = $data; 00115 return $this; 00116 } 00117 00118 public function getBlock() 00119 { 00120 return $this->_getData('block'); 00121 } 00122 }