Current file: htdocs/lib/Varien/Event/Collection.php
Legend: executed not executed dead code

  Coverage
  Classes Functions / Methods Lines
Total
0.00%0.00%
0.00% 0 / 1
0.00%0.00%
0.00% 0 / 7 CRAP
0.00%0.00%
0.00% 0 / 21
 
Varien_Event_Collection
0.00%0.00%
0.00% 0 / 1
0.00%0.00%
0.00% 0 / 7
0.00%0.00%
0.00% 0 / 21
 __construct()
0.00%0.00%
0.00% 0 / 1 2
0.00%0.00%
0.00% 0 / 3
 getAllEvents()
0.00%0.00%
0.00% 0 / 1 2
0.00%0.00%
0.00% 0 / 1
 getGlobalObservers()
0.00%0.00%
0.00% 0 / 1 2
0.00%0.00%
0.00% 0 / 1
 getEventByName($eventName)
0.00%0.00%
0.00% 0 / 1 6
0.00%0.00%
0.00% 0 / 4
 addEvent(Varien_Event $event)
0.00%0.00%
0.00% 0 / 1 2
0.00%0.00%
0.00% 0 / 2
 addObserver(Varien_Event_Observer $observer)
0.00%0.00%
0.00% 0 / 1 6
0.00%0.00%
0.00% 0 / 6
 dispatch($eventName, array $data=array()
0.00%0.00%
0.00% 0 / 1 2
0.00%0.00%
0.00% 0 / 4


       1                 : <?php                                                                                      
       2                 : /**                                                                                        
       3                 :  * Magento                                                                                 
       4                 :  *                                                                                         
       5                 :  * NOTICE OF LICENSE                                                                       
       6                 :  *                                                                                         
       7                 :  * This source file is subject to the Open Software License (OSL 3.0)                      
       8                 :  * that is bundled with this package in the file LICENSE.txt.                              
       9                 :  * It is also available through the world-wide-web at this URL:                            
      10                 :  * http://opensource.org/licenses/osl-3.0.php                                              
      11                 :  * If you did not receive a copy of the license and are unable to                          
      12                 :  * obtain it through the world-wide-web, please send an email                              
      13                 :  * to license@magentocommerce.com so we can send you a copy immediately.                   
      14                 :  *                                                                                         
      15                 :  * DISCLAIMER                                                                              
      16                 :  *                                                                                         
      17                 :  * Do not edit or add to this file if you wish to upgrade Magento to newer                 
      18                 :  * versions in the future. If you wish to customize Magento for your                       
      19                 :  * needs please refer to http://www.magentocommerce.com for more information.              
      20                 :  *                                                                                         
      21                 :  * @category   Varien                                                                      
      22                 :  * @package    Varien_Event                                                                
      23                 :  * @copyright  Copyright (c) 2008 Irubin Consulting Inc. DBA Varien (http://www.varien.com)
      24                 :  * @license    http://opensource.org/licenses/osl-3.0.php  Open Software License (OSL 3.0) 
      25                 :  */                                                                                        
      26                 :                                                                                            
      27                 :                                                                                            
      28                 : /**                                                                                        
      29                 :  * Collection of events                                                                    
      30                 :  *                                                                                         
      31                 :  * @category   Varien                                                                      
      32                 :  * @package    Varien_Event                                                                
      33                 :  * @author      Magento Core Team <core@magentocommerce.com>                               
      34                 :  */                                                                                        
      35                 : class Varien_Event_Collection                                                              
      36                 : {                                                                                          
      37                 :     /**                                                                                    
      38                 :      * Array of events in the collection                                                   
      39                 :      *                                                                                     
      40                 :      * @var array                                                                          
      41                 :      */                                                                                    
      42                 :     protected $_events;                                                                    
      43                 :                                                                                            
      44                 :     /**                                                                                    
      45                 :      * Global observers                                                                    
      46                 :      *                                                                                     
      47                 :      * For example regex observers will watch all events that                              
      48                 :      *                                                                                     
      49                 :      * @var Varien_Event_Observer_Collection                                               
      50                 :      */                                                                                    
      51                 :     protected $_observers;                                                                 
      52                 :                                                                                            
      53                 :     /**                                                                                    
      54                 :      * Initializes global observers collection                                             
      55                 :      *                                                                                     
      56                 :      */                                                                                    
      57                 :     public function __construct()                                                          
      58                 :     {                                                                                      
      59               0 :         $this->_events = array();                                                          
      60               0 :         $this->_globalObservers = new Varien_Event_Observer_Collection();                  
      61               0 :     }                                                                                      
      62                 :                                                                                            
      63                 :     /**                                                                                    
      64                 :      * Returns all registered events in collection                                         
      65                 :      *                                                                                     
      66                 :      * @return array                                                                       
      67                 :      */                                                                                    
      68                 :     public function getAllEvents()                                                         
      69                 :     {                                                                                      
      70               0 :         return $this->_events;                                                             
      71                 :     }                                                                                      
      72                 :                                                                                            
      73                 :     /**                                                                                    
      74                 :      * Returns all registered global observers for the collection of events                
      75                 :      *                                                                                     
      76                 :      * @return Varien_Event_Observer_Collection                                            
      77                 :      */                                                                                    
      78                 :     public function getGlobalObservers()                                                   
      79                 :     {                                                                                      
      80               0 :         return $this->_globalObservers;                                                    
      81                 :     }                                                                                      
      82                 :                                                                                            
      83                 :     /**                                                                                    
      84                 :      * Returns event by its name                                                           
      85                 :      *                                                                                     
      86                 :      * If event doesn't exist creates new one and returns it                               
      87                 :      *                                                                                     
      88                 :      * @param string $eventName                                                            
      89                 :      * @return Varien_Event                                                                
      90                 :      */                                                                                    
      91                 :     public function getEventByName($eventName)                                             
      92                 :     {                                                                                      
      93               0 :         if (!isset($this->_events[$eventName])) {                                          
      94               0 :             $this->addEvent(new Varien_Event(array('name'=>$eventName)));                  
      95               0 :         }                                                                                  
      96               0 :         return $this->_events[$eventName];                                                 
      97                 :     }                                                                                      
      98                 :                                                                                            
      99                 :     /**                                                                                    
     100                 :      * Register an event for this collection                                               
     101                 :      *                                                                                     
     102                 :      * @param Varien_Event $event                                                          
     103                 :      * @return Varien_Event_Collection                                                     
     104                 :      */                                                                                    
     105                 :     public function addEvent(Varien_Event $event)                                          
     106                 :     {                                                                                      
     107               0 :         $this->_events[$event->getName()] = $event;                                        
     108               0 :         return $this;                                                                      
     109                 :     }                                                                                      
     110                 :                                                                                            
     111                 :     /**                                                                                    
     112                 :      * Register an observer                                                                
     113                 :      *                                                                                     
     114                 :      * If observer has event_name property it will be regitered for this specific event.   
     115                 :      * If not it will be registered as global observer                                     
     116                 :      *                                                                                     
     117                 :      * @param Varien_Event_Observer $observer                                              
     118                 :      * @return Varien_Event_Collection                                                     
     119                 :      */                                                                                    
     120                 :     public function addObserver(Varien_Event_Observer $observer)                           
     121                 :     {                                                                                      
     122               0 :         $eventName = $observer->getEventName();                                            
     123               0 :         if ($eventName) {                                                                  
     124               0 :             $this->getEventByName($eventName)->addObserver($observer);                     
     125               0 :         } else {                                                                           
     126               0 :             $this->getGlobalObservers()->addObserver($observer);                           
     127                 :         }                                                                                  
     128               0 :         return $this;                                                                      
     129                 :     }                                                                                      
     130                 :                                                                                            
     131                 :     /**                                                                                    
     132                 :      * Dispatch event name with optional data                                              
     133                 :      *                                                                                     
     134                 :      * Will dispatch specific event and will try all global observers                      
     135                 :      *                                                                                     
     136                 :      * @param string $eventName                                                            
     137                 :      * @param array $data                                                                  
     138                 :      * @return Varien_Event_Collection                                                     
     139                 :      */                                                                                    
     140                 :     public function dispatch($eventName, array $data=array())                              
     141                 :     {                                                                                      
     142               0 :         $event = $this->getEventByName($eventName);                                        
     143               0 :         $event->addData($data)->dispatch();                                                
     144               0 :         $this->getGlobalObservers()->dispatch($event);                                     
     145               0 :         return $this;                                                                      
     146                 :     }                                                                                      

Generated by PHP_CodeCoverage 1.0.4 using PHP 5.3.4 and PHPUnit 3.5.13 at Tue Jul 5 9:07:16 UTC 2011.