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