-
Notifications
You must be signed in to change notification settings - Fork 18
Expand file tree
/
Copy pathAbstractHasDispatcher.php
More file actions
59 lines (52 loc) · 1.41 KB
/
AbstractHasDispatcher.php
File metadata and controls
59 lines (52 loc) · 1.41 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
<?php
namespace Phpforce\Common;
use Symfony\Component\EventDispatcher\EventDispatcherInterface;
use Symfony\Component\EventDispatcher\EventDispatcher;
use Symfony\Component\EventDispatcher\GenericEvent as Event;
/**
* Can be extended by classes that dispatch events using the event dispatcher
*
*/
abstract class AbstractHasDispatcher
{
/**
* @var EventDispatcherInterface
*/
protected $eventDispatcher;
/**
* Set event dispatcher
*
* @param EventDispatcherInterface $eventDispatcher
*/
public function setEventDispatcher(EventDispatcherInterface $eventDispatcher)
{
$this->eventDispatcher = $eventDispatcher;
}
/**
* Get event dispatcher
*
* If no event dispatcher is supplied, a new one is created. This one will
* then be used internally by the Accelerate library.
*
* @return EventDispatcherInterface
*/
public function getEventDispatcher()
{
if (null == $this->eventDispatcher) {
$this->eventDispatcher = new EventDispatcher();
}
return $this->eventDispatcher;
}
/**
* Dispatch an event
*
* @param string $name Name of event: see Events.php
* @param Event $event Event object
*
* @return Event
*/
protected function dispatch($name, Event $event)
{
return $this->getEventDispatcher()->dispatch($event, $name);
}
}