Guest User

Untitled

a guest
Nov 24th, 2017
357
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.08 KB | None | 0 0
  1. <?php
  2. /**
  3. * Collection
  4. *
  5. * @author Guido Scialfa <dev@guidoscialfa.com>
  6. * @copyright Copyright (c) 2017, Guido Scialfa
  7. * @license GNU General Public License, version 2
  8. *
  9. * Copyright (C) 2017 Guido Scialfa <dev@guidoscialfa.com>
  10. *
  11. * This program is free software; you can redistribute it and/or
  12. * modify it under the terms of the GNU General Public License
  13. * as published by the Free Software Foundation; either version 2
  14. * of the License, or (at your option) any later version.
  15. *
  16. * This program is distributed in the hope that it will be useful,
  17. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  18. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  19. * GNU General Public License for more details.
  20. *
  21. * You should have received a copy of the GNU General Public License
  22. * along with this program; if not, write to the Free Software
  23. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
  24. */
  25.  
  26. namespace Unprefix;
  27.  
  28. /**
  29. * Class Collection
  30. *
  31. * @version 1.0.0
  32. * @author Guido Scialfa <dev@guidoscialfa.com>
  33. */
  34. class Collection implements \ArrayAccess, \Iterator, \Countable
  35. {
  36. /**
  37. * List
  38. *
  39. * @since 1.0.0
  40. *
  41. * @var array
  42. */
  43. private $list;
  44.  
  45. /**
  46. * FilterContainer constructor
  47. *
  48. * @since 1.0.0
  49. *
  50. * @param array $list
  51. */
  52. public function __construct(array $list = array())
  53. {
  54. $this->list = $list;
  55. }
  56.  
  57. /**
  58. * As Array
  59. *
  60. * @since 1.0.0
  61. *
  62. * @return array The entire data list
  63. */
  64. public function asArray()
  65. {
  66. return $this->list;
  67. }
  68.  
  69. /**
  70. * @inheritDoc
  71. *
  72. * @since 1.0.0
  73. */
  74. public function offsetExists($offset)
  75. {
  76. return isset($this->list[$offset]);
  77. }
  78.  
  79. /**
  80. * @inheritDoc
  81. *
  82. * @since 1.0.0
  83. */
  84. public function offsetGet($offset)
  85. {
  86. if ($this->offsetExists($offset)) {
  87. return $this->list[$offset];
  88. }
  89. }
  90.  
  91. /**
  92. * @inheritDoc
  93. *
  94. * @since 1.0.0
  95. */
  96. public function offsetSet($offset, $value)
  97. {
  98. $this->list[$offset] = $value;
  99. }
  100.  
  101. /**
  102. * @inheritDoc
  103. *
  104. * @since 1.0.0
  105. */
  106. public function offsetUnset($offset)
  107. {
  108. unset($this->list[$offset]);
  109. }
  110.  
  111. /**
  112. * @inheritDoc
  113. *
  114. * @since 1.0.0
  115. */
  116. public function current()
  117. {
  118. return current($this->list);
  119. }
  120.  
  121. /**
  122. * @inheritDoc
  123. *
  124. * @since 1.0.0
  125. */
  126. public function next()
  127. {
  128. return next($this->list);
  129. }
  130.  
  131. /**
  132. * @inheritDoc
  133. *
  134. * @since 1.0.0
  135. */
  136. public function key()
  137. {
  138. return key($this->list);
  139. }
  140.  
  141. /**
  142. * @inheritDoc
  143. *
  144. * @since 1.0.0
  145. */
  146. public function valid()
  147. {
  148. return isset($this->list[$this->key()]);
  149. }
  150.  
  151. /**
  152. * @inheritDoc
  153. *
  154. * @since 1.0.0
  155. */
  156. public function rewind()
  157. {
  158. reset($this->list);
  159. }
  160.  
  161. /**
  162. * @inheritDoc
  163. *
  164. * @since 1.0.0
  165. */
  166. public function count()
  167. {
  168. return count($this->list);
  169. }
  170. }
Add Comment
Please, Sign In to add comment