MapGetToPropFind.php 1.4 KB

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