BraintreeCollection

Braintree Generic collection.

Defined (1)

The class is defined in the following location(s).

/classes/lib/Braintree/Braintree/Collection.php  
  1. class Collection implements Countable, IteratorAggregate, ArrayAccess 
  2. /** 
  3. * @var array collection storage 
  4. */ 
  5. protected $_collection = []; 
  6.  
  7. /** 
  8. * Add a value into the collection 
  9. * @param string $value 
  10. */ 
  11. public function add($value) 
  12. $this->_collection[] = $value; 
  13.  
  14. /** 
  15. * Set index's value 
  16. * @param integer $index 
  17. * @param mixed $value 
  18. * @throws OutOfRangeException 
  19. */ 
  20. public function set($index, $value) 
  21. if($index >= $this->count()) 
  22. throw new OutOfRangeException('Index out of range'); 
  23.  
  24. $this->_collection[$index] = $value; 
  25.  
  26. /** 
  27. * Remove a value from the collection 
  28. * @param integer $index index to remove 
  29. * @throws OutOfRangeException if index is out of range 
  30. */ 
  31. public function remove($index) 
  32. if($index >= $this->count()) 
  33. throw new OutOfRangeException('Index out of range'); 
  34.  
  35. array_splice($this->_collection, $index, 1); 
  36.  
  37. /** 
  38. * Return value at index 
  39. * @param integer $index 
  40. * @return mixed 
  41. * @throws OutOfRangeException 
  42. */ 
  43. public function get($index) 
  44. if($index >= $this->count()) 
  45. throw new OutOfRangeException('Index out of range'); 
  46.  
  47. return $this->_collection[$index]; 
  48.  
  49. /** 
  50. * Determine if index exists 
  51. * @param integer $index 
  52. * @return boolean 
  53. */ 
  54. public function exists($index) 
  55. if($index >= $this->count()) 
  56. return false; 
  57.  
  58. return true; 
  59. /** 
  60. * Return count of items in collection 
  61. * Implements countable 
  62. * @return integer 
  63. */ 
  64. public function count() 
  65. return count($this->_collection); 
  66.  
  67.  
  68. /** 
  69. * Return an iterator 
  70. * Implements IteratorAggregate 
  71. * @return ArrayIterator 
  72. */ 
  73. public function getIterator() 
  74. return new ArrayIterator($this->_collection); 
  75.  
  76. /** 
  77. * Set offset to value 
  78. * Implements ArrayAccess 
  79. * @see set 
  80. * @param integer $offset 
  81. * @param mixed $value 
  82. */ 
  83. public function offsetSet($offset, $value) 
  84. $this->set($offset, $value); 
  85.  
  86. /** 
  87. * Unset offset 
  88. * Implements ArrayAccess 
  89. * @see remove 
  90. * @param integer $offset 
  91. */ 
  92. public function offsetUnset($offset) 
  93. $this->remove($offset); 
  94.  
  95. /** 
  96. * get an offset's value 
  97. * Implements ArrayAccess 
  98. * @see get 
  99. * @param integer $offset 
  100. * @return mixed 
  101. */ 
  102. public function offsetGet($offset) 
  103. return $this->get($offset); 
  104.  
  105. /** 
  106. * Determine if offset exists 
  107. * Implements ArrayAccess 
  108. * @see exists 
  109. * @param integer $offset 
  110. * @return boolean 
  111. */ 
  112. public function offsetExists($offset) 
  113. return $this->exists($offset); 
  114.