public
Description: A collection of PHP classes which anyone can add to their development toolbox
Homepage: http://www.jeremyjohnstone.com
Clone URL: git://github.com/jsjohnst/php_class_lib.git
Click here to lend your support to: php_class_lib and make a donation at www.pledgie.com !
php_class_lib / classes / types / enum / EnumIterator.inc
100644 38 lines (30 sloc) 0.81 kb
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
<?php
 
class EnumIterator implements Iterator {
protected $classes = array();
protected $enum_type;
 
public function __construct($enum_type) {
if(!class_exists($enum_type) || !is_subclass_of($enum_type, "Enum")) throw new Exception("Specified Enum type doesn't exist or is not an Enum!");
$this->enum_type = $enum_type;
foreach(get_declared_classes() as $class) {
if(is_subclass_of($class, $this->enum_type)) {
$this->classes[] = $class;
}
}
}
 
public function current() {
return current($this->classes);
}
 
public function key() {
return key($this->classes);
}
 
public function next() {
next($this->classes);
return $this->current();
}
 
public function rewind() {
return reset($this->classes);
}
 
public function valid() {
return (bool) $this->current();
}
}