Overview

Packages

  • Imap
    • Client

Classes

  • Horde_Imap_Client
  • Horde_Imap_Client_Auth_DigestMD5
  • Horde_Imap_Client_Base
  • Horde_Imap_Client_Cache
  • Horde_Imap_Client_Data_Acl
  • Horde_Imap_Client_Data_AclCommon
  • Horde_Imap_Client_Data_AclNegative
  • Horde_Imap_Client_Data_AclRights
  • Horde_Imap_Client_Data_Envelope
  • Horde_Imap_Client_Data_Fetch
  • Horde_Imap_Client_Data_Fetch_Pop3
  • Horde_Imap_Client_Data_Thread
  • Horde_Imap_Client_DateTime
  • Horde_Imap_Client_Exception
  • Horde_Imap_Client_Exception_NoSupportExtension
  • Horde_Imap_Client_Fetch_Query
  • Horde_Imap_Client_Ids
  • Horde_Imap_Client_Ids_Pop3
  • Horde_Imap_Client_Mailbox
  • Horde_Imap_Client_Search_Query
  • Horde_Imap_Client_Socket
  • Horde_Imap_Client_Socket_Pop3
  • Horde_Imap_Client_Sort
  • Horde_Imap_Client_Translation
  • Horde_Imap_Client_Utf7imap
  • Horde_Imap_Client_Utils
  • Horde_Imap_Client_Utils_Pop3
  • Overview
  • Package
  • Class
  • Tree
  1: <?php
  2: /**
  3:  * Available ACL rights for a mailbox/identifier (see RFC 2086/4314).
  4:  *
  5:  * Copyright 2011-2012 Horde LLC (http://www.horde.org/)
  6:  *
  7:  * See the enclosed file COPYING for license information (LGPL). If you
  8:  * did not receive this file, see http://www.horde.org/licenses/lgpl21.
  9:  *
 10:  * @author   Michael Slusarz <slusarz@horde.org>
 11:  * @category Horde
 12:  * @license  http://www.horde.org/licenses/lgpl21 LGPL 2.1
 13:  * @package  Imap_Client
 14:  */
 15: class Horde_Imap_Client_Data_AclRights extends Horde_Imap_Client_Data_AclCommon implements ArrayAccess, Iterator, Serializable
 16: {
 17:     /**
 18:      * ACL optional rights.
 19:      *
 20:      * @var array
 21:      */
 22:     protected $_optional = array();
 23: 
 24:     /**
 25:      * ACL required rights.
 26:      *
 27:      * @var array
 28:      */
 29:     protected $_required = array();
 30: 
 31:     /**
 32:      * Constructor.
 33:      *
 34:      * @param array $required  The required rights (see RFC 4314 [2.1]).
 35:      * @param array $optional  The optional rights (see RFC 4314 [2.1]).
 36:      */
 37:     public function __construct(array $required = array(),
 38:                                 array $optional = array())
 39:     {
 40:         $this->_required = $required;
 41: 
 42:         foreach ($optional as $val) {
 43:             foreach (str_split($val) as $right) {
 44:                 $this->_optional[$right] = $val;
 45:             }
 46:         }
 47: 
 48:         $this->_normalize();
 49:     }
 50: 
 51:     /**
 52:      * String representation of the ACL.
 53:      *
 54:      * @return string  String representation (RFC 4314 compliant).
 55:      *
 56:      */
 57:     public function __toString()
 58:     {
 59:         return implode('', array_keys(array_flip(array_merge(array_values($this->_required), array_keys($this->_optional)))));
 60:     }
 61: 
 62:     /**
 63:      * Normalize virtual rights (see RFC 4314 [2.1.1]).
 64:      */
 65:     protected function _normalize()
 66:     {
 67:         /* Clients conforming to RFC 4314 MUST ignore the virtual ACL_CREATE
 68:          * and ACL_DELETE rights. See RFC 4314 [2.1]. However, we still need
 69:          * to handle these rights when dealing with RFC 2086 servers since
 70:          * we are abstracting out use of ACL_CREATE/ACL_DELETE to their
 71:          * component RFC 4314 rights. */
 72:         foreach ($this->_virtual as $key => $val) {
 73:             if (isset($this->_optional[$key])) {
 74:                 unset($this->_optional[$key]);
 75:                 foreach ($val as $val2) {
 76:                     $this->_optional[$val2] = implode('', $val);
 77:                 }
 78:             } elseif (($pos = array_search($key, $this->_required)) !== false) {
 79:                 unset($this->_required[$pos]);
 80:                 $this->_required = array_unique(array_merge($this->_required, $val));
 81:             }
 82:         }
 83:     }
 84: 
 85:     /* ArrayAccess methods. */
 86: 
 87:     /**
 88:      */
 89:     public function offsetExists($offset)
 90:     {
 91:         return (bool)$this[$offset];
 92:     }
 93: 
 94:     /**
 95:      */
 96:     public function offsetGet($offset)
 97:     {
 98:         if (isset($this->_optional[$offset])) {
 99:             return $this->_optional[$offset];
100:         }
101: 
102:         $pos = array_search($offset, $this->_required);
103: 
104:         return ($pos === false)
105:             ? null
106:             : $this->_required[$pos];
107:     }
108: 
109:     /**
110:      */
111:     public function offsetSet($offset, $value)
112:     {
113:         $this->_optional[$offset] = $value;
114:         $this->_normalize();
115:     }
116: 
117:     /**
118:      */
119:     public function offsetUnset($offset)
120:     {
121:         unset($this->_optional[$offset]);
122:         $this->_required = array_values(array_diff($this->_required, array($offset)));
123: 
124:         if (isset($this->_virtual[$offset])) {
125:             foreach ($this->_virtual[$offset] as $val) {
126:                 unset($this[$val]);
127:             }
128:         }
129:     }
130: 
131:     /* Iterator methods. */
132: 
133:     /**
134:      */
135:     public function current()
136:     {
137:         $val = current($this->_required);
138:         return is_null($val)
139:             ? current($this->_optional)
140:             : $val;
141:     }
142: 
143:     /**
144:      */
145:     public function key()
146:     {
147:         $key = key($this->_required);
148:         return is_null($key)
149:             ? key($this->_optional)
150:             : $key;
151:     }
152: 
153:     /**
154:      */
155:     public function next()
156:     {
157:         if (key($this->_required) === null) {
158:             next($this->_optional);
159:         } else {
160:             next($this->_required);
161:         }
162:     }
163: 
164:     /**
165:      */
166:     public function rewind()
167:     {
168:         reset($this->_required);
169:         reset($this->_optional);
170:     }
171: 
172:     /**
173:      */
174:     public function valid()
175:     {
176:         return ((key($this->_required) !== null) ||
177:                 (key($this->_optional) !== null));
178: 
179:     }
180: 
181:     /* Serializable methods. */
182: 
183:     /**
184:      */
185:     public function serialize()
186:     {
187:         return json_encode(array(
188:             $this->_required,
189:             $this->_optional
190:         ));
191:     }
192: 
193:     /**
194:      */
195:     public function unserialize($data)
196:     {
197:         list($this->_required, $this->_optional) = json_decode($data);
198:     }
199: 
200: }
201: 
API documentation generated by ApiGen