]> git.mxchange.org Git - friendica-addons.git/blob - dav/SabreDAV/lib/Sabre/DAV/SimpleCollection.php
Merge branch '3.6-release'
[friendica-addons.git] / dav / SabreDAV / lib / Sabre / DAV / SimpleCollection.php
1 <?php
2
3 /**
4  * SimpleCollection
5  *
6  * The SimpleCollection is used to quickly setup static directory structures.
7  * Just create the object with a proper name, and add children to use it.
8  *
9  * @package Sabre
10  * @subpackage DAV
11  * @copyright Copyright (C) 2007-2012 Rooftop Solutions. All rights reserved.
12  * @author Evert Pot (http://www.rooftopsolutions.nl/)
13  * @license http://code.google.com/p/sabredav/wiki/License Modified BSD License
14  */
15 class Sabre_DAV_SimpleCollection extends Sabre_DAV_Collection {
16
17     /**
18      * List of childnodes
19      *
20      * @var array
21      */
22     protected $children = array();
23
24     /**
25      * Name of this resource
26      *
27      * @var string
28      */
29     protected $name;
30
31     /**
32      * Creates this node
33      *
34      * The name of the node must be passed, child nodes can also be passed.
35      * This nodes must be instances of Sabre_DAV_INode
36      *
37      * @param string $name
38      * @param array $children
39      */
40     public function __construct($name,array $children = array()) {
41
42         $this->name = $name;
43         foreach($children as $child) {
44
45             if (!($child instanceof Sabre_DAV_INode)) throw new Sabre_DAV_Exception('Only instances of Sabre_DAV_INode are allowed to be passed in the children argument');
46             $this->addChild($child);
47
48         }
49
50     }
51
52     /**
53      * Adds a new childnode to this collection
54      *
55      * @param Sabre_DAV_INode $child
56      * @return void
57      */
58     public function addChild(Sabre_DAV_INode $child) {
59
60         $this->children[$child->getName()] = $child;
61
62     }
63
64     /**
65      * Returns the name of the collection
66      *
67      * @return string
68      */
69     public function getName() {
70
71         return $this->name;
72
73     }
74
75     /**
76      * Returns a child object, by its name.
77      *
78      * This method makes use of the getChildren method to grab all the child nodes, and compares the name.
79      * Generally its wise to override this, as this can usually be optimized
80      *
81      * This method must throw Sabre_DAV_Exception_NotFound if the node does not
82      * exist.
83      *
84      * @param string $name
85      * @throws Sabre_DAV_Exception_NotFound
86      * @return Sabre_DAV_INode
87      */
88     public function getChild($name) {
89
90         if (isset($this->children[$name])) return $this->children[$name];
91         throw new Sabre_DAV_Exception_NotFound('File not found: ' . $name . ' in \'' . $this->getName() . '\'');
92
93     }
94
95     /**
96      * Returns a list of children for this collection
97      *
98      * @return array
99      */
100     public function getChildren() {
101
102         return array_values($this->children);
103
104     }
105
106
107 }
108