TemporaryFileFilterPlugin
extends ServerPlugin
in package
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 a WebDAV share as a disk.
It will intercept these files and place them in a separate directory. these files are not deleted automatically, so it is advisable to delete these after they are not accessed for 24 hours.
Currently it supports:
- OS/X style resource forks and .DS_Store
- desktop.ini and Thumbs.db (windows)
- .*.swp (vim temporary files)
- .dat.* (smultron temporary files)
Additional patterns can be added, by adding on to the temporaryFilePatterns property.
Tags
Table of Contents
- $temporaryFilePatterns : array<string|int, mixed>
- This is the list of patterns we intercept.
- $server : Server
- A reference to the main Server class.
- $dataDir : string
- This is the directory where this plugin will store it's files.
- __construct() : mixed
- Creates the plugin.
- beforeCreateFile() : bool
- This method is invoked if some subsystem creates a new file.
- beforeMethod() : bool
- This method is called before any HTTP method handler.
- getFeatures() : array<string|int, mixed>
- This method should return a list of server-features.
- getHTTPMethods() : array<string|int, mixed>
- Use this method to tell the server this plugin defines additional HTTP methods.
- getPluginInfo() : array<string|int, mixed>
- Returns a bunch of meta-data about the plugin.
- getPluginName() : string
- Returns a plugin name.
- getSupportedReportSet() : array<string|int, mixed>
- Returns a list of reports this plugin supports.
- httpDelete() : bool
- This method handles the DELETE method.
- httpGet() : bool
- This method handles the GET method for temporary files.
- httpPropfind() : bool
- This method handles the PROPFIND method.
- httpPut() : bool
- This method handles the PUT method.
- initialize() : mixed
- Initialize the plugin.
- getDataDir() : string
- This method returns the directory where the temporary files should be stored.
- isTempFile() : bool|string
- This method will check if the url matches the temporary file pattern if it does, it will return an path based on $this->dataDir for the temporary file storage.
Properties
$temporaryFilePatterns
This is the list of patterns we intercept.
public
array<string|int, mixed>
$temporaryFilePatterns
= [
'/^\._(.*)$/',
// OS/X resource forks
'/^.DS_Store$/',
// OS/X custom folder settings
'/^desktop.ini$/',
// Windows custom folder settings
'/^Thumbs.db$/',
// Windows thumbnail cache
'/^.(.*).swp$/',
// ViM temporary files
'/^\.dat(.*)$/',
// Smultron seems to create these
'/^~lock.(.*)#$/',
]
If new patterns are added, they must be valid patterns for preg_match.
$server
A reference to the main Server class.
protected
Server
$server
$dataDir
This is the directory where this plugin will store it's files.
private
string
$dataDir
Methods
__construct()
Creates the plugin.
public
__construct([string|null $dataDir = null ]) : mixed
Make sure you specify a directory for your files. If you don't, we will use PHP's directory for session-storage instead, and you might not want that.
Parameters
- $dataDir : string|null = null
Return values
mixed —beforeCreateFile()
This method is invoked if some subsystem creates a new file.
public
beforeCreateFile(string $uri, resource $data, ICollection $parent, bool $modified) : bool
This is used to deal with HTTP LOCK requests which create a new file.
Parameters
- $uri : string
- $data : resource
- $parent : ICollection
- $modified : bool
-
should be set to true, if this event handler changed &$data
Return values
bool —beforeMethod()
This method is called before any HTTP method handler.
public
beforeMethod(RequestInterface $request, ResponseInterface $response) : bool
This method intercepts any GET, DELETE, PUT and PROPFIND calls to filenames that are known to match the 'temporary file' regex.
Parameters
- $request : RequestInterface
- $response : ResponseInterface
Return values
bool —getFeatures()
This method should return a list of server-features.
public
getFeatures() : array<string|int, mixed>
This is for example 'versioning' and is added to the DAV: header in an OPTIONS response.
Return values
array<string|int, mixed> —getHTTPMethods()
Use this method to tell the server this plugin defines additional HTTP methods.
public
getHTTPMethods(string $path) : array<string|int, mixed>
This method is passed a uri. It should only return HTTP methods that are available for the specified uri.
Parameters
- $path : string
Return values
array<string|int, mixed> —getPluginInfo()
Returns a bunch of meta-data about the plugin.
public
getPluginInfo() : array<string|int, mixed>
Providing this information is optional, and is mainly displayed by the Browser plugin.
The description key in the returned array may contain html and will not be sanitized.
Return values
array<string|int, mixed> —getPluginName()
Returns a plugin name.
public
getPluginName() : string
Using this name other plugins will be able to access other plugins using \Sabre\DAV\Server::getPlugin
Return values
string —getSupportedReportSet()
Returns a list of reports this plugin supports.
public
getSupportedReportSet(string $uri) : array<string|int, mixed>
This will be used in the {DAV:}supported-report-set property. Note that you still need to subscribe to the 'report' event to actually implement them
Parameters
- $uri : string
Return values
array<string|int, mixed> —httpDelete()
This method handles the DELETE method.
public
httpDelete(RequestInterface $request, ResponseInterface $hR, string $tempLocation) : bool
If the file didn't exist, it will return false, which will make the standard HTTP DELETE handler kick in.
Parameters
- $request : RequestInterface
- $hR : ResponseInterface
- $tempLocation : string
Return values
bool —httpGet()
This method handles the GET method for temporary files.
public
httpGet(RequestInterface $request, ResponseInterface $hR, string $tempLocation) : bool
If the file doesn't exist, it will return false which will kick in the regular system for the GET method.
Parameters
- $request : RequestInterface
- $hR : ResponseInterface
- $tempLocation : string
Return values
bool —httpPropfind()
This method handles the PROPFIND method.
public
httpPropfind(RequestInterface $request, ResponseInterface $hR, string $tempLocation) : bool
It's a very lazy method, it won't bother checking the request body for which properties were requested, and just sends back a default set of properties.
Parameters
- $request : RequestInterface
- $hR : ResponseInterface
- $tempLocation : string
Return values
bool —httpPut()
This method handles the PUT method.
public
httpPut(RequestInterface $request, ResponseInterface $hR, string $tempLocation) : bool
Parameters
- $request : RequestInterface
- $hR : ResponseInterface
- $tempLocation : string
Return values
bool —initialize()
Initialize the plugin.
public
initialize(Server $server) : mixed
This is called automatically be the Server class after this plugin is added with Sabre\DAV\Server::addPlugin()
Parameters
- $server : Server
Return values
mixed —getDataDir()
This method returns the directory where the temporary files should be stored.
protected
getDataDir() : string
Return values
string —isTempFile()
This method will check if the url matches the temporary file pattern if it does, it will return an path based on $this->dataDir for the temporary file storage.
protected
isTempFile(string $path) : bool|string
Parameters
- $path : string