1: <?php
2: /**
3: * Provides common methods shared in all ACL classes (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_AclCommon
16: {
17: /* Constants for getString(). */
18: const RFC_2086 = 1;
19: const RFC_4314 = 2;
20:
21: /**
22: * List of virtual rights (RFC 4314 [2.1.1]).
23: *
24: * @var array
25: */
26: protected $_virtual = array(
27: Horde_Imap_Client::ACL_CREATE => array(
28: Horde_Imap_Client::ACL_CREATEMBOX,
29: Horde_Imap_Client::ACL_DELETEMBOX
30: ),
31: Horde_Imap_Client::ACL_DELETE => array(
32: Horde_Imap_Client::ACL_DELETEMSGS,
33: // Don't put this first - we do checks on the existence of the
34: // first element in this array to determine the RFC type, and this
35: // is duplicate of right contained in ACL_CREATE.
36: Horde_Imap_Client::ACL_DELETEMBOX,
37: Horde_Imap_Client::ACL_EXPUNGE
38: )
39: );
40:
41: /**
42: * Returns the raw string to use in IMAP server calls.
43: *
44: * @param integer $type The RFC type to use (RFC_* constant).
45: *
46: * @return string The string representation of the ACL.
47: */
48: public function getString($type = self::RFC_4314)
49: {
50: $acl = strval($this);
51:
52: if ($type == self::RFC_2086) {
53: foreach ($this->_virtual as $key => $val) {
54: $acl = str_replace($val, '', $acl, $count);
55: if ($count) {
56: $acl .= $key;
57: }
58: }
59: }
60:
61: return $acl;
62: }
63:
64: }
65: