Forbidden.php 1.3 KB

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