aboutsummaryrefslogtreecommitdiffstats
path: root/vendor/sabre/dav/tests/Sabre/DAV/Mock/Collection.php
diff options
context:
space:
mode:
Diffstat (limited to 'vendor/sabre/dav/tests/Sabre/DAV/Mock/Collection.php')
-rw-r--r--vendor/sabre/dav/tests/Sabre/DAV/Mock/Collection.php61
1 files changed, 31 insertions, 30 deletions
diff --git a/vendor/sabre/dav/tests/Sabre/DAV/Mock/Collection.php b/vendor/sabre/dav/tests/Sabre/DAV/Mock/Collection.php
index b2613ec9f..6ccab4f66 100644
--- a/vendor/sabre/dav/tests/Sabre/DAV/Mock/Collection.php
+++ b/vendor/sabre/dav/tests/Sabre/DAV/Mock/Collection.php
@@ -15,7 +15,7 @@ use Sabre\DAV;
* * a string, for a file
* * An instance of \Sabre\DAV\INode.
*
- * @copyright Copyright (C) 2007-2014 fruux GmbH. All rights reserved.
+ * @copyright Copyright (C) fruux GmbH (https://fruux.com/)
* @author Evert Pot (http://evertpot.com/)
* @license http://sabre.io/license/ Modified BSD License
*/
@@ -32,10 +32,20 @@ class Collection extends DAV\Collection {
* @param array $children
* @return void
*/
- public function __construct($name, array $children = array(), Collection $parent = null) {
+ function __construct($name, array $children = [], Collection $parent = null) {
$this->name = $name;
- $this->children = $children;
+ foreach ($children as $key => $value) {
+ if (is_string($value)) {
+ $this->children[] = new File($key, $value, $this);
+ } elseif (is_array($value)) {
+ $this->children[] = new self($key, $value, $this);
+ } elseif ($value instanceof \Sabre\DAV\INode) {
+ $this->children[] = $value;
+ } else {
+ throw new \InvalidArgumentException('Unknown value passed in $children');
+ }
+ }
$this->parent = $parent;
}
@@ -47,7 +57,7 @@ class Collection extends DAV\Collection {
*
* @return string
*/
- public function getName() {
+ function getName() {
return $this->name;
@@ -77,12 +87,12 @@ class Collection extends DAV\Collection {
* @param resource|string $data Initial payload
* @return null|string
*/
- public function createFile($name, $data = null) {
+ function createFile($name, $data = null) {
if (is_resource($data)) {
$data = stream_get_contents($data);
}
- $this->children[$name] = $data;
+ $this->children[] = new File($name, $data, $this);
return '"' . md5($data) . '"';
}
@@ -93,9 +103,9 @@ class Collection extends DAV\Collection {
* @param string $name
* @return void
*/
- public function createDirectory($name) {
+ function createDirectory($name) {
- $this->children[$name] = array();
+ $this->children[] = new self($name);
}
@@ -104,22 +114,18 @@ class Collection extends DAV\Collection {
*
* @return \Sabre\DAV\INode[]
*/
- public function getChildren() {
+ function getChildren() {
- $result = array();
- foreach($this->children as $key=>$value) {
+ return $this->children;
- if ($value instanceof DAV\INode) {
- $result[] = $value;
- } elseif (is_array($value)) {
- $result[] = new Collection($key, $value, $this);
- } else {
- $result[] = new File($key, $value, $this);
- }
+ }
- }
+ /**
+ * Adds an already existing node to this collection.
+ */
+ function addNode(\Sabre\DAV\INode $node) {
- return $result;
+ $this->children[] = $node;
}
@@ -129,16 +135,11 @@ class Collection extends DAV\Collection {
* @param string $name
* @return void
*/
- public function deleteChild($name) {
+ function deleteChild($name) {
- foreach($this->children as $key=>$value) {
+ foreach ($this->children as $key => $value) {
- if ($value instanceof DAV\INode) {
- if ($value->getName() == $name) {
- unset($this->children[$key]);
- return;
- }
- } elseif ($key === $name) {
+ if ($value->getName() == $name) {
unset($this->children[$key]);
return;
}
@@ -152,9 +153,9 @@ class Collection extends DAV\Collection {
*
* @return void
*/
- public function delete() {
+ function delete() {
- foreach($this->getChildren() as $child) {
+ foreach ($this->getChildren() as $child) {
$this->deleteChild($child->getName());
}
$this->parent->deleteChild($this->getName());