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.
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
15 class Sabre_DAV_SimpleCollection extends Sabre_DAV_Collection {
22 protected $children = array();
25 * Name of this resource
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
38 * @param array $children
40 public function __construct($name,array $children = array()) {
43 foreach($children as $child) {
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);
53 * Adds a new childnode to this collection
55 * @param Sabre_DAV_INode $child
58 public function addChild(Sabre_DAV_INode $child) {
60 $this->children[$child->getName()] = $child;
65 * Returns the name of the collection
69 public function getName() {
76 * Returns a child object, by its name.
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
81 * This method must throw Sabre_DAV_Exception_NotFound if the node does not
85 * @throws Sabre_DAV_Exception_NotFound
86 * @return Sabre_DAV_INode
88 public function getChild($name) {
90 if (isset($this->children[$name])) return $this->children[$name];
91 throw new Sabre_DAV_Exception_NotFound('File not found: ' . $name . ' in \'' . $this->getName() . '\'');
96 * Returns a list of children for this collection
100 public function getChildren() {
102 return array_values($this->children);