aboutsummaryrefslogtreecommitdiffstats
path: root/vendor/sabre/dav/lib/DAV/Sync/Plugin.php
diff options
context:
space:
mode:
Diffstat (limited to 'vendor/sabre/dav/lib/DAV/Sync/Plugin.php')
-rw-r--r--vendor/sabre/dav/lib/DAV/Sync/Plugin.php112
1 files changed, 43 insertions, 69 deletions
diff --git a/vendor/sabre/dav/lib/DAV/Sync/Plugin.php b/vendor/sabre/dav/lib/DAV/Sync/Plugin.php
index 8e4b1aa64..f76827fe3 100644
--- a/vendor/sabre/dav/lib/DAV/Sync/Plugin.php
+++ b/vendor/sabre/dav/lib/DAV/Sync/Plugin.php
@@ -1,5 +1,7 @@
<?php
+declare(strict_types=1);
+
namespace Sabre\DAV\Sync;
use Sabre\DAV;
@@ -18,10 +20,10 @@ use Sabre\HTTP\RequestInterface;
* @author Evert Pot (http://evertpot.com/)
* @license http://sabre.io/license/ Modified BSD License
*/
-class Plugin extends DAV\ServerPlugin {
-
+class Plugin extends DAV\ServerPlugin
+{
/**
- * Reference to server object
+ * Reference to server object.
*
* @var DAV\Server
*/
@@ -37,10 +39,9 @@ class Plugin extends DAV\ServerPlugin {
*
* @return string
*/
- function getPluginName() {
-
+ public function getPluginName()
+ {
return 'sync';
-
}
/**
@@ -49,28 +50,25 @@ class Plugin extends DAV\ServerPlugin {
* This is when the plugin registers it's hooks.
*
* @param DAV\Server $server
- * @return void
*/
- function initialize(DAV\Server $server) {
-
+ public function initialize(DAV\Server $server)
+ {
$this->server = $server;
$server->xml->elementMap['{DAV:}sync-collection'] = 'Sabre\\DAV\\Xml\\Request\\SyncCollectionReport';
$self = $this;
- $server->on('report', function($reportName, $dom, $uri) use ($self) {
-
- if ($reportName === '{DAV:}sync-collection') {
+ $server->on('report', function ($reportName, $dom, $uri) use ($self) {
+ if ('{DAV:}sync-collection' === $reportName) {
$this->server->transactionType = 'report-sync-collection';
$self->syncCollection($uri, $dom);
+
return false;
}
-
});
- $server->on('propFind', [$this, 'propFind']);
+ $server->on('propFind', [$this, 'propFind']);
$server->on('validateTokens', [$this, 'validateTokens']);
-
}
/**
@@ -81,10 +79,11 @@ class Plugin extends DAV\ServerPlugin {
* implement them
*
* @param string $uri
+ *
* @return array
*/
- function getSupportedReportSet($uri) {
-
+ public function getSupportedReportSet($uri)
+ {
$node = $this->server->tree->getNodeForPath($uri);
if ($node instanceof ISyncCollection && $node->getSyncToken()) {
return [
@@ -93,19 +92,16 @@ class Plugin extends DAV\ServerPlugin {
}
return [];
-
}
-
/**
* This method handles the {DAV:}sync-collection HTTP REPORT.
*
- * @param string $uri
+ * @param string $uri
* @param SyncCollectionReport $report
- * @return void
*/
- function syncCollection($uri, SyncCollectionReport $report) {
-
+ public function syncCollection($uri, SyncCollectionReport $report)
+ {
// Getting the data
$node = $this->server->tree->getNodeForPath($uri);
if (!$node instanceof ISyncCollection) {
@@ -119,19 +115,16 @@ class Plugin extends DAV\ServerPlugin {
$syncToken = $report->syncToken;
if (!is_null($syncToken)) {
// Sync-token must start with our prefix
- if (substr($syncToken, 0, strlen(self::SYNCTOKEN_PREFIX)) !== self::SYNCTOKEN_PREFIX) {
+ if (self::SYNCTOKEN_PREFIX !== substr($syncToken, 0, strlen(self::SYNCTOKEN_PREFIX))) {
throw new DAV\Exception\InvalidSyncToken('Invalid or unknown sync token');
}
$syncToken = substr($syncToken, strlen(self::SYNCTOKEN_PREFIX));
-
}
$changeInfo = $node->getChanges($syncToken, $report->syncLevel, $report->limit);
if (is_null($changeInfo)) {
-
throw new DAV\Exception\InvalidSyncToken('Invalid or unknown sync token');
-
}
// Encoding the response
@@ -143,7 +136,6 @@ class Plugin extends DAV\ServerPlugin {
$changeInfo['deleted'],
$report->properties
);
-
}
/**
@@ -151,50 +143,41 @@ class Plugin extends DAV\ServerPlugin {
*
* @param string $syncToken
* @param string $collectionUrl
- * @param array $added
- * @param array $modified
- * @param array $deleted
- * @param array $properties
- * @return void
+ * @param array $added
+ * @param array $modified
+ * @param array $deleted
+ * @param array $properties
*/
- protected function sendSyncCollectionResponse($syncToken, $collectionUrl, array $added, array $modified, array $deleted, array $properties) {
-
-
+ protected function sendSyncCollectionResponse($syncToken, $collectionUrl, array $added, array $modified, array $deleted, array $properties)
+ {
$fullPaths = [];
// Pre-fetching children, if this is possible.
foreach (array_merge($added, $modified) as $item) {
- $fullPath = $collectionUrl . '/' . $item;
+ $fullPath = $collectionUrl.'/'.$item;
$fullPaths[] = $fullPath;
}
$responses = [];
foreach ($this->server->getPropertiesForMultiplePaths($fullPaths, $properties) as $fullPath => $props) {
-
// The 'Property_Response' class is responsible for generating a
// single {DAV:}response xml element.
$responses[] = new DAV\Xml\Element\Response($fullPath, $props);
-
}
-
-
// Deleted items also show up as 'responses'. They have no properties,
// and a single {DAV:}status element set as 'HTTP/1.1 404 Not Found'.
foreach ($deleted as $item) {
-
- $fullPath = $collectionUrl . '/' . $item;
+ $fullPath = $collectionUrl.'/'.$item;
$responses[] = new DAV\Xml\Element\Response($fullPath, [], 404);
-
}
- $multiStatus = new DAV\Xml\Response\MultiStatus($responses, self::SYNCTOKEN_PREFIX . $syncToken);
+ $multiStatus = new DAV\Xml\Response\MultiStatus($responses, self::SYNCTOKEN_PREFIX.$syncToken);
$this->server->httpResponse->setStatus(207);
$this->server->httpResponse->setHeader('Content-Type', 'application/xml; charset=utf-8');
$this->server->httpResponse->setBody(
$this->server->xml->write('{DAV:}multistatus', $multiStatus, $this->server->getBaseUri())
);
-
}
/**
@@ -202,18 +185,17 @@ class Plugin extends DAV\ServerPlugin {
* We intercept this to see if we must return a {DAV:}sync-token.
*
* @param DAV\PropFind $propFind
- * @param DAV\INode $node
- * @return void
+ * @param DAV\INode $node
*/
- function propFind(DAV\PropFind $propFind, DAV\INode $node) {
-
- $propFind->handle('{DAV:}sync-token', function() use ($node) {
+ public function propFind(DAV\PropFind $propFind, DAV\INode $node)
+ {
+ $propFind->handle('{DAV:}sync-token', function () use ($node) {
if (!$node instanceof ISyncCollection || !$token = $node->getSyncToken()) {
return;
}
- return self::SYNCTOKEN_PREFIX . $token;
- });
+ return self::SYNCTOKEN_PREFIX.$token;
+ });
}
/**
@@ -223,17 +205,14 @@ class Plugin extends DAV\ServerPlugin {
* in the If: header, and check if they are valid.
*
* @param RequestInterface $request
- * @param array $conditions
- * @return void
+ * @param array $conditions
*/
- function validateTokens(RequestInterface $request, &$conditions) {
-
+ public function validateTokens(RequestInterface $request, &$conditions)
+ {
foreach ($conditions as $kk => $condition) {
-
foreach ($condition['tokens'] as $ii => $token) {
-
// Sync-tokens must always start with our designated prefix.
- if (substr($token['token'], 0, strlen(self::SYNCTOKEN_PREFIX)) !== self::SYNCTOKEN_PREFIX) {
+ if (self::SYNCTOKEN_PREFIX !== substr($token['token'], 0, strlen(self::SYNCTOKEN_PREFIX))) {
continue;
}
@@ -246,11 +225,8 @@ class Plugin extends DAV\ServerPlugin {
) {
$conditions[$kk]['tokens'][$ii]['validToken'] = true;
}
-
}
-
}
-
}
/**
@@ -264,14 +240,12 @@ class Plugin extends DAV\ServerPlugin {
*
* @return array
*/
- function getPluginInfo() {
-
+ public function getPluginInfo()
+ {
return [
- 'name' => $this->getPluginName(),
+ 'name' => $this->getPluginName(),
'description' => 'Adds support for WebDAV Collection Sync (rfc6578)',
- 'link' => 'http://sabre.io/dav/sync/',
+ 'link' => 'http://sabre.io/dav/sync/',
];
-
}
-
}