Overview

Namespaces

  • Contrib
    • Bundle
      • CoverallsBundle
        • Console
        • Entity
      • CoverallsV1Bundle
        • Api
        • Collector
        • Command
        • Config
        • Entity
          • Git
    • Component
      • File
      • Log
      • System
        • Git
  • Guzzle
    • Batch
      • Exception
    • Cache
    • Common
      • Exception
    • Http
      • Curl
      • Exception
      • Message
      • QueryAggregator
    • Inflection
    • Iterator
    • Log
    • Parser
      • Cookie
      • Message
      • UriTemplate
      • Url
    • Plugin
      • Async
      • Backoff
      • Cache
      • Cookie
        • CookieJar
        • Exception
      • CurlAuth
      • ErrorResponse
        • Exception
      • History
      • Log
      • Md5
      • Mock
      • Oauth
    • Service
      • Builder
      • Command
        • Factory
        • LocationVisitor
          • Request
          • Response
      • Description
      • Exception
      • Resource
    • Stream
  • PHP
  • Psr
    • Log
  • Symfony
    • Component
      • Config
        • Definition
          • Builder
          • Exception
        • Exception
        • Loader
        • Resource
        • Util
      • Console
        • Command
        • Formatter
        • Helper
        • Input
        • Output
        • Tester
      • EventDispatcher
        • Debug
      • Finder
        • Adapter
        • Comparator
        • Exception
        • Expression
        • Iterator
        • Shell
      • Stopwatch
      • Yaml
        • Exception

Classes

  • AbstractEntityBodyDecorator
  • CachingEntityBody
  • Client
  • EntityBody
  • IoEmittingEntityBody
  • Mimetypes
  • QueryString
  • ReadLimitEntityBody
  • RedirectPlugin
  • Url

Interfaces

  • ClientInterface
  • EntityBodyInterface
  • Overview
  • Namespace
  • Class
  • Tree
  • Todo
  1: <?php
  2: 
  3: namespace Guzzle\Http;
  4: 
  5: use Guzzle\Common\Event;
  6: use Guzzle\Common\HasDispatcherInterface;
  7: use Symfony\Component\EventDispatcher\EventDispatcher;
  8: use Symfony\Component\EventDispatcher\EventSubscriberInterface;
  9: use Symfony\Component\EventDispatcher\EventDispatcherInterface;
 10: 
 11: /**
 12:  * EntityBody decorator that emits events for read and write methods
 13:  */
 14: class IoEmittingEntityBody extends AbstractEntityBodyDecorator implements HasDispatcherInterface
 15: {
 16:     /**
 17:      * @var EventDispatcherInterface
 18:      */
 19:     protected $eventDispatcher;
 20: 
 21:     /**
 22:      * {@inheritdoc}
 23:      */
 24:     public static function getAllEvents()
 25:     {
 26:         return array('body.read', 'body.write');
 27:     }
 28: 
 29:     /**
 30:      * {@inheritdoc}
 31:      * @codeCoverageIgnore
 32:      */
 33:     public function setEventDispatcher(EventDispatcherInterface $eventDispatcher)
 34:     {
 35:         $this->eventDispatcher = $eventDispatcher;
 36: 
 37:         return $this;
 38:     }
 39: 
 40:     /**
 41:      * {@inheritdoc}
 42:      */
 43:     public function getEventDispatcher()
 44:     {
 45:         if (!$this->eventDispatcher) {
 46:             $this->eventDispatcher = new EventDispatcher();
 47:         }
 48: 
 49:         return $this->eventDispatcher;
 50:     }
 51: 
 52:     /**
 53:      * {@inheritdoc}
 54:      */
 55:     public function dispatch($eventName, array $context = array())
 56:     {
 57:         $this->getEventDispatcher()->dispatch($eventName, new Event($context));
 58:     }
 59: 
 60:     /**
 61:      * {@inheritdoc}
 62:      * @codeCoverageIgnore
 63:      */
 64:     public function addSubscriber(EventSubscriberInterface $subscriber)
 65:     {
 66:         $this->getEventDispatcher()->addSubscriber($subscriber);
 67: 
 68:         return $this;
 69:     }
 70: 
 71:     /**
 72:      * {@inheritdoc}
 73:      */
 74:     public function read($length)
 75:     {
 76:         $event = array(
 77:             'body'   => $this,
 78:             'length' => $length,
 79:             'read'   => $this->body->read($length)
 80:         );
 81:         $this->dispatch('body.read', $event);
 82: 
 83:         return $event['read'];
 84:     }
 85: 
 86:     /**
 87:      * {@inheritdoc}
 88:      */
 89:     public function write($string)
 90:     {
 91:         $event = array(
 92:             'body'   => $this,
 93:             'write'  => $string,
 94:             'result' => $this->body->write($string)
 95:         );
 96:         $this->dispatch('body.write', $event);
 97: 
 98:         return $event['result'];
 99:     }
100: }
101: 
php-coveralls API documentation generated by ApiGen 2.8.0