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