aboutsummaryrefslogtreecommitdiffstats
path: root/vendor/sabre/dav/lib/DAV/TemporaryFileFilterPlugin.php
diff options
context:
space:
mode:
Diffstat (limited to 'vendor/sabre/dav/lib/DAV/TemporaryFileFilterPlugin.php')
-rw-r--r--vendor/sabre/dav/lib/DAV/TemporaryFileFilterPlugin.php161
1 files changed, 88 insertions, 73 deletions
diff --git a/vendor/sabre/dav/lib/DAV/TemporaryFileFilterPlugin.php b/vendor/sabre/dav/lib/DAV/TemporaryFileFilterPlugin.php
index 7b453d105..6cf772f44 100644
--- a/vendor/sabre/dav/lib/DAV/TemporaryFileFilterPlugin.php
+++ b/vendor/sabre/dav/lib/DAV/TemporaryFileFilterPlugin.php
@@ -1,13 +1,15 @@
<?php
+declare(strict_types=1);
+
namespace Sabre\DAV;
use Sabre\HTTP\RequestInterface;
use Sabre\HTTP\ResponseInterface;
-use Sabre\HTTP\URLUtil;
+use Sabre\Uri;
/**
- * Temporary File Filter Plugin
+ * Temporary File Filter Plugin.
*
* The purpose of this filter is to intercept some of the garbage files
* operation systems and applications tend to generate when mounting
@@ -30,8 +32,8 @@ use Sabre\HTTP\URLUtil;
* @author Evert Pot (http://evertpot.com/)
* @license http://sabre.io/license/ Modified BSD License
*/
-class TemporaryFileFilterPlugin extends ServerPlugin {
-
+class TemporaryFileFilterPlugin extends ServerPlugin
+{
/**
* This is the list of patterns we intercept.
* If new patterns are added, they must be valid patterns for preg_match.
@@ -49,7 +51,7 @@ class TemporaryFileFilterPlugin extends ServerPlugin {
];
/**
- * A reference to the main Server class
+ * A reference to the main Server class.
*
* @var \Sabre\DAV\Server
*/
@@ -72,58 +74,61 @@ class TemporaryFileFilterPlugin extends ServerPlugin {
*
* @param string|null $dataDir
*/
- function __construct($dataDir = null) {
-
- if (!$dataDir) $dataDir = ini_get('session.save_path') . '/sabredav/';
- if (!is_dir($dataDir)) mkdir($dataDir);
+ public function __construct($dataDir = null)
+ {
+ if (!$dataDir) {
+ $dataDir = ini_get('session.save_path').'/sabredav/';
+ }
+ if (!is_dir($dataDir)) {
+ mkdir($dataDir);
+ }
$this->dataDir = $dataDir;
-
}
/**
- * Initialize the plugin
+ * Initialize the plugin.
*
* This is called automatically be the Server class after this plugin is
* added with Sabre\DAV\Server::addPlugin()
*
* @param Server $server
- * @return void
*/
- function initialize(Server $server) {
-
+ public function initialize(Server $server)
+ {
$this->server = $server;
- $server->on('beforeMethod', [$this, 'beforeMethod']);
+ $server->on('beforeMethod:*', [$this, 'beforeMethod']);
$server->on('beforeCreateFile', [$this, 'beforeCreateFile']);
-
}
/**
- * This method is called before any HTTP method handler
+ * This method is called before any HTTP method handler.
*
* This method intercepts any GET, DELETE, PUT and PROPFIND calls to
* filenames that are known to match the 'temporary file' regex.
*
- * @param RequestInterface $request
+ * @param RequestInterface $request
* @param ResponseInterface $response
+ *
* @return bool
*/
- function beforeMethod(RequestInterface $request, ResponseInterface $response) {
-
- if (!$tempLocation = $this->isTempFile($request->getPath()))
+ public function beforeMethod(RequestInterface $request, ResponseInterface $response)
+ {
+ if (!$tempLocation = $this->isTempFile($request->getPath())) {
return;
+ }
switch ($request->getMethod()) {
- case 'GET' :
+ case 'GET':
return $this->httpGet($request, $response, $tempLocation);
- case 'PUT' :
+ case 'PUT':
return $this->httpPut($request, $response, $tempLocation);
- case 'PROPFIND' :
+ case 'PROPFIND':
return $this->httpPropfind($request, $response, $tempLocation);
- case 'DELETE' :
+ case 'DELETE':
return $this->httpDelete($request, $response, $tempLocation);
}
- return;
+ return;
}
/**
@@ -132,24 +137,25 @@ class TemporaryFileFilterPlugin extends ServerPlugin {
* This is used to deal with HTTP LOCK requests which create a new
* file.
*
- * @param string $uri
- * @param resource $data
+ * @param string $uri
+ * @param resource $data
* @param ICollection $parent
- * @param bool $modified Should be set to true, if this event handler
- * changed &$data.
+ * @param bool $modified should be set to true, if this event handler
+ * changed &$data
+ *
* @return bool
*/
- function beforeCreateFile($uri, $data, ICollection $parent, $modified) {
-
+ public function beforeCreateFile($uri, $data, ICollection $parent, $modified)
+ {
if ($tempPath = $this->isTempFile($uri)) {
-
$hR = $this->server->httpResponse;
$hR->setHeader('X-Sabre-Temp', 'true');
file_put_contents($tempPath, $data);
+
return false;
}
- return;
+ return;
}
/**
@@ -158,71 +164,76 @@ class TemporaryFileFilterPlugin extends ServerPlugin {
* temporary file storage.
*
* @param string $path
+ *
* @return bool|string
*/
- protected function isTempFile($path) {
-
+ protected function isTempFile($path)
+ {
// We're only interested in the basename.
- list(, $tempPath) = URLUtil::splitPath($path);
+ list(, $tempPath) = Uri\split($path);
- foreach ($this->temporaryFilePatterns as $tempFile) {
+ if (null === $tempPath) {
+ return false;
+ }
+ foreach ($this->temporaryFilePatterns as $tempFile) {
if (preg_match($tempFile, $tempPath)) {
- return $this->getDataDir() . '/sabredav_' . md5($path) . '.tempfile';
+ return $this->getDataDir().'/sabredav_'.md5($path).'.tempfile';
}
-
}
return false;
-
}
-
/**
* This method handles the GET method for temporary files.
* If the file doesn't exist, it will return false which will kick in
* the regular system for the GET method.
*
- * @param RequestInterface $request
+ * @param RequestInterface $request
* @param ResponseInterface $hR
- * @param string $tempLocation
+ * @param string $tempLocation
+ *
* @return bool
*/
- function httpGet(RequestInterface $request, ResponseInterface $hR, $tempLocation) {
-
- if (!file_exists($tempLocation)) return;
+ public function httpGet(RequestInterface $request, ResponseInterface $hR, $tempLocation)
+ {
+ if (!file_exists($tempLocation)) {
+ return;
+ }
$hR->setHeader('Content-Type', 'application/octet-stream');
$hR->setHeader('Content-Length', filesize($tempLocation));
$hR->setHeader('X-Sabre-Temp', 'true');
$hR->setStatus(200);
$hR->setBody(fopen($tempLocation, 'r'));
- return false;
+ return false;
}
/**
* This method handles the PUT method.
*
- * @param RequestInterface $request
+ * @param RequestInterface $request
* @param ResponseInterface $hR
- * @param string $tempLocation
+ * @param string $tempLocation
+ *
* @return bool
*/
- function httpPut(RequestInterface $request, ResponseInterface $hR, $tempLocation) {
-
+ public function httpPut(RequestInterface $request, ResponseInterface $hR, $tempLocation)
+ {
$hR->setHeader('X-Sabre-Temp', 'true');
$newFile = !file_exists($tempLocation);
if (!$newFile && ($this->server->httpRequest->getHeader('If-None-Match'))) {
- throw new Exception\PreconditionFailed('The resource already exists, and an If-None-Match header was supplied');
+ throw new Exception\PreconditionFailed('The resource already exists, and an If-None-Match header was supplied');
}
file_put_contents($tempLocation, $this->server->httpRequest->getBody());
$hR->setStatus($newFile ? 201 : 200);
- return false;
+ return false;
}
/**
@@ -231,20 +242,23 @@ class TemporaryFileFilterPlugin extends ServerPlugin {
* If the file didn't exist, it will return false, which will make the
* standard HTTP DELETE handler kick in.
*
- * @param RequestInterface $request
+ * @param RequestInterface $request
* @param ResponseInterface $hR
- * @param string $tempLocation
+ * @param string $tempLocation
+ *
* @return bool
*/
- function httpDelete(RequestInterface $request, ResponseInterface $hR, $tempLocation) {
-
- if (!file_exists($tempLocation)) return;
+ public function httpDelete(RequestInterface $request, ResponseInterface $hR, $tempLocation)
+ {
+ if (!file_exists($tempLocation)) {
+ return;
+ }
unlink($tempLocation);
$hR->setHeader('X-Sabre-Temp', 'true');
$hR->setStatus(204);
- return false;
+ return false;
}
/**
@@ -254,14 +268,17 @@ class TemporaryFileFilterPlugin extends ServerPlugin {
* for which properties were requested, and just sends back a default
* set of properties.
*
- * @param RequestInterface $request
+ * @param RequestInterface $request
* @param ResponseInterface $hR
- * @param string $tempLocation
+ * @param string $tempLocation
+ *
* @return bool
*/
- function httpPropfind(RequestInterface $request, ResponseInterface $hR, $tempLocation) {
-
- if (!file_exists($tempLocation)) return;
+ public function httpPropfind(RequestInterface $request, ResponseInterface $hR, $tempLocation)
+ {
+ if (!file_exists($tempLocation)) {
+ return;
+ }
$hR->setHeader('X-Sabre-Temp', 'true');
$hR->setStatus(207);
@@ -269,22 +286,20 @@ class TemporaryFileFilterPlugin extends ServerPlugin {
$properties = [
'href' => $request->getPath(),
- 200 => [
- '{DAV:}getlastmodified' => new Xml\Property\GetLastModified(filemtime($tempLocation)),
- '{DAV:}getcontentlength' => filesize($tempLocation),
- '{DAV:}resourcetype' => new Xml\Property\ResourceType(null),
- '{' . Server::NS_SABREDAV . '}tempFile' => true,
-
+ 200 => [
+ '{DAV:}getlastmodified' => new Xml\Property\GetLastModified(filemtime($tempLocation)),
+ '{DAV:}getcontentlength' => filesize($tempLocation),
+ '{DAV:}resourcetype' => new Xml\Property\ResourceType(null),
+ '{'.Server::NS_SABREDAV.'}tempFile' => true,
],
];
$data = $this->server->generateMultiStatus([$properties]);
$hR->setBody($data);
- return false;
+ return false;
}
-
/**
* This method returns the directory where the temporary files should be stored.
*