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:  * ACL rights for a mailbox (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_Acl extends Horde_Imap_Client_Data_AclCommon implements ArrayAccess, Iterator, Serializable
 16: {
 17:     /**
 18:      * ACL rights.
 19:      *
 20:      * @var array
 21:      */
 22:     protected $_rights;
 23: 
 24:     /**
 25:      * Constructor.
 26:      *
 27:      * @var string $rights  The rights (see RFC 4314 [2.1]).
 28:      */
 29:     public function __construct($rights = '')
 30:     {
 31:         $this->_rights = str_split($rights);
 32:         $this->_normalize();
 33:     }
 34: 
 35:     /**
 36:      * String representation of the ACL.
 37:      *
 38:      * @return string  String representation (RFC 4314 compliant).
 39:      */
 40:     public function __toString()
 41:     {
 42:         return implode('', $this->_rights);
 43:     }
 44: 
 45:     /**
 46:      * Computes the difference to another rights string.
 47:      * Virtual rights are ignored.
 48:      *
 49:      * @param string $rights  The rights to compute against.
 50:      *
 51:      * @return array  Two element array: added and removed.
 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:      * Normalize virtual rights (see RFC 4314 [2.1.1]).
 65:      */
 66:     protected function _normalize()
 67:     {
 68:         /* Clients conforming to RFC 4314 MUST ignore the virtual ACL_CREATE
 69:          * and ACL_DELETE rights. See RFC 4314 [2.1]. However, we still need
 70:          * to handle these rights when dealing with RFC 2086 servers since
 71:          * we are abstracting out use of ACL_CREATE/ACL_DELETE to their
 72:          * component RFC 4314 rights. */
 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:     /* ArrayAccess methods. */
 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:     /* Iterator methods. */
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:     /* Serializable methods. */
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: 
API documentation generated by ApiGen