1<?php
2
3/**
4 * DokuWiki WebDAV Plugin: Dummy GET Response Plugin
5 *
6 * @copyright Copyright (C) 2019-2020
7 * @author Giuseppe Di Terlizzi (giuseppe.diterlizzi@gmail.com)
8 * @license GNU GPL 2
9 */
10
11namespace dokuwiki\plugin\webdav\core\Plugin;
12
13use Sabre\DAV\Server;
14use Sabre\DAV\ServerPlugin;
15use Sabre\HTTP\RequestInterface;
16use Sabre\HTTP\ResponseInterface;
17
18class DummyGetResponse extends ServerPlugin
19{
20    /** @var \Sabre\DAV\Server */
21    protected $server;
22
23    /**
24     * @param \Sabre\DAV\Server $server
25     * @return void
26     */
27    public function initialize(Server $server)
28    {
29        $server->on('method:GET', [$this, 'httpGet'], 200);
30    }
31
32    /**
33     * @param RequestInterface $request
34     * @param ResponseInterface $response
35     * @return false
36     */
37    public function httpGet(RequestInterface $request, ResponseInterface $response)
38    {
39        $string = 'This is the WebDAV interface. It can only be accessed by WebDAV clients.';
40        $stream = fopen('php://memory', 'r+');
41        fwrite($stream, $string);
42        rewind($stream);
43
44        $response->setStatus(200);
45        $response->setBody($stream);
46
47        return false;
48    }
49}
50