sabre/dav Documentation
repository·master·Indexed 23 days ago
https://github.com/sabre-io/davA robust PHP framework for building WebDAV, CalDAV, and CardDAV servers. It provides an extensible framework for managing file trees, handling WebDAV methods (PROPFIND, MOVE, COPY, etc.), and supporting extensions like locking and ACLs. The library includes a PDO CalDAV backend for storing calendar data in databases like MySQL or SQLite, supporting CRUD operations on calendar objects, scheduling, subscriptions, and sharing.
What's inside sabre/dav
- sabre/dav is a PHP framework designed for building WebDAV, CalDAV, and CardDAV servers. It is a widely used library for implementing these protocols within PHP applications.
Understand the CalendarHome abstraction
masterIn the CalDAV implementation,
CalendarHomerepresents a node typically located within a user's calendar-homeset. It acts as a container for a user's personal resources, including:- Calendars: The user's primary calendar collections.
- Special Nodes: Depending on backend support, it can contain an
inboxandoutbox(for Scheduling), anotificationscollection, and calendar subscriptions. - ACLs: It manages Access Control Lists (ACLs) for the user's calendar space.
CalendarHomedelegates actual data storage and retrieval to aBackendackendInterface.Implement a DAVACL server plugin
masterTo extend WebDAV functionality with Access Control Lists (ACL), you can implement or extend the
DAVACL\Pluginbase class. This class provides support for RFC3744 features, including various REPORT methods used for principal matching, property expansion, and principal searching.When implementing a plugin, you can use
getPluginInfo()to provide metadata that can be displayed by browser interfaces, including a name and a description (which may contain unsanitized HTML).public function getPluginInfo(): array { return [ 'name' => $this->getPluginName(), 'description' => 'Adds support for WebDAV ACL (rfc3744)', 'link' => 'http://sabre.io/dav/acl/', ]; }Initialize the SabreDAV Server
masterTheSabre\DAV\Serverclass is the main entry point for a WebDAV server. You can initialize it by providing a directory tree, a root node, or an array of top-level children. If no tree is provided, it defaults to aSimpleCollectionnamed 'root'.Initialize the SabreDAV Client
masterTo use the
Sabre\DAV\Client, instantiate it with a$settingsarray. ThebaseUriis a required setting. You can also configure authentication, proxies, and content encoding.Supported Settings:
baseUri(string, required): The base URL of the WebDAV server.userName(string, optional): Username for authentication.password(string, optional): Password for authentication.proxy(string, optional): Proxy server configuration.authType(int, optional): A bitmap of authentication methods (see constants).encoding(int, optional): A bitmap of supported encodings (see constants).
Run the SabreDAV test server via CLI
masterThe
bin/sabredav.phpscript is a test server implementation designed to be run using the PHP built-in web server. It initializes a SabreDAV server instance with a root directory set to the current working directory (getcwd()) and includes theSabre\DAV\Browser\Pluginto allow web-based browsing of the WebDAV filesystem.Note: This script is specifically intended to be executed via the PHP built-in web server (e.g.,
php -S localhost:8080 bin/sabredav.php) rather than as a standalone CLI command.Configure the PDO CalDAV backend
masterThe
Sabre\CalDAV\Backend\PDOclass is a CalDAV backend implementation that uses a PDO database (such as MySQL or SQLite) to store calendar data.When initializing the backend, you can customize the database table names used for various components of the CalDAV system by setting the following public properties:
$calendarTableName: Table for calendars.$calendarInstancesTableName: Table for calendar instances (e.g., when a calendar is shared).$calendarObjectTableName: Table for individual calendar objects (events, todos, etc.).$calendarChangesTableName: Table for tracking changes.$schedulingObjectTableName: Table for inbox/scheduling items.$calendarSubscriptionsTableName: Table for calendar subscriptions.
You can also extend the
$propertyMapor$subscriptionPropertyMapto map additional CalDAV/iCalendar properties to specific database field names. Note that only string-based properties are supported via this mapping.Configure the DAVACL Plugin
masterThe
Sabre\DAVACL\Pluginclass can be customized via several public properties to change how permissions and principals are handled.Key configuration options include:
$principalCollectionSet: A list of URLs containing principal collections. Modify this if your principals are located elsewhere.$hideNodesFromListings: If set totrue, nodes that are inaccessible by the user will be hidden from directory listings (e.g.,PROPFINDon a parent withDepth: 1). Defaults tofalse.$adminPrincipals: A list of principal URIs that will automatically receive{DAV:}allprivileges as protected privileges.$allowUnauthenticatedAccess: Iftrue, the plugin modifies the auth plugin to only require login when a privileged operation is denied. Set tofalseto harden security.$principalSearchPropertySet: Defines which properties a client can search using the{DAV:}principal-property-searchreport. Keys are property names, values are descriptions.
Configure Server Properties
masterThe
Serverclass provides several public properties and static settings to control its behavior:$debugExceptions(bool): Iftrue, the XML error response will include detailed information like file, line, code, and stack trace. Defaults tofalse.$enablePropfindDepthInfinity(bool): Iftrue, allowsDepth: infinityonPROPFINDrequests. This can be a DoS vector and isfalseby default.$resourceTypeMapping(array): Maps node classes/interfaces to DAV resource types (e.g.,ICollection::class => '{DAV:}collection').$protectedProperties(array): A list of properties (e.g.,{DAV:}getetag) that are server-controlled and cannot be modified viaPROPPATCH.static $exposeVersion(bool): Iffalse, the SabreDAV version number is hidden from headers and XML responses. Defaults totrue.static $streamMultiStatus(bool): Iftrue,PROPFINDmulti-status responses are streamed to the output buffer to save memory. Defaults tofalse.
Instantiate a Principal object
masterThe
Sabre\DAVACL\Principalclass represents a user or group in the DAVACL system. To instantiate it, you must provide an implementation ofPrincipalBackend\BackendInterfaceand an array of properties that includes at least theurikey.Note that the
uriis used as the unique identifier for the principal.Create a directory with createDirectory()
masterThe
createDirectory($uri)method is a convenience wrapper used to create a new directory (collection) at the specified URI. It internally callscreateCollection()using a standardMkColobject with the{DAV:}collectionresource type./** * @param string $uri */ public function createDirectory($uri)Manage user subscriptions with createSubscription() and updateSubscription()
masterThe PDO backend provides methods to manage CalDAV subscriptions for a principal.
Create a subscription
Use
createSubscription($principalUri, $uri, array $properties)to create a new subscription. The$propertiesarray must include the{http://calendarserver.org/ns/}sourcekey, which contains the subscription source object.Update a subscription
Use
updateSubscription($subscriptionId, PropPatch $propPatch)to modify an existing subscription. You must pass aPropPatchobject and call itshandle()method, specifying the supported properties (including{http://calendarserver.org/ns/}source) to process the mutations.Delete a subscription
Use
deleteSubscription($subscriptionId)to remove a subscription.public function createSubscription($principalUri, $uri, array $properties) public function updateSubscription($subscriptionId, PropPatch $propPatch) public function deleteSubscription($subscriptionId)