Subversion Repositories php-qbpwcf

Rev

Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
3 liveuser 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
    /** @var EventDispatcherInterface */
15
    protected $eventDispatcher;
16
 
17
    public static function getAllEvents()
18
    {
19
        return array();
20
    }
21
 
22
    public function setEventDispatcher(EventDispatcherInterface $eventDispatcher)
23
    {
24
        $this->eventDispatcher = $eventDispatcher;
25
 
26
        return $this;
27
    }
28
 
29
    public function getEventDispatcher()
30
    {
31
        if (!$this->eventDispatcher) {
32
            $this->eventDispatcher = new EventDispatcher();
33
        }
34
 
35
        return $this->eventDispatcher;
36
    }
37
 
38
    public function dispatch($eventName, array $context = array())
39
    {
40
        return $this->getEventDispatcher()->dispatch($eventName, new Event($context));
41
    }
42
 
43
    public function addSubscriber(EventSubscriberInterface $subscriber)
44
    {
45
        $this->getEventDispatcher()->addSubscriber($subscriber);
46
 
47
        return $this;
48
    }
49
}