InvalidPath.php 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. <?php
  2. /**
  3. * SPDX-FileCopyrightText: 2016-2024 Nextcloud GmbH and Nextcloud contributors
  4. * SPDX-FileCopyrightText: 2016 ownCloud, Inc.
  5. * SPDX-License-Identifier: AGPL-3.0-only
  6. */
  7. namespace OCA\DAV\Connector\Sabre\Exception;
  8. use Sabre\DAV\Exception;
  9. class InvalidPath extends Exception {
  10. public const NS_OWNCLOUD = 'http://owncloud.org/ns';
  11. /**
  12. * @var bool
  13. */
  14. private $retry;
  15. /**
  16. * @param string $message
  17. * @param bool $retry
  18. * @param \Exception|null $previous
  19. */
  20. public function __construct($message, $retry = false, ?\Exception $previous = null) {
  21. parent::__construct($message, 0, $previous);
  22. $this->retry = $retry;
  23. }
  24. /**
  25. * Returns the HTTP status code for this exception
  26. *
  27. * @return int
  28. */
  29. public function getHTTPCode() {
  30. return 400;
  31. }
  32. /**
  33. * This method allows the exception to include additional information
  34. * into the WebDAV error response
  35. *
  36. * @param \Sabre\DAV\Server $server
  37. * @param \DOMElement $errorNode
  38. * @return void
  39. */
  40. public function serialize(\Sabre\DAV\Server $server, \DOMElement $errorNode) {
  41. // set ownCloud namespace
  42. $errorNode->setAttribute('xmlns:o', self::NS_OWNCLOUD);
  43. // adding the retry node
  44. $error = $errorNode->ownerDocument->createElementNS('o:', 'o:retry', var_export($this->retry, true));
  45. $errorNode->appendChild($error);
  46. // adding the message node
  47. $error = $errorNode->ownerDocument->createElementNS('o:', 'o:reason', $this->getMessage());
  48. $errorNode->appendChild($error);
  49. }
  50. }