PreconditionFailed.php 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. <?php
  2. declare(strict_types=1);
  3. namespace Sabre\DAV\Exception;
  4. use Sabre\DAV;
  5. /**
  6. * PreconditionFailed.
  7. *
  8. * This exception is normally thrown when a client submitted a conditional request,
  9. * like for example an If, If-None-Match or If-Match header, which caused the HTTP
  10. * request to not execute (the condition of the header failed)
  11. *
  12. * @copyright Copyright (C) fruux GmbH (https://fruux.com/)
  13. * @author Evert Pot (http://evertpot.com/)
  14. * @license http://sabre.io/license/ Modified BSD License
  15. */
  16. class PreconditionFailed extends DAV\Exception
  17. {
  18. /**
  19. * When this exception is thrown, the header-name might be set.
  20. *
  21. * This allows the exception-catching code to determine which HTTP header
  22. * caused the exception.
  23. *
  24. * @var string
  25. */
  26. public $header = null;
  27. /**
  28. * Create the exception.
  29. *
  30. * @param string $message
  31. * @param string $header
  32. */
  33. public function __construct($message, $header = null)
  34. {
  35. parent::__construct($message);
  36. $this->header = $header;
  37. }
  38. /**
  39. * Returns the HTTP statuscode for this exception.
  40. *
  41. * @return int
  42. */
  43. public function getHTTPCode()
  44. {
  45. return 412;
  46. }
  47. /**
  48. * This method allows the exception to include additional information into the WebDAV error response.
  49. */
  50. public function serialize(DAV\Server $server, \DOMElement $errorNode)
  51. {
  52. if ($this->header) {
  53. $prop = $errorNode->ownerDocument->createElement('s:header');
  54. $prop->nodeValue = $this->header;
  55. $errorNode->appendChild($prop);
  56. }
  57. }
  58. }