Locked.php 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. <?php
  2. declare(strict_types=1);
  3. namespace Sabre\DAV\Exception;
  4. use Sabre\DAV;
  5. /**
  6. * Locked.
  7. *
  8. * The 423 is thrown when a client tried to access a resource that was locked, without supplying a valid lock token
  9. *
  10. * @copyright Copyright (C) fruux GmbH (https://fruux.com/)
  11. * @author Evert Pot (http://evertpot.com/)
  12. * @license http://sabre.io/license/ Modified BSD License
  13. */
  14. class Locked extends DAV\Exception
  15. {
  16. /**
  17. * Lock information.
  18. *
  19. * @var \Sabre\DAV\Locks\LockInfo
  20. */
  21. protected $lock;
  22. /**
  23. * Creates the exception.
  24. *
  25. * A LockInfo object should be passed if the user should be informed
  26. * which lock actually has the file locked.
  27. *
  28. * @param DAV\Locks\LockInfo $lock
  29. */
  30. public function __construct(DAV\Locks\LockInfo $lock = null)
  31. {
  32. parent::__construct();
  33. $this->lock = $lock;
  34. }
  35. /**
  36. * Returns the HTTP statuscode for this exception.
  37. *
  38. * @return int
  39. */
  40. public function getHTTPCode()
  41. {
  42. return 423;
  43. }
  44. /**
  45. * This method allows the exception to include additional information into the WebDAV error response.
  46. */
  47. public function serialize(DAV\Server $server, \DOMElement $errorNode)
  48. {
  49. if ($this->lock) {
  50. $error = $errorNode->ownerDocument->createElementNS('DAV:', 'd:lock-token-submitted');
  51. $errorNode->appendChild($error);
  52. $href = $errorNode->ownerDocument->createElementNS('DAV:', 'd:href');
  53. $href->appendChild($errorNode->ownerDocument->createTextNode($this->lock->uri));
  54. $error->appendChild(
  55. $href
  56. );
  57. }
  58. }
  59. }