1: <?php
2: 3: 4: 5: 6: 7: 8: 9: 10: 11: 12: 13: 14:
15: class Horde_Imap_Client_Data_Acl extends Horde_Imap_Client_Data_AclCommon implements ArrayAccess, Iterator, Serializable
16: {
17: 18: 19: 20: 21:
22: protected $_rights;
23:
24: 25: 26: 27: 28:
29: public function __construct($rights = '')
30: {
31: $this->_rights = str_split($rights);
32: $this->_normalize();
33: }
34:
35: 36: 37: 38: 39:
40: public function __toString()
41: {
42: return implode('', $this->_rights);
43: }
44:
45: 46: 47: 48: 49: 50: 51: 52:
53: public function diff($rights)
54: {
55: $rlist = array_diff(str_split($rights), array_keys($this->_virtual));
56:
57: return array(
58: 'added' => implode('', array_diff($rlist, $this->_rights)),
59: 'removed' => implode('', array_diff($this->_rights, $rlist))
60: );
61: }
62:
63: 64: 65:
66: protected function _normalize()
67: {
68: 69: 70: 71: 72:
73: foreach ($this->_virtual as $key => $val) {
74: if ($this[$key]) {
75: unset($this[$key]);
76: if (!$this[reset($val)]) {
77: $this->_rights = array_unique(array_merge($this->_rights, $val));
78: }
79: }
80: }
81: }
82:
83:
84:
85: 86:
87: public function offsetExists($offset)
88: {
89: return $this[$offset];
90: }
91:
92: 93:
94: public function offsetGet($offset)
95: {
96: return in_array($offset, $this->_rights);
97: }
98:
99: 100:
101: public function offsetSet($offset, $value)
102: {
103: if ($value) {
104: if (!$this[$offset]) {
105: $this->_rights[] = $offset;
106: $this->_normalize();
107: }
108: } elseif ($this[$offset]) {
109: if (isset($this->_virtual[$offset])) {
110: foreach ($this->_virtual[$offset] as $val) {
111: unset($this[$val]);
112: }
113: }
114: unset($this[$offset]);
115: }
116: }
117:
118: 119:
120: public function offsetUnset($offset)
121: {
122: $this->_rights = array_values(array_diff($this->_rights, array($offset)));
123: }
124:
125:
126:
127: 128:
129: public function current()
130: {
131: return current($this->_rights);
132: }
133:
134: 135:
136: public function key()
137: {
138: return key($this->_rights);
139: }
140:
141: 142:
143: public function next()
144: {
145: next($this->_rights);
146: }
147:
148: 149:
150: public function rewind()
151: {
152: reset($this->_rights);
153: }
154:
155: 156:
157: public function valid()
158: {
159: return (key($this->_rights) !== null);
160: }
161:
162:
163:
164: 165:
166: public function serialize()
167: {
168: return json_encode($this->_rights);
169: }
170:
171: 172:
173: public function unserialize($data)
174: {
175: $this->_rights = json_decode($data);
176: }
177:
178: }
179: