Skip to content

Instantly share code, notes, and snippets.

@evert
Created March 18, 2011 12:46
Show Gist options
  • Save evert/876002 to your computer and use it in GitHub Desktop.
Save evert/876002 to your computer and use it in GitHub Desktop.
SabreDAV demo server sourcecode
<?php
error_reporting(E_ALL | E_STRICT);
ini_set('display_errors',1);
$publicDir = '/home/groups/s/sa/sabredav/persistent/public';
$pdo = new PDO('sqlite:/home/groups/s/sa/sabredav/persistent/db/db.sqlite');
$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);
/* Directory structure */
$nodes = array(
new Sabre_DAV_FS_Directory($publicDir),
new Sabre_CalDAV_Principal_Collection($principalBackend),
new Sabre_CalDAV_CalendarRootNode($principalBackend, $calendarBackend),
);
$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);
/* 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