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