1: <?php
2:
3: 4: 5: 6:
7:
8: namespace Nette\Utils;
9:
10: use Nette;
11:
12:
13: 14: 15:
16: class ArrayList implements \ArrayAccess, \Countable, \IteratorAggregate
17: {
18: use Nette\SmartObject;
19:
20: private $list = [];
21:
22:
23: 24: 25: 26:
27: public function getIterator()
28: {
29: return new \ArrayIterator($this->list);
30: }
31:
32:
33: 34: 35: 36:
37: public function count()
38: {
39: return count($this->list);
40: }
41:
42:
43: 44: 45: 46: 47: 48: 49:
50: public function offsetSet($index, $value)
51: {
52: if ($index === NULL) {
53: $this->list[] = $value;
54:
55: } elseif ($index < 0 || $index >= count($this->list)) {
56: throw new Nette\OutOfRangeException('Offset invalid or out of range');
57:
58: } else {
59: $this->list[(int) $index] = $value;
60: }
61: }
62:
63:
64: 65: 66: 67: 68: 69:
70: public function offsetGet($index)
71: {
72: if ($index < 0 || $index >= count($this->list)) {
73: throw new Nette\OutOfRangeException('Offset invalid or out of range');
74: }
75: return $this->list[(int) $index];
76: }
77:
78:
79: 80: 81: 82: 83:
84: public function offsetExists($index)
85: {
86: return $index >= 0 && $index < count($this->list);
87: }
88:
89:
90: 91: 92: 93: 94: 95:
96: public function offsetUnset($index)
97: {
98: if ($index < 0 || $index >= count($this->list)) {
99: throw new Nette\OutOfRangeException('Offset invalid or out of range');
100: }
101: array_splice($this->list, (int) $index, 1);
102: }
103:
104:
105: 106: 107: 108: 109:
110: public function prepend($value)
111: {
112: $first = array_slice($this->list, 0, 1);
113: $this->offsetSet(0, $value);
114: array_splice($this->list, 1, 0, $first);
115: }
116:
117: }
118: