jsjohnst / php_class_lib

A collection of PHP classes which anyone can add to their development toolbox

php_class_lib / classes / types / enum / EnumIterator.inc
de72408e » jsjohnst 2008-10-05 Added enum and enumiterator... 1 <?php
2
3 class EnumIterator implements Iterator {
4 protected $classes = array();
5 protected $enum_type;
6
7 public function __construct($enum_type) {
8 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!");
9 $this->enum_type = $enum_type;
10 foreach(get_declared_classes() as $class) {
11 if(is_subclass_of($class, $this->enum_type)) {
12 $this->classes[] = $class;
13 }
14 }
15 }
16
17 public function current() {
18 return current($this->classes);
19 }
20
21 public function key() {
22 return key($this->classes);
23 }
24
25 public function next() {
26 next($this->classes);
27 return $this->current();
28 }
29
30 public function rewind() {
31 return reset($this->classes);
32 }
33
34 public function valid() {
35 return (bool) $this->current();
36 }
37 }