ILIAS  release_5-4 Revision v5.4.26-12-gabc799a52e6
Sabre\DAV\Sync\MockSyncCollection Class Reference

This mocks a ISyncCollection, for unittesting. More...

+ Inheritance diagram for Sabre\DAV\Sync\MockSyncCollection:
+ Collaboration diagram for Sabre\DAV\Sync\MockSyncCollection:

Public Member Functions

 getSyncToken ()
 This method returns the current sync-token for this collection. More...
 
 addChange (array $added, array $modified, array $deleted)
 
 getChanges ($syncToken, $syncLevel, $limit=null)
 The getChanges method returns all the changes that have happened, since the specified syncToken and the current collection. More...
 
- Public Member Functions inherited from Sabre\DAV\SimpleCollection
 __construct ($name, array $children=[])
 Creates this node. More...
 
 addChild (INode $child)
 Adds a new childnode to this collection. More...
 
 getName ()
 Returns the name of the collection. More...
 
 getChild ($name)
 Returns a child object, by its name. More...
 
 getChildren ()
 Returns a list of children for this collection. 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...
 

Data Fields

 $changeLog = []
 
 $token = null
 

Additional Inherited Members

- Protected Attributes inherited from Sabre\DAV\SimpleCollection
 $children = []
 
 $name
 

Detailed Description

This mocks a ISyncCollection, for unittesting.

This object behaves the same as SimpleCollection. Call addChange to update the 'changelog' that this class uses for the collection.

Author
Evert Pot (http://evertpot.com/) http://sabre.io/license/ Modified BSD License

Definition at line 17 of file MockSyncCollection.php.

Member Function Documentation

◆ addChange()

Sabre\DAV\Sync\MockSyncCollection::addChange ( array  $added,
array  $modified,
array  $deleted 
)

Definition at line 39 of file MockSyncCollection.php.

References Sabre\DAV\Sync\MockSyncCollection\$token.

39  {
40 
41  $this->token++;
42  $this->changeLog[$this->token] = [
43  'added' => $added,
44  'modified' => $modified,
45  'deleted' => $deleted,
46  ];
47 
48  }

◆ getChanges()

Sabre\DAV\Sync\MockSyncCollection::getChanges (   $syncToken,
  $syncLevel,
  $limit = null 
)

The getChanges method returns all the changes that have happened, since the specified syncToken and the current collection.

This function should return an array, such as the following:

array( 'syncToken' => 'The current synctoken', 'modified' => array( 'new.txt', ), 'deleted' => array( 'foo.php.bak', 'old.txt' ) );

The syncToken property should reflect the current syncToken of the collection, as reported getSyncToken(). This is needed here too, to ensure the operation is atomic.

If the syncToken is specified as null, this is an initial sync, and all members should be reported.

The modified property is an array of nodenames that have changed since the last token.

The deleted property is an array with nodenames, that have been deleted from collection.

The second argument is basically the 'depth' of the report. If it's 1, you only have to report changes that happened only directly in immediate descendants. If it's 2, it should also include changes from the nodes below the child collections. (grandchildren)

The third (optional) argument allows a client to specify how many results should be returned at most. If the limit is not specified, it should be treated as infinite.

If the limit (infinite or not) is higher than you're willing to return, you should throw a Sabre() exception.

If the syncToken is expired (due to data cleanup) or unknown, you must return null.

The limit is 'suggestive'. You are free to ignore it.

Parameters
string$syncToken
int$syncLevel
int$limit
Returns
array

Implements Sabre\DAV\Sync\ISyncCollection.

Definition at line 102 of file MockSyncCollection.php.

References Sabre\DAV\Sync\MockSyncCollection\$token, Sabre\DAV\SimpleCollection\getChildren(), and Sabre\DAV\Sync\MockSyncCollection\getSyncToken().

102  {
103 
104  // This is an initial sync
105  if (is_null($syncToken)) {
106  return [
107  'added' => array_map(
108  function($item) {
109  return $item->getName();
110  }, $this->getChildren()
111  ),
112  'modified' => [],
113  'deleted' => [],
114  'syncToken' => $this->getSyncToken(),
115  ];
116  }
117 
118  if (!is_int($syncToken) && !ctype_digit($syncToken)) {
119 
120  return null;
121 
122  }
123  if (is_null($this->token)) return null;
124 
125  $added = [];
126  $modified = [];
127  $deleted = [];
128 
129  foreach ($this->changeLog as $token => $change) {
130 
131  if ($token > $syncToken) {
132 
133  $added = array_merge($added, $change['added']);
134  $modified = array_merge($modified, $change['modified']);
135  $deleted = array_merge($deleted, $change['deleted']);
136 
137  if ($limit) {
138  // If there's a limit, we may need to cut things off.
139  // This alghorithm is weird and stupid, but it works.
140  $left = $limit - (count($modified) + count($deleted));
141  if ($left > 0) continue;
142  if ($left === 0) break;
143  if ($left < 0) {
144  $modified = array_slice($modified, 0, $left);
145  }
146  $left = $limit - (count($modified) + count($deleted));
147  if ($left === 0) break;
148  if ($left < 0) {
149  $deleted = array_slice($deleted, 0, $left);
150  }
151  break;
152 
153  }
154 
155  }
156 
157  }
158 
159  return [
160  'syncToken' => $this->token,
161  'added' => $added,
162  'modified' => $modified,
163  'deleted' => $deleted,
164  ];
165 
166  }
getChildren()
Returns a list of children for this collection.
getSyncToken()
This method returns the current sync-token for this collection.
+ Here is the call graph for this function:

◆ getSyncToken()

Sabre\DAV\Sync\MockSyncCollection::getSyncToken ( )

This method returns the current sync-token for this collection.

This can be any string.

If null is returned from this function, the plugin assumes there's no sync information available.

Returns
string|null

Implements Sabre\DAV\Sync\ISyncCollection.

Definition at line 32 of file MockSyncCollection.php.

References Sabre\DAV\Sync\MockSyncCollection\$token.

Referenced by Sabre\DAV\Sync\MockSyncCollection\getChanges().

32  {
33 
34  // Will be 'null' in the first round, and will increment ever after.
35  return $this->token;
36 
37  }
+ Here is the caller graph for this function:

Field Documentation

◆ $changeLog

Sabre\DAV\Sync\MockSyncCollection::$changeLog = []

Definition at line 19 of file MockSyncCollection.php.

◆ $token


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