InvalidPath.php 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. <?php
  2. /**
  3. * @copyright Copyright (c) 2016, ownCloud, Inc.
  4. *
  5. * @author Christoph Wurst <christoph@winzerhof-wurst.at>
  6. * @author Robin Appelman <robin@icewind.nl>
  7. * @author Thomas Müller <thomas.mueller@tmit.eu>
  8. *
  9. * @license AGPL-3.0
  10. *
  11. * This code is free software: you can redistribute it and/or modify
  12. * it under the terms of the GNU Affero General Public License, version 3,
  13. * as published by the Free Software Foundation.
  14. *
  15. * This program is distributed in the hope that it will be useful,
  16. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  17. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  18. * GNU Affero General Public License for more details.
  19. *
  20. * You should have received a copy of the GNU Affero General Public License, version 3,
  21. * along with this program. If not, see <http://www.gnu.org/licenses/>
  22. *
  23. */
  24. namespace OCA\DAV\Connector\Sabre\Exception;
  25. use Sabre\DAV\Exception;
  26. class InvalidPath extends Exception {
  27. public const NS_OWNCLOUD = 'http://owncloud.org/ns';
  28. /**
  29. * @var bool
  30. */
  31. private $retry;
  32. /**
  33. * @param string $message
  34. * @param bool $retry
  35. * @param \Exception|null $previous
  36. */
  37. public function __construct($message, $retry = false, \Exception $previous = null) {
  38. parent::__construct($message, 0, $previous);
  39. $this->retry = $retry;
  40. }
  41. /**
  42. * Returns the HTTP status code for this exception
  43. *
  44. * @return int
  45. */
  46. public function getHTTPCode() {
  47. return 400;
  48. }
  49. /**
  50. * This method allows the exception to include additional information
  51. * into the WebDAV error response
  52. *
  53. * @param \Sabre\DAV\Server $server
  54. * @param \DOMElement $errorNode
  55. * @return void
  56. */
  57. public function serialize(\Sabre\DAV\Server $server, \DOMElement $errorNode) {
  58. // set ownCloud namespace
  59. $errorNode->setAttribute('xmlns:o', self::NS_OWNCLOUD);
  60. // adding the retry node
  61. $error = $errorNode->ownerDocument->createElementNS('o:', 'o:retry', var_export($this->retry, true));
  62. $errorNode->appendChild($error);
  63. // adding the message node
  64. $error = $errorNode->ownerDocument->createElementNS('o:', 'o:reason', $this->getMessage());
  65. $errorNode->appendChild($error);
  66. }
  67. }