xref: /plugin/davcal/vendor/sabre/dav/lib/DAV/Browser/MapGetToPropFind.php (revision a1a3b6794e0e143a4a8b51d3185ce2d339be61ab)
1*a1a3b679SAndreas Boehler<?php
2*a1a3b679SAndreas Boehler
3*a1a3b679SAndreas Boehlernamespace Sabre\DAV\Browser;
4*a1a3b679SAndreas Boehler
5*a1a3b679SAndreas Boehleruse Sabre\DAV;
6*a1a3b679SAndreas Boehleruse Sabre\HTTP\RequestInterface;
7*a1a3b679SAndreas Boehleruse Sabre\HTTP\ResponseInterface;
8*a1a3b679SAndreas Boehler
9*a1a3b679SAndreas Boehler/**
10*a1a3b679SAndreas Boehler * This is a simple plugin that will map any GET request for non-files to
11*a1a3b679SAndreas Boehler * PROPFIND allprops-requests.
12*a1a3b679SAndreas Boehler *
13*a1a3b679SAndreas Boehler * This should allow easy debugging of PROPFIND
14*a1a3b679SAndreas Boehler *
15*a1a3b679SAndreas Boehler * @copyright Copyright (C) 2007-2015 fruux GmbH (https://fruux.com/).
16*a1a3b679SAndreas Boehler * @author Evert Pot (http://evertpot.com/)
17*a1a3b679SAndreas Boehler * @license http://sabre.io/license/ Modified BSD License
18*a1a3b679SAndreas Boehler */
19*a1a3b679SAndreas Boehlerclass MapGetToPropFind extends DAV\ServerPlugin {
20*a1a3b679SAndreas Boehler
21*a1a3b679SAndreas Boehler    /**
22*a1a3b679SAndreas Boehler     * reference to server class
23*a1a3b679SAndreas Boehler     *
24*a1a3b679SAndreas Boehler     * @var Sabre\DAV\Server
25*a1a3b679SAndreas Boehler     */
26*a1a3b679SAndreas Boehler    protected $server;
27*a1a3b679SAndreas Boehler
28*a1a3b679SAndreas Boehler    /**
29*a1a3b679SAndreas Boehler     * Initializes the plugin and subscribes to events
30*a1a3b679SAndreas Boehler     *
31*a1a3b679SAndreas Boehler     * @param DAV\Server $server
32*a1a3b679SAndreas Boehler     * @return void
33*a1a3b679SAndreas Boehler     */
34*a1a3b679SAndreas Boehler    function initialize(DAV\Server $server) {
35*a1a3b679SAndreas Boehler
36*a1a3b679SAndreas Boehler        $this->server = $server;
37*a1a3b679SAndreas Boehler        $this->server->on('method:GET', [$this, 'httpGet'], 90);
38*a1a3b679SAndreas Boehler    }
39*a1a3b679SAndreas Boehler
40*a1a3b679SAndreas Boehler    /**
41*a1a3b679SAndreas Boehler     * This method intercepts GET requests to non-files, and changes it into an HTTP PROPFIND request
42*a1a3b679SAndreas Boehler     *
43*a1a3b679SAndreas Boehler     * @param RequestInterface $request
44*a1a3b679SAndreas Boehler     * @param ResponseInterface $response
45*a1a3b679SAndreas Boehler     * @return bool
46*a1a3b679SAndreas Boehler     */
47*a1a3b679SAndreas Boehler    function httpGet(RequestInterface $request, ResponseInterface $response) {
48*a1a3b679SAndreas Boehler
49*a1a3b679SAndreas Boehler        $node = $this->server->tree->getNodeForPath($request->getPath());
50*a1a3b679SAndreas Boehler        if ($node instanceof DAV\IFile) return;
51*a1a3b679SAndreas Boehler
52*a1a3b679SAndreas Boehler        $subRequest = clone $request;
53*a1a3b679SAndreas Boehler        $subRequest->setMethod('PROPFIND');
54*a1a3b679SAndreas Boehler
55*a1a3b679SAndreas Boehler        $this->server->invokeMethod($subRequest, $response);
56*a1a3b679SAndreas Boehler        return false;
57*a1a3b679SAndreas Boehler
58*a1a3b679SAndreas Boehler    }
59*a1a3b679SAndreas Boehler
60*a1a3b679SAndreas Boehler}
61