4 * This server combines both CardDAV and CalDAV functionality into a single
5 * server. It is assumed that the server runs at the root of a HTTP domain (be
6 * that a domainname-based vhost or a specific TCP port.
8 * This example also assumes that you're using SQLite and the database has
9 * already been setup (along with the database tables).
11 * You may choose to use MySQL instead, just change the PDO connection
16 * UTC or GMT is easy to work with, and usually recommended for any
19 date_default_timezone_set('UTC');
22 * Make sure this setting is turned on and reflect the root url for your WebDAV
25 * This can be for example the root / or a complete path to your server script.
32 * Feel free to switch this to MySQL, it will definitely be better for higher
35 $pdo = new PDO('sqlite:data/db.sqlite');
36 $pdo->setAttribute(PDO::ATTR_ERRMODE,PDO::ERRMODE_EXCEPTION);
39 * Mapping PHP errors to exceptions.
41 * While this is not strictly needed, it makes a lot of sense to do so. If an
42 * E_NOTICE or anything appears in your code, this allows SabreDAV to intercept
43 * the issue and send a proper response back to the client (HTTP/1.1 500).
45 function exception_error_handler($errno, $errstr, $errfile, $errline ) {
46 throw new ErrorException($errstr, 0, $errno, $errfile, $errline);
48 set_error_handler("exception_error_handler");
51 require_once 'lib/Sabre/autoload.php';
54 * The backends. Yes we do really need all of them.
56 * This allows any developer to subclass just any of them and hook into their
57 * own backend systems.
59 $authBackend = new Sabre_DAV_Auth_Backend_PDO($pdo);
60 $principalBackend = new Sabre_DAVACL_PrincipalBackend_PDO($pdo);
61 $carddavBackend = new Sabre_CardDAV_Backend_PDO($pdo);
62 $caldavBackend = new Sabre_CalDAV_Backend_PDO($pdo);
67 * Basically this is an array which contains the 'top-level' directories in the
72 new Sabre_CalDAV_Principal_Collection($principalBackend),
74 new Sabre_CalDAV_CalendarRootNode($principalBackend, $caldavBackend),
76 new Sabre_CardDAV_AddressBookRoot($principalBackend, $carddavBackend),
79 // The object tree needs in turn to be passed to the server class
80 $server = new Sabre_DAV_Server($nodes);
81 $server->setBaseUri($baseUri);
84 $server->addPlugin(new Sabre_DAV_Auth_Plugin($authBackend,'SabreDAV'));
85 $server->addPlugin(new Sabre_DAV_Browser_Plugin());
86 $server->addPlugin(new Sabre_CalDAV_Plugin());
87 $server->addPlugin(new Sabre_CardDAV_Plugin());
88 $server->addPlugin(new Sabre_DAVACL_Plugin());