GuessContentType
extends ServerPlugin
in package
GuessContentType plugin.
A lot of the built-in File objects just return application/octet-stream as a content-type by default. This is a problem for some clients, because they expect a correct contenttype.
There's really no accurate, fast and portable way to determine the contenttype so this extension does what the rest of the world does, and guesses it based on the file extension.
Tags
Table of Contents
- $extensionMap : array<string|int, mixed>
- List of recognized file extensions.
- 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.
- initialize() : mixed
- Initializes the plugin.
- propFind() : mixed
- Our PROPFIND handler.
- getContentType() : string
- Simple method to return the contenttype.
Properties
$extensionMap
List of recognized file extensions.
public
array<string|int, mixed>
$extensionMap
= [
// images
'jpg' => 'image/jpeg',
'gif' => 'image/gif',
'png' => 'image/png',
// groupware
'ics' => 'text/calendar',
'vcf' => 'text/vcard',
// text
'txt' => 'text/plain',
]
Feel free to add more
Methods
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> —initialize()
Initializes the plugin.
public
initialize(Server $server) : mixed
Parameters
- $server : Server
Return values
mixed —propFind()
Our PROPFIND handler.
public
propFind(PropFind $propFind, INode $node) : mixed
Here we set a contenttype, if the node didn't already have one.
Parameters
Return values
mixed —getContentType()
Simple method to return the contenttype.
protected
getContentType(string $fileName) : string
Parameters
- $fileName : string