Page Menu
Home
WickedGov Phorge
Search
Configure Global Search
Log In
Files
F1430283
EventsEmitter.php
No One
Temporary
Actions
Download File
Edit File
Delete File
View Transforms
Subscribe
Flag For Later
Award Token
Size
1 KB
Referenced Files
None
Subscribers
None
EventsEmitter.php
View Options
<?php
/**
* This file is part of the Peast package
*
* (c) Marco Marchiò <marco.mm89@gmail.com>
*
* For the full copyright and license information refer to the LICENSE file
* distributed with this source code
*/
namespace
Peast\Syntax
;
/**
* Events emitter class. An instance of this class is used by Parser and Scanner
* to emit events and attach listeners to them
*
* @author Marco Marchiò <marco.mm89@gmail.com>
*/
class
EventsEmitter
{
/**
* Events registry array
*
* @var array
*/
protected
$eventsRegistry
=
array
();
/**
* Attaches a listener function to the given event
*
* @param string $event Event name
* @param callable $listener Listener function
*
* @return $this
*/
public
function
addListener
(
$event
,
$listener
)
{
if
(!
isset
(
$this
->
eventsRegistry
[
$event
]))
{
$this
->
eventsRegistry
[
$event
]
=
array
();
}
$this
->
eventsRegistry
[
$event
][]
=
$listener
;
return
$this
;
}
/**
* Fires an event
*
* @param string $event Event name
* @param array $args Arguments to pass to functions attached to the
* event
*
* @return $this
*/
public
function
fire
(
$event
,
$args
=
array
())
{
if
(
isset
(
$this
->
eventsRegistry
[
$event
]))
{
foreach
(
$this
->
eventsRegistry
[
$event
]
as
$listener
)
{
call_user_func_array
(
$listener
,
$args
);
}
}
return
$this
;
}
}
File Metadata
Details
Attached
Mime Type
text/x-php
Expires
Sat, May 16, 18:36 (5 h, 1 m)
Storage Engine
local-disk
Storage Format
Raw Data
Storage Handle
00/a1/3aabcea37de6a3ea0cf9bd13f1c9
Default Alt Text
EventsEmitter.php (1 KB)
Attached To
Mode
rMWPROD MediaWiki Production
Attached
Detach File
Event Timeline
Log In to Comment