1: <?php
2: /**
3: * @author Chuck Hagenbuch <chuck@horde.org>
4: * @author Mike Naberezny <mike@maintainable.com>
5: * @license http://www.horde.org/licenses/bsd BSD
6: * @category Horde
7: * @package Argv
8: */
9:
10: /**
11: * Result hash for Horde_Argv_Parser
12: *
13: * @category Horde
14: * @package Argv
15: */
16: class Horde_Argv_Values implements IteratorAggregate, ArrayAccess, Countable
17: {
18: public function __construct($defaults = array())
19: {
20: foreach ($defaults as $attr => $val) {
21: $this->$attr = $val;
22: }
23: }
24:
25: public function __toString()
26: {
27: $str = array();
28: foreach ($this as $attr => $val) {
29: $str[] = $attr . ': ' . (string)$val;
30: }
31: return implode(', ', $str);
32: }
33:
34: public function offsetExists($attr)
35: {
36: return !is_null($this->$attr);
37: }
38:
39: public function offsetGet($attr)
40: {
41: return $this->$attr;
42: }
43:
44: public function offsetSet($attr, $val)
45: {
46: $this->$attr = $val;
47: }
48:
49: public function offsetUnset($attr)
50: {
51: unset($this->$attr);
52: }
53:
54: public function getIterator()
55: {
56: return new ArrayIterator(get_object_vars($this));
57: }
58:
59: public function count()
60: {
61: return count(get_object_vars($this));
62: }
63:
64: public function ensureValue($attr, $value)
65: {
66: if (is_null($this->$attr)) {
67: $this->$attr = $value;
68: }
69: return $this->$attr;
70: }
71:
72: }
73: