ILIAS  release_5-4 Revision v5.4.26-12-gabc799a52e6
Sabre\DAV\Mock\Collection Class Reference

Mock Collection. More...

+ Inheritance diagram for Sabre\DAV\Mock\Collection:
+ Collaboration diagram for Sabre\DAV\Mock\Collection:

Public Member Functions

 __construct ($name, array $children=[], Collection $parent=null)
 Creates the object. More...
 
 getName ()
 Returns the name of the node. More...
 
 createFile ($name, $data=null)
 Creates a new file in the directory. More...
 
 createDirectory ($name)
 Creates a new subdirectory. More...
 
 getChildren ()
 Returns an array with all the child nodes. More...
 
 addNode (\Sabre\DAV\INode $node)
 Adds an already existing node to this collection. More...
 
 deleteChild ($name)
 Removes a childnode from this node. More...
 
 delete ()
 Deletes this collection and all its children,. More...
 
- Public Member Functions inherited from Sabre\DAV\Collection
 getChild ($name)
 Returns a child object, by its name. More...
 
 childExists ($name)
 Checks is a child-node exists. More...
 
 createFile ($name, $data=null)
 Creates a new file in the directory. More...
 
 createDirectory ($name)
 Creates a new subdirectory. More...
 
- Public Member Functions inherited from Sabre\DAV\Node
 getLastModified ()
 Returns the last modification time as a unix timestamp. More...
 
 delete ()
 Deletes the current node. More...
 
 setName ($name)
 Renames the node. More...
 

Protected Attributes

 $name
 
 $children
 
 $parent
 

Detailed Description

Mock Collection.

This collection quickly allows you to create trees of nodes. Children are specified as an array.

Every key a filename, every array value is either:

  • an array, for a sub-collection
  • a string, for a file
  • An instance of .
Author
Evert Pot (http://evertpot.com/) http://sabre.io/license/ Modified BSD License

Definition at line 22 of file Collection.php.

Constructor & Destructor Documentation

◆ __construct()

Sabre\DAV\Mock\Collection::__construct (   $name,
array  $children = [],
Collection  $parent = null 
)

Creates the object.

Parameters
string$name
array$children
Collection$parent
Returns
void

Definition at line 36 of file Collection.php.

References Sabre\DAV\Mock\Collection\$children, $key, $name, and Sabre\DAV\Mock\Collection\$parent.

36  {
37 
38  $this->name = $name;
39  foreach ($children as $key => $value) {
40  if (is_string($value)) {
41  $this->children[] = new File($key, $value, $this);
42  } elseif (is_array($value)) {
43  $this->children[] = new self($key, $value, $this);
44  } elseif ($value instanceof \Sabre\DAV\INode) {
45  $this->children[] = $value;
46  } else {
47  throw new \InvalidArgumentException('Unknown value passed in $children');
48  }
49  }
50  $this->parent = $parent;
51 
52  }
$key
Definition: croninfo.php:18

Member Function Documentation

◆ addNode()

Sabre\DAV\Mock\Collection::addNode ( \Sabre\DAV\INode  $node)

Adds an already existing node to this collection.

Parameters
\Sabre\DAV\INode$node

Definition at line 129 of file Collection.php.

129  {
130 
131  $this->children[] = $node;
132 
133  }

◆ createDirectory()

Sabre\DAV\Mock\Collection::createDirectory (   $name)

Creates a new subdirectory.

Parameters
string$name
Returns
void

Implements Sabre\DAV\ICollection.

Definition at line 107 of file Collection.php.

References $name.

107  {
108 
109  $this->children[] = new self($name);
110 
111  }

◆ createFile()

Sabre\DAV\Mock\Collection::createFile (   $name,
  $data = null 
)

Creates a new file in the directory.

Data will either be supplied as a stream resource, or in certain cases as a string. Keep in mind that you may have to support either.

After successful creation of the file, you may choose to return the ETag of the new file here.

The returned ETag must be surrounded by double-quotes (The quotes should be part of the actual string).

If you cannot accurately determine the ETag, you should not return it. If you don't store the file exactly as-is (you're transforming it somehow) you should also not return an ETag.

This means that if a subsequent GET to this new file does not exactly return the same contents of what was submitted here, you are strongly recommended to omit the ETag.

Parameters
string$nameName of the file
resource | string$dataInitial payload
Returns
null|string

Implements Sabre\DAV\ICollection.

Definition at line 91 of file Collection.php.

References $data, and $name.

91  {
92 
93  if (is_resource($data)) {
94  $data = stream_get_contents($data);
95  }
96  $this->children[] = new File($name, $data, $this);
97  return '"' . md5($data) . '"';
98 
99  }
$data
Definition: bench.php:6

◆ delete()

Sabre\DAV\Mock\Collection::delete ( )

Deletes this collection and all its children,.

Returns
void

Implements Sabre\DAV\INode.

Definition at line 159 of file Collection.php.

References Sabre\DAV\Mock\Collection\deleteChild(), Sabre\DAV\ICollection\getChildren(), and Sabre\DAV\INode\getName().

159  {
160 
161  foreach ($this->getChildren() as $child) {
162  $this->deleteChild($child->getName());
163  }
164  $this->parent->deleteChild($this->getName());
165 
166  }
getName()
Returns the name of the node.
getChildren()
Returns an array with all the child nodes.
deleteChild($name)
Removes a childnode from this node.
Definition: Collection.php:141
+ Here is the call graph for this function:

◆ deleteChild()

Sabre\DAV\Mock\Collection::deleteChild (   $name)

Removes a childnode from this node.

Parameters
string$name
Returns
void

Definition at line 141 of file Collection.php.

References $key, and $name.

Referenced by Sabre\DAV\Mock\Collection\delete().

141  {
142 
143  foreach ($this->children as $key => $value) {
144 
145  if ($value->getName() == $name) {
146  unset($this->children[$key]);
147  return;
148  }
149 
150  }
151 
152  }
$key
Definition: croninfo.php:18
+ Here is the caller graph for this function:

◆ getChildren()

Sabre\DAV\Mock\Collection::getChildren ( )

Returns an array with all the child nodes.

Returns
[]

Implements Sabre\DAV\ICollection.

Definition at line 118 of file Collection.php.

118  {
119 
120  return $this->children;
121 
122  }

◆ getName()

Sabre\DAV\Mock\Collection::getName ( )

Returns the name of the node.

This is used to generate the url.

Returns
string

Implements Sabre\DAV\INode.

Definition at line 61 of file Collection.php.

References $name.

61  {
62 
63  return $this->name;
64 
65  }

Field Documentation

◆ $children

Sabre\DAV\Mock\Collection::$children
protected

Definition at line 25 of file Collection.php.

Referenced by Sabre\DAV\Mock\Collection\__construct().

◆ $name

Sabre\DAV\Mock\Collection::$name
protected

Definition at line 24 of file Collection.php.

◆ $parent

Sabre\DAV\Mock\Collection::$parent
protected

Definition at line 26 of file Collection.php.

Referenced by Sabre\DAV\Mock\Collection\__construct().


The documentation for this class was generated from the following file: