invalidpath.php 1.9 KB

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