1: <?php
2:
3: 4: 5: 6: 7: 8: 9: 10:
11:
12:
13:
14: 15: 16: 17: 18: 19:
20: class DibiRow implements ArrayAccess, IteratorAggregate, Countable
21: {
22:
23: public function __construct($arr)
24: {
25: foreach ($arr as $k => $v) $this->$k = $v;
26: }
27:
28:
29:
30: public function toArray()
31: {
32: return (array) $this;
33: }
34:
35:
36:
37: 38: 39: 40: 41: 42:
43: public function asDateTime($key, $format = NULL)
44: {
45: $time = $this[$key];
46: if (!$time instanceof DibiDateTime) {
47: if ((int) $time === 0) {
48: return NULL;
49: }
50: $time = new DibiDateTime(is_numeric($time) ? date('Y-m-d H:i:s', $time) : $time);
51: }
52: return $format === NULL ? $time : $time->format($format);
53: }
54:
55:
56:
57: 58: 59: 60: 61:
62: public function asTimestamp($key)
63: {
64: trigger_error(__METHOD__ . '() is deprecated.', E_USER_WARNING);
65: $time = $this[$key];
66: return (int) $time === 0
67: ? NULL
68: : (is_numeric($time) ? (int) $time : strtotime($time));
69: }
70:
71:
72:
73: 74: 75: 76: 77:
78: public function asBool($key)
79: {
80: trigger_error(__METHOD__ . '() is deprecated.', E_USER_WARNING);
81: return $this[$key];
82: }
83:
84:
85:
86:
87: public function asDate($key, $format = NULL)
88: {
89: trigger_error(__METHOD__ . '() is deprecated.', E_USER_WARNING);
90: if ($format === NULL) {
91: return $this->asTimestamp($key);
92: } else {
93: return $this->asDateTime($key, $format === TRUE ? NULL : $format);
94: }
95: }
96:
97:
98:
99:
100:
101:
102:
103: final public function count()
104: {
105: return count((array) $this);
106: }
107:
108:
109:
110: final public function getIterator()
111: {
112: return new ArrayIterator($this);
113: }
114:
115:
116:
117: final public function offsetSet($nm, $val)
118: {
119: $this->$nm = $val;
120: }
121:
122:
123:
124: final public function offsetGet($nm)
125: {
126: return $this->$nm;
127: }
128:
129:
130:
131: final public function offsetExists($nm)
132: {
133: return isset($this->$nm);
134: }
135:
136:
137:
138: final public function offsetUnset($nm)
139: {
140: unset($this->$nm);
141: }
142:
143: }
144: