-
Notifications
You must be signed in to change notification settings - Fork 18
/
class.messagestack.php
executable file
·64 lines (47 loc) · 1.4 KB
/
class.messagestack.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
55
56
57
58
59
60
61
62
63
64
<?php
Final Class MessageStack implements Iterator{
private $_messages = array();
public function __construct(array $messages=NULL){
$this->_messages = array();
if(!is_null($messages)){
$this->_messages = $messages;
}
}
public function rewind(){
reset($this->_messages);
}
public function current(){
return current($this->_messages);
}
public function key(){
return key($this->_messages);
}
public function next(){
return next($this->_messages);
}
public function valid(){
return ($this->current() !== false);
}
public function length(){
return count($this->_messages);
}
## TODO: This is a bit voodoo. Maybe come up with a better solution
private static function __sanitiseElementName($element){
return str_replace('_', '-', $element);
}
public function append($element, $message){
$this->_messages[self::__sanitiseElementName($element)] = $message;
}
public function remove($element){
$element = self::__sanitiseElementName($element);
if(isset($this->_messages[$element])){
unset($this->_messages[$element]);
}
}
public function __get($element){
return (isset($this->_messages[$element]) ? $this->_messages[$element] : NULL);
}
public function __isset($element){
return isset($this->_messages[$element]);
}
}