Exponential Basic 2.4.0.1 Exponential Basic CMS — PHP Class Reference

ezpevent.php
Go to the documentation of this file.
1 <?php
20 class ezpEvent
21 {
27 protected $listeners = array();
28
35 protected static $listenerIdNumber = 0;
36
42 protected static $instance = null;
43
49 protected $loadGlobalEvents;
50
57 public function __construct( $loadGlobalEvents = true )
58 {
59 $this->loadGlobalEvents = $loadGlobalEvents;
60 }
61
65 public function registerEventListeners()
66 {
67 if ( $this->loadGlobalEvents )
68 {
69 $listeners = eZINI::instance()->variable( 'Event', 'Listeners' );
70 foreach ( $listeners as $listener )
71 {
72 // $listener may be empty if some override logic has been involved
73 if ( $listener == "" )
74 {
75 continue;
76 }
77
78 // format from ini is seperated by @
79 list( $event, $callback ) = explode( '@', $listener );
80 $this->attach( $event, $callback );
81 }
82 }
83 }
84
92 public function attach( $name, $listener )
93 {
94 $id = self::$listenerIdNumber++;
95 // explode callback if static class string, workaround for PHP < 5.2.3
96 if ( is_string( $listener ) && strpos( $listener, '::' ) !== false )
97 {
98 $listener = explode( '::', $listener );
99 }
100
101 $this->listeners[$name][$id] = $listener;
102 return $id;
103 }
104
112 public function detach( $name, $id )
113 {
114 if ( !isset( $this->listeners[$name][$id] ) )
115 {
116 return false;
117 }
118
119 unset( $this->listeners[$name][$id] );
120 return true;
121 }
122
130 public function notify( $name, array $params = array() )
131 {
132 if ( empty( $this->listeners[$name] ) )
133 {
134 return false;
135 }
136
137 foreach ( $this->listeners[$name] as $listener )
138 {
139 call_user_func_array( $listener, $params );
140 }
141 return true;
142 }
143
152 public function filter( $name, $value )
153 {
154 if ( empty( $this->listeners[$name] ) )
155 {
156 return $value;
157 }
158
159 $params = func_get_args();
160 // We delete the first param, which is the name of the filter
161 // in order to retrieve only params for the listener
162 array_shift( $params );
163
164 foreach ( $this->listeners[$name] as $listener )
165 {
166 $params[0] = call_user_func_array( $listener, $params );
167 }
168 return $params[0];
169 }
170
176 public static function getInstance()
177 {
178 if ( !self::$instance instanceof ezpEvent )
179 {
180 self::$instance = new self();
181 }
182 return self::$instance;
183 }
184
188 public static function resetInstance()
189 {
190 self::$instance = null;
191 }
192 }
193
194 ?>
ezpEvent
Definition: ezpevent.php:21
ezpEvent\$listenerIdNumber
static $listenerIdNumber
Definition: ezpevent.php:35
ezpEvent\attach
attach( $name, $listener)
Definition: ezpevent.php:92
ezpEvent\$listeners
$listeners
Definition: ezpevent.php:27
ezpEvent\notify
notify( $name, array $params=array())
Definition: ezpevent.php:130
ezpEvent\getInstance
static getInstance()
Definition: ezpevent.php:176
ezpEvent\detach
detach( $name, $id)
Definition: ezpevent.php:112
ezpEvent\__construct
__construct( $loadGlobalEvents=true)
Definition: ezpevent.php:57
ezpEvent\resetInstance
static resetInstance()
Definition: ezpevent.php:188
ezpEvent\filter
filter( $name, $value)
Definition: ezpevent.php:152
ezpEvent\registerEventListeners
registerEventListeners()
Definition: ezpevent.php:65
ezpEvent\$instance
static $instance
Definition: ezpevent.php:42
ezpEvent\$loadGlobalEvents
$loadGlobalEvents
Definition: ezpevent.php:49
$name
$name
Definition: companytypelist.php:194
$id
$id
Definition: companytypelist.php:193
$event
if(isset( $Action) && $Action=="New") else $event
Definition: eventedit.php:189
$instance
$instance
Definition: orderedit.php:667
Copyright © 1998 – 2026 7x. All rights reserved. Licensed under the GNU GPLv2+.