Open Journal Systems  3.3.0
IoEmittingEntityBody.php
1 <?php
2 
3 namespace Guzzle\Http;
4 
10 
15 {
17  protected $eventDispatcher;
18 
19  public static function getAllEvents()
20  {
21  return array('body.read', 'body.write');
22  }
23 
29  {
30  $this->eventDispatcher = $eventDispatcher;
31 
32  return $this;
33  }
34 
35  public function getEventDispatcher()
36  {
37  if (!$this->eventDispatcher) {
38  $this->eventDispatcher = new EventDispatcher();
39  }
40 
42  }
43 
44  public function dispatch($eventName, array $context = array())
45  {
46  return $this->getEventDispatcher()->dispatch($eventName, new Event($context));
47  }
48 
53  public function addSubscriber(EventSubscriberInterface $subscriber)
54  {
55  $this->getEventDispatcher()->addSubscriber($subscriber);
56 
57  return $this;
58  }
59 
60  public function read($length)
61  {
62  $event = array(
63  'body' => $this,
64  'length' => $length,
65  'read' => $this->body->read($length)
66  );
67  $this->dispatch('body.read', $event);
68 
69  return $event['read'];
70  }
71 
72  public function write($string)
73  {
74  $event = array(
75  'body' => $this,
76  'write' => $string,
77  'result' => $this->body->write($string)
78  );
79  $this->dispatch('body.write', $event);
80 
81  return $event['result'];
82  }
83 }
Symfony\Component\EventDispatcher\EventSubscriberInterface
Definition: lib/vendor/symfony/event-dispatcher/EventSubscriberInterface.php:25
Guzzle\Http\IoEmittingEntityBody\read
read($length)
Definition: IoEmittingEntityBody.php:63
Guzzle\Http\AbstractEntityBodyDecorator
Definition: AbstractEntityBodyDecorator.php:10
Guzzle\Common\HasDispatcherInterface
Definition: HasDispatcherInterface.php:11
Guzzle\Http\IoEmittingEntityBody\getAllEvents
static getAllEvents()
Definition: IoEmittingEntityBody.php:22
Guzzle\Http\IoEmittingEntityBody\$eventDispatcher
$eventDispatcher
Definition: IoEmittingEntityBody.php:20
Guzzle\Http\IoEmittingEntityBody\addSubscriber
addSubscriber(EventSubscriberInterface $subscriber)
Definition: IoEmittingEntityBody.php:56
Guzzle\Common\Event
Definition: lib/vendor/guzzle/guzzle/src/Guzzle/Common/Event.php:10
Guzzle\Http
Definition: AbstractEntityBodyDecorator.php:3
Guzzle\Http\IoEmittingEntityBody
Definition: IoEmittingEntityBody.php:14
Symfony\Component\EventDispatcher\EventDispatcherInterface
Definition: lib/vendor/symfony/event-dispatcher/EventDispatcherInterface.php:21
Guzzle\Http\IoEmittingEntityBody\setEventDispatcher
setEventDispatcher(EventDispatcherInterface $eventDispatcher)
Definition: IoEmittingEntityBody.php:31
Guzzle\Http\IoEmittingEntityBody\write
write($string)
Definition: IoEmittingEntityBody.php:75
Symfony\Component\EventDispatcher\EventDispatcher
Definition: lib/vendor/symfony/event-dispatcher/EventDispatcher.php:28
Guzzle\Http\IoEmittingEntityBody\dispatch
dispatch($eventName, array $context=array())
Definition: IoEmittingEntityBody.php:47
Guzzle\Http\IoEmittingEntityBody\getEventDispatcher
getEventDispatcher()
Definition: IoEmittingEntityBody.php:38