PEIP_Event_Builder.php

Go to the documentation of this file.
00001 <?php
00002 
00003 /*
00004  * This file is part of the PEIP package.
00005  * (c) 2010 Timo Michna <timomichna/yahoo.de>
00006  * 
00007  * For the full copyright and license information, please view the LICENSE
00008  * file that was distributed with this source code.
00009  */
00010 
00022 class PEIP_Event_Builder {
00023 
00024     protected $eventClass,
00025         $defaultParameters;
00026     
00027     protected static $instances = array();      
00028         
00029     
00036     public function __construct($eventClass, array $defaultParameters = array()){
00037         $this->eventClass = $eventClass;
00038         $this->defaultParameters = $defaultParameters;
00039     }
00040 
00041     public static function getInstance($eventClass = false){
00042         $eventClass = $eventClass ? $eventClass : 'PEIP_Event';
00043         return isset(self::$instances[$eventClass]) 
00044             ? self::$instances[$eventClass] 
00045             : self::$instances[$eventClass] = new PEIP_Event_Builder($eventClass);
00046     }
00047     
00048     
00049     
00057     public function build($subject, $name, array $parameters = array()){
00058         $parameters = array_merge($this->defaultParameters, $parameters);
00059         return $event = new $this->eventClass($subject, $name, $parameters);
00060     }
00061 
00062     
00079     public function buildAndDispatch(PEIP_Object_Event_Dispatcher $dispatcher, $subject, $name, array $parameters = array()){
00080         $event = $this->build($subject, $name, $parameters);    
00081         return $dispatcher->notify($name, $event);          
00082     }
00083 
00084 
00085 
00086 }

Generated on Mon Apr 12 11:39:00 2010 for PEIP by  doxygen 1.5.1