Skip to content

Instantly share code, notes, and snippets.

@evert
Created February 1, 2012 12:52
Show Gist options
  • Save evert/1716860 to your computer and use it in GitHub Desktop.
Save evert/1716860 to your computer and use it in GitHub Desktop.
sabredav demo server
<?php
error_reporting(E_ALL | E_STRICT);
ini_set('display_errors',1);
$publicDir = '/path/to/public/directory';
$pdo = new PDO('sqlite:/path/to/sqlite/database');
$pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
date_default_timezone_set('UTC');
include dirname(__FILE__) . '/SabreDAV/lib/Sabre/autoload.php';
include dirname(__FILE__) . '/MyBrowser.php';
/* Backends */
$authBackend = new Sabre_DAV_Auth_Backend_PDO($pdo);
$principalBackend = new Sabre_DAVACL_PrincipalBackend_PDO($pdo);
$locksBackend = new Sabre_DAV_Locks_Backend_PDO($pdo);
$calendarBackend = new Sabre_CalDAV_Backend_PDO($pdo);
$addressbookBackend = new Sabre_CardDAV_Backend_PDO($pdo);
/* Directory structure */
$nodes = array(
new Sabre_DAV_FS_Directory($publicDir),
new Sabre_CalDAV_Principal_Collection($principalBackend),
new Sabre_CalDAV_CalendarRootNode($principalBackend, $calendarBackend),
new Sabre_CardDAV_AddressBookRoot($principalBackend, $addressbookBackend)
);
$server = new Sabre_DAV_Server($nodes);
$server->setBaseUri('/');
/* Locks */
$locksPlugin = new Sabre_DAV_Locks_Plugin($locksBackend);
$server->addPlugin($locksPlugin);
/* Authentication */
$authPlugin = new Sabre_DAV_Auth_Plugin($authBackend, 'SabreDAV');
$server->addPlugin($authPlugin);
/* CalDAV */
$caldavPlugin = new Sabre_CalDAV_Plugin();
$server->addPlugin($caldavPlugin);
/* CardDAV */
$carddavPlugin = new Sabre_CardDAV_Plugin();
$server->addPlugin($carddavPlugin);
/* ACL */
$aclPlugin = new Sabre_DAVACL_Plugin();
$server->addPlugin($aclPlugin);
/* ICS */
$icsPlugin = new Sabre_CalDAV_ICSExportPlugin();
$server->addPlugin($icsPlugin);
/* Handy plugins */
$server->addPlugin(new MyBrowser(false));
$server->addPlugin(new Sabre_DAV_Mount_Plugin());
$server->addPlugin(new Sabre_DAV_Browser_GuessContentType());
$server->exec();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment