1<?php
2/**
3 * Copyright 2006-2017 Horde LLC (http://www.horde.org/)
4 *
5 * See the enclosed file COPYING for license information (LGPL). If you
6 * did not receive this file, see http://www.horde.org/licenses/lgpl21.
7 *
8 * @category Horde
9 * @package  Perms
10 * @author   Gunnar Wrobel <wrobel@pardus.de>
11 * @license  http://www.horde.org/licenses/lgpl21 LGPL 2.1
12 */
13
14/**
15 * Maps Kolab_Storage ACL to the Horde permission system.
16 *
17 * @category Horde
18 * @package  Perms
19 * @author   Gunnar Wrobel <wrobel@pardus.de>
20 * @license  http://www.horde.org/licenses/lgpl21 LGPL 2.1
21 */
22class Horde_Perms_Permission_Kolab_AclIterator implements IteratorAggregate
23{
24    /**
25     * The ACL elements.
26     *
27     * @var array
28     */
29    protected $_acl = array();
30
31    /**
32     * Constructor.
33     *
34     * @param array $acl  The folder ACL as provided by the driver.
35     */
36    public function __construct(array $acl)
37    {
38        foreach ($acl as $user => $rights) {
39            if (substr($user, 0, 6) == 'group:') {
40                $this->_acl[] = new Horde_Perms_Permission_Kolab_Acl_Group(
41                    $rights, substr($user, 6)
42                );
43            } elseif ($user == 'anyone' || $user == 'anonymous'){
44                $class = 'Horde_Perms_Permission_Kolab_Acl_' . Horde_String::ucfirst($user);
45                $this->_acl[] = new $class(
46                    $rights
47                );
48            } else {
49                $this->_acl[] = new Horde_Perms_Permission_Kolab_Acl_User(
50                    $rights, $user
51                );
52            }
53        }
54    }
55
56    public function getIterator()
57    {
58        return new ArrayIterator($this->_acl);
59    }
60}
61