aboutsummaryrefslogtreecommitdiffstats
path: root/vendor/sabre/dav/examples/simplefsserver.php
diff options
context:
space:
mode:
authorHaakon Meland Eriksen <haakon.eriksen@far.no>2014-06-24 19:34:36 +0200
committerHaakon Meland Eriksen <haakon.eriksen@far.no>2014-06-24 19:34:36 +0200
commitb8dc9e855af2d30f33d0f90dc13d8cad0a7b3e70 (patch)
tree718df6305bcb82c8dcb4b287a7132422e748cdfb /vendor/sabre/dav/examples/simplefsserver.php
parentc2d520f1be115fb3cb5da2a35eb10146cecee8aa (diff)
parenta92fb0b04c3e6474ec48faf8e4cc65c382e89d66 (diff)
downloadvolse-hubzilla-b8dc9e855af2d30f33d0f90dc13d8cad0a7b3e70.tar.gz
volse-hubzilla-b8dc9e855af2d30f33d0f90dc13d8cad0a7b3e70.tar.bz2
volse-hubzilla-b8dc9e855af2d30f33d0f90dc13d8cad0a7b3e70.zip
Merge remote-tracking branch 'upstream/master'
Diffstat (limited to 'vendor/sabre/dav/examples/simplefsserver.php')
-rw-r--r--vendor/sabre/dav/examples/simplefsserver.php123
1 files changed, 123 insertions, 0 deletions
diff --git a/vendor/sabre/dav/examples/simplefsserver.php b/vendor/sabre/dav/examples/simplefsserver.php
new file mode 100644
index 000000000..f1b4a1100
--- /dev/null
+++ b/vendor/sabre/dav/examples/simplefsserver.php
@@ -0,0 +1,123 @@
+<?php
+
+// !!!! Make sure the Sabre directory is in the include_path !!!
+// example:
+// set_include_path('lib/' . PATH_SEPARATOR . get_include_path());
+
+/*
+
+This example demonstrates a simple way to create your own virtual filesystems.
+By extending the _File and Directory classes, you can easily create a tree
+based on various datasources.
+
+The most obvious example is the filesystem itself. A more complete and documented
+example can be found in:
+
+lib/Sabre/DAV/FS/Node.php
+lib/Sabre/DAV/FS/Directory.php
+lib/Sabre/DAV/FS/File.php
+
+*/
+
+// settings
+date_default_timezone_set('Canada/Eastern');
+$publicDir = 'public';
+
+// Files we need
+require_once 'vendor/autoload.php';
+
+class MyCollection extends Sabre\DAV\Collection {
+
+ private $myPath;
+
+ function __construct($myPath) {
+
+ $this->myPath = $myPath;
+
+ }
+
+ function getChildren() {
+
+ $children = array();
+ // Loop through the directory, and create objects for each node
+ foreach(scandir($this->myPath) as $node) {
+
+ // Ignoring files staring with .
+ if ($node[0]==='.') continue;
+
+ $children[] = $this->getChild($node);
+
+ }
+
+ return $children;
+
+ }
+
+ function getChild($name) {
+
+ $path = $this->myPath . '/' . $name;
+
+ // We have to throw a NotFound exception if the file didn't exist
+ if (!file\exists($this->myPath)) throw new \Sabre\DAV\Exception\NotFound('The file with name: ' . $name . ' could not be found');
+ // Some added security
+
+ if ($name[0]=='.') throw new \Sabre\DAV\Exception\Forbidden('Access denied');
+
+ if (is_dir($path)) {
+
+ return new \MyCollection($name);
+
+ } else {
+
+ return new \MyFile($path);
+
+ }
+
+ }
+
+ function getName() {
+
+ return basename($this->myPath);
+
+ }
+
+}
+
+class MyFile extends \Sabre\DAV\File {
+
+ private $myPath;
+
+ function __construct($myPath) {
+
+ $this->myPath = $myPath;
+
+ }
+
+ function getName() {
+
+ return basename($this->myPath);
+
+ }
+
+ function get() {
+
+ return fopen($this->myPath,'r');
+
+ }
+
+ function getSize() {
+
+ return filesize($this->myPath);
+
+ }
+
+}
+
+// Make sure there is a directory in your current directory named 'public'. We will be exposing that directory to WebDAV
+$rootNode = new \MyCollection($publicDir);
+
+// The rootNode needs to be passed to the server object.
+$server = new \Sabre\DAV\Server($rootNode);
+
+// And off we go!
+$server->exec();