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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
<?php
namespace Khansia\Generic;
class Set implements \Countable, \Iterator {
protected $_list = array();
protected $_index = 0;
protected $_count = 0;
public function __construct($list = array()) {
foreach ($list as $item) {
$this->_list[] = $item;
}
$this->_count = count($this->_list);
}
public function find($property, $value) {
foreach ($this->_list as $item) {
//if (isset($item->{$property})) {
if ($item->{$property} == $value) {
return $item;
}
//}
}
return false;
}
public function set($property, $value) {
foreach ($this->_list as $item) {
$item->{$property} = $value;
}
return true;
}
/* countable */
public function count() {
return $this->_count;
}
/* iterator */
public function rewind() {
$this->_index = 0;
}
public function next() {
$this->_index++;
}
public function current() {
return $this->_list[$this->_index];
}
public function key() {
return $this->_key;
}
public function valid() {
return ($this->_index < $this->_count);
}
public function clear() {
unset($this->_list);
$this->_list = array();
$this->_count = 0;
}
public function add(\Neuron\Generic\Object $object) {
if ($object) {
$this->_list[] = $object;
$this->_count = count($this->_list);
return $this->_count - 1;
}
return false;
}
public function remove($index) {
if (array_key_exists($index, $this->_list)) {
array_splice($this->_list, $index, 1);
$this->_count = count($this->_list);
return true;
}
return false;
}
public function item($index) {
return $this->_list[$index];
}
public function items() {
return $this->_list;
}
}