Event.php 1.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. <?php
  2. namespace Guzzle\Common;
  3. use Symfony\Component\EventDispatcher\Event as SymfonyEvent;
  4. /**
  5. * Default event for Guzzle notifications
  6. */
  7. class Event extends SymfonyEvent implements ToArrayInterface, \ArrayAccess, \IteratorAggregate
  8. {
  9. /** @var array */
  10. private $context;
  11. /**
  12. * @param array $context Contextual information
  13. */
  14. public function __construct(array $context = array())
  15. {
  16. $this->context = $context;
  17. }
  18. public function getIterator()
  19. {
  20. return new \ArrayIterator($this->context);
  21. }
  22. public function offsetGet($offset)
  23. {
  24. return isset($this->context[$offset]) ? $this->context[$offset] : null;
  25. }
  26. public function offsetSet($offset, $value)
  27. {
  28. $this->context[$offset] = $value;
  29. }
  30. public function offsetExists($offset)
  31. {
  32. return isset($this->context[$offset]);
  33. }
  34. public function offsetUnset($offset)
  35. {
  36. unset($this->context[$offset]);
  37. }
  38. public function toArray()
  39. {
  40. return $this->context;
  41. }
  42. }