HasDataTrait.php 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. <?php
  2. namespace GuzzleHttp\Command;
  3. /**
  4. * Basic collection behavior for Command and Result objects.
  5. *
  6. * The methods in the class are primarily for implementing the ArrayAccess,
  7. * Countable, and IteratorAggregate interfaces.
  8. */
  9. trait HasDataTrait
  10. {
  11. /** @var array Data stored in the collection. */
  12. protected $data;
  13. public function __toString()
  14. {
  15. return print_r($this, true);
  16. }
  17. public function __debugInfo()
  18. {
  19. return $this->data;
  20. }
  21. #[\ReturnTypeWillChange]
  22. public function offsetExists($offset)
  23. {
  24. return array_key_exists($offset, $this->data);
  25. }
  26. #[\ReturnTypeWillChange]
  27. public function offsetGet($offset)
  28. {
  29. return isset($this->data[$offset]) ? $this->data[$offset] : null;
  30. }
  31. #[\ReturnTypeWillChange]
  32. public function offsetSet($offset, $value)
  33. {
  34. $this->data[$offset] = $value;
  35. }
  36. #[\ReturnTypeWillChange]
  37. public function offsetUnset($offset)
  38. {
  39. unset($this->data[$offset]);
  40. }
  41. #[\ReturnTypeWillChange]
  42. public function count()
  43. {
  44. return count($this->data);
  45. }
  46. #[\ReturnTypeWillChange]
  47. public function getIterator()
  48. {
  49. return new \ArrayIterator($this->data);
  50. }
  51. public function toArray()
  52. {
  53. return $this->data;
  54. }
  55. }