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 observer object 00030 * 00031 * @category Varien 00032 * @package Varien_Event 00033 * @author Magento Core Team <core@magentocommerce.com> 00034 */ 00035 class Varien_Event_Observer extends Varien_Object 00036 { 00037 /** 00038 * Checkes the observer's event_regex against event's name 00039 * 00040 * @param Varien_Event $event 00041 * @return boolean 00042 */ 00043 public function isValidFor(Varien_Event $event) 00044 { 00045 return $this->getEventName()===$event->getName(); 00046 } 00047 00048 /** 00049 * Dispatches an event to observer's callback 00050 * 00051 * @param Varien_Event $event 00052 * @return Varien_Event_Observer 00053 */ 00054 public function dispatch(Varien_Event $event) 00055 { 00056 if (!$this->isValidFor($event)) { 00057 return $this; 00058 } 00059 00060 $callback = $this->getCallback(); 00061 $this->setEvent($event); 00062 00063 $_profilerKey = 'OBSERVER: '.(is_object($callback[0]) ? get_class($callback[0]) : (string)$callback[0]).' -> '.$callback[1]; 00064 Varien_Profiler::start($_profilerKey); 00065 call_user_func($callback, $this); 00066 Varien_Profiler::stop($_profilerKey); 00067 00068 return $this; 00069 } 00070 00071 public function getName() 00072 { 00073 return $this->getData('name'); 00074 } 00075 00076 public function setName($data) 00077 { 00078 return $this->setData('name', $data); 00079 } 00080 00081 public function getEventName() 00082 { 00083 return $this->getData('event_name'); 00084 } 00085 00086 public function setEventName($data) 00087 { 00088 return $this->setData('event_name', $data); 00089 } 00090 00091 public function getCallback() 00092 { 00093 return $this->getData('callback'); 00094 } 00095 00096 public function setCallback($data) 00097 { 00098 return $this->setData('callback', $data); 00099 } 00100 00101 /** 00102 * Get observer event object 00103 * 00104 * @return Varien_Event 00105 */ 00106 public function getEvent() 00107 { 00108 return $this->getData('event'); 00109 } 00110 00111 public function setEvent($data) 00112 { 00113 return $this->setData('event', $data); 00114 } 00115 }