1
0

Forbidden.php 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  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. class Forbidden extends \Sabre\DAV\Exception\Forbidden {
  9. public const NS_OWNCLOUD = 'http://owncloud.org/ns';
  10. /**
  11. * @var bool
  12. */
  13. private $retry;
  14. /**
  15. * @param string $message
  16. * @param bool $retry
  17. * @param \Exception $previous
  18. */
  19. public function __construct($message, $retry = false, ?\Exception $previous = null) {
  20. parent::__construct($message, 0, $previous);
  21. $this->retry = $retry;
  22. }
  23. /**
  24. * This method allows the exception to include additional information
  25. * into the WebDAV error response
  26. *
  27. * @param \Sabre\DAV\Server $server
  28. * @param \DOMElement $errorNode
  29. * @return void
  30. */
  31. public function serialize(\Sabre\DAV\Server $server, \DOMElement $errorNode) {
  32. // set ownCloud namespace
  33. $errorNode->setAttribute('xmlns:o', self::NS_OWNCLOUD);
  34. // adding the retry node
  35. $error = $errorNode->ownerDocument->createElementNS('o:', 'o:retry', var_export($this->retry, true));
  36. $errorNode->appendChild($error);
  37. // adding the message node
  38. $error = $errorNode->ownerDocument->createElementNS('o:', 'o:reason', $this->getMessage());
  39. $errorNode->appendChild($error);
  40. }
  41. }