]> git.mxchange.org Git - friendica-addons.git/blob - dav/SabreDAV/lib/Sabre/DAVACL/AbstractPrincipalCollection.php
Merge branch 'master' of git://github.com/friendica/friendica-addons
[friendica-addons.git] / dav / SabreDAV / lib / Sabre / DAVACL / AbstractPrincipalCollection.php
1 <?php
2
3 /**
4  * Principals Collection
5  *
6  * This is a helper class that easily allows you to create a collection that
7  * has a childnode for every principal.
8  *
9  * To use this class, simply implement the getChildForPrincipal method.
10  *
11  * @package Sabre
12  * @subpackage DAVACL
13  * @copyright Copyright (C) 2007-2012 Rooftop Solutions. All rights reserved.
14  * @author Evert Pot (http://www.rooftopsolutions.nl/)
15  * @license http://code.google.com/p/sabredav/wiki/License Modified BSD License
16  */
17 abstract class Sabre_DAVACL_AbstractPrincipalCollection extends Sabre_DAV_Collection  {
18
19     /**
20      * Node or 'directory' name.
21      *
22      * @var string
23      */
24     protected $path;
25
26     /**
27      * Principal backend
28      *
29      * @var Sabre_DAVACL_IPrincipalBackend
30      */
31     protected $principalBackend;
32
33     /**
34      * If this value is set to true, it effectively disables listing of users
35      * it still allows user to find other users if they have an exact url.
36      *
37      * @var bool
38      */
39     public $disableListing = false;
40
41     /**
42      * Creates the object
43      *
44      * This object must be passed the principal backend. This object will
45      * filter all principals from a specified prefix ($principalPrefix). The
46      * default is 'principals', if your principals are stored in a different
47      * collection, override $principalPrefix
48      *
49      *
50      * @param Sabre_DAVACL_IPrincipalBackend $principalBackend
51      * @param string $principalPrefix
52      */
53     public function __construct(Sabre_DAVACL_IPrincipalBackend $principalBackend, $principalPrefix = 'principals') {
54
55         $this->principalPrefix = $principalPrefix;
56         $this->principalBackend = $principalBackend;
57
58     }
59
60     /**
61      * This method returns a node for a principal.
62      *
63      * The passed array contains principal information, and is guaranteed to
64      * at least contain a uri item. Other properties may or may not be
65      * supplied by the authentication backend.
66      *
67      * @param array $principalInfo
68      * @return Sabre_DAVACL_IPrincipal
69      */
70     abstract function getChildForPrincipal(array $principalInfo);
71
72     /**
73      * Returns the name of this collection.
74      *
75      * @return string
76      */
77     public function getName() {
78
79         list(,$name) = Sabre_DAV_URLUtil::splitPath($this->principalPrefix);
80         return $name;
81
82     }
83
84     /**
85      * Return the list of users
86      *
87      * @return array
88      */
89     public function getChildren() {
90
91         if ($this->disableListing)
92             throw new Sabre_DAV_Exception_MethodNotAllowed('Listing members of this collection is disabled');
93
94         $children = array();
95         foreach($this->principalBackend->getPrincipalsByPrefix($this->principalPrefix) as $principalInfo) {
96
97             $children[] = $this->getChildForPrincipal($principalInfo);
98
99
100         }
101         return $children;
102
103     }
104
105     /**
106      * Returns a child object, by its name.
107      *
108      * @param string $name
109      * @throws Sabre_DAV_Exception_NotFound
110      * @return Sabre_DAVACL_IPrincipal
111      */
112     public function getChild($name) {
113
114         $principalInfo = $this->principalBackend->getPrincipalByPath($this->principalPrefix . '/' . $name);
115         if (!$principalInfo) throw new Sabre_DAV_Exception_NotFound('Principal with name ' . $name . ' not found');
116         return $this->getChildForPrincipal($principalInfo);
117
118     }
119
120     /**
121      * This method is used to search for principals matching a set of
122      * properties.
123      *
124      * This search is specifically used by RFC3744's principal-property-search
125      * REPORT. You should at least allow searching on
126      * http://sabredav.org/ns}email-address.
127      *
128      * The actual search should be a unicode-non-case-sensitive search. The
129      * keys in searchProperties are the WebDAV property names, while the values
130      * are the property values to search on.
131      *
132      * If multiple properties are being searched on, the search should be
133      * AND'ed.
134      *
135      * This method should simply return a list of 'child names', which may be
136      * used to call $this->getChild in the future.
137      *
138      * @param array $searchProperties
139      * @return array
140      */
141     public function searchPrincipals(array $searchProperties) {
142
143         $result = $this->principalBackend->searchPrincipals($this->principalPrefix, $searchProperties);
144         $r = array();
145
146         foreach($result as $row) {
147             list(, $r[]) = Sabre_DAV_URLUtil::splitPath($row);
148         }
149
150         return $r;
151
152     }
153
154 }