Blame view

sources/3rdparty/guzzle/common/Guzzle/Common/AbstractHasDispatcher.php 1.17 KB
6d9380f96   Cédric Dupont   Update sources OC...
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
  <?php
  
  namespace Guzzle\Common;
  
  use Symfony\Component\EventDispatcher\EventDispatcher;
  use Symfony\Component\EventDispatcher\EventDispatcherInterface;
  use Symfony\Component\EventDispatcher\EventSubscriberInterface;
  
  /**
   * Class that holds an event dispatcher
   */
  class AbstractHasDispatcher implements HasDispatcherInterface
  {
      /** @var EventDispatcherInterface */
      protected $eventDispatcher;
  
      public static function getAllEvents()
      {
          return array();
      }
  
      public function setEventDispatcher(EventDispatcherInterface $eventDispatcher)
      {
          $this->eventDispatcher = $eventDispatcher;
  
          return $this;
      }
  
      public function getEventDispatcher()
      {
          if (!$this->eventDispatcher) {
              $this->eventDispatcher = new EventDispatcher();
          }
  
          return $this->eventDispatcher;
      }
  
      public function dispatch($eventName, array $context = array())
      {
          return $this->getEventDispatcher()->dispatch($eventName, new Event($context));
      }
  
      public function addSubscriber(EventSubscriberInterface $subscriber)
      {
          $this->getEventDispatcher()->addSubscriber($subscriber);
  
          return $this;
      }
  }