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