/
Collection.php
54 lines (43 loc) · 1013 Bytes
/
Collection.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
<?php
class Collection
{
protected $_items;
public function __construct()
{
$this->_items = array();
}
public function add($item)
{
array_push($this->_items, $item);
}
public function contains($value)
{
if (in_array($value, $this->_items))
{
return TRUE;
}
return FALSE;
}
public function remove()
{
if (array_pop($this->_items) === NULL)
{
throw new UnderflowException('Collection is empty');
}
return TRUE;
}
public function getCount()
{
return count($this->_items);
}
public function removeAt($index)
{
if ($this->_items[$index] === NULL)
{
throw new OutOfRangeException('Invalid index');
}
unset($this->_items[$index]);
array_unshift($this->_items, array_shift($this->_items));
return TRUE;
}
}