1: <?php
2:
3: namespace Guzzle\Common;
4:
5: use Symfony\Component\EventDispatcher\EventDispatcher;
6: use Symfony\Component\EventDispatcher\EventDispatcherInterface;
7: use Symfony\Component\EventDispatcher\EventSubscriberInterface;
8:
9: /**
10: * Class that holds an event dispatcher
11: */
12: class AbstractHasDispatcher implements HasDispatcherInterface
13: {
14: /**
15: * @var EventDispatcherInterface
16: */
17: protected $eventDispatcher;
18:
19: /**
20: * {@inheritdoc}
21: */
22: public static function getAllEvents()
23: {
24: return array();
25: }
26:
27: /**
28: * {@inheritdoc}
29: */
30: public function setEventDispatcher(EventDispatcherInterface $eventDispatcher)
31: {
32: $this->eventDispatcher = $eventDispatcher;
33:
34: return $this;
35: }
36:
37: /**
38: * {@inheritdoc}
39: */
40: public function getEventDispatcher()
41: {
42: if (!$this->eventDispatcher) {
43: $this->eventDispatcher = new EventDispatcher();
44: }
45:
46: return $this->eventDispatcher;
47: }
48:
49: /**
50: * {@inheritdoc}
51: */
52: public function dispatch($eventName, array $context = array())
53: {
54: $this->getEventDispatcher()->dispatch($eventName, new Event($context));
55: }
56:
57: /**
58: * {@inheritdoc}
59: */
60: public function addSubscriber(EventSubscriberInterface $subscriber)
61: {
62: $this->getEventDispatcher()->addSubscriber($subscriber);
63:
64: return $this;
65: }
66: }
67: