1<?php
2
3namespace Sabre\DAV\Exception;
4
5use Sabre\DAV;
6
7/**
8 * Locked
9 *
10 * The 423 is thrown when a client tried to access a resource that was locked, without supplying a valid lock token
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 */
16class Locked extends DAV\Exception {
17
18    /**
19     * Lock information
20     *
21     * @var Sabre\DAV\Locks\LockInfo
22     */
23    protected $lock;
24
25    /**
26     * Creates the exception
27     *
28     * A LockInfo object should be passed if the user should be informed
29     * which lock actually has the file locked.
30     *
31     * @param DAV\Locks\LockInfo $lock
32     */
33    function __construct(DAV\Locks\LockInfo $lock = null) {
34
35        $this->lock = $lock;
36
37    }
38
39    /**
40     * Returns the HTTP statuscode for this exception
41     *
42     * @return int
43     */
44    function getHTTPCode() {
45
46        return 423;
47
48    }
49
50    /**
51     * This method allows the exception to include additional information into the WebDAV error response
52     *
53     * @param DAV\Server $server
54     * @param \DOMElement $errorNode
55     * @return void
56     */
57    function serialize(DAV\Server $server, \DOMElement $errorNode) {
58
59        if ($this->lock) {
60            $error = $errorNode->ownerDocument->createElementNS('DAV:', 'd:lock-token-submitted');
61            $errorNode->appendChild($error);
62
63            $href = $errorNode->ownerDocument->createElementNS('DAV:', 'd:href');
64            $href->appendChild($errorNode->ownerDocument->createTextNode($this->lock->uri));
65            $error->appendChild(
66                $href
67            );
68        }
69
70    }
71
72}
73