xref: /plugin/davcal/vendor/sabre/dav/lib/DAV/Xml/Property/LockDiscovery.php (revision a1a3b6794e0e143a4a8b51d3185ce2d339be61ab)
1*a1a3b679SAndreas Boehler<?php
2*a1a3b679SAndreas Boehler
3*a1a3b679SAndreas Boehlernamespace Sabre\DAV\Xml\Property;
4*a1a3b679SAndreas Boehler
5*a1a3b679SAndreas Boehleruse Sabre\DAV;
6*a1a3b679SAndreas Boehleruse Sabre\DAV\Locks\LockInfo;
7*a1a3b679SAndreas Boehleruse Sabre\Xml\Element\XmlFragment;
8*a1a3b679SAndreas Boehleruse Sabre\Xml\Writer;
9*a1a3b679SAndreas Boehleruse Sabre\Xml\XmlSerializable;
10*a1a3b679SAndreas Boehler
11*a1a3b679SAndreas Boehler/**
12*a1a3b679SAndreas Boehler * Represents {DAV:}lockdiscovery property.
13*a1a3b679SAndreas Boehler *
14*a1a3b679SAndreas Boehler * This property is defined here:
15*a1a3b679SAndreas Boehler * http://tools.ietf.org/html/rfc4918#section-15.8
16*a1a3b679SAndreas Boehler *
17*a1a3b679SAndreas Boehler * This property contains all the open locks on a given resource
18*a1a3b679SAndreas Boehler *
19*a1a3b679SAndreas Boehler * @copyright Copyright (C) 2007-2015 fruux GmbH (https://fruux.com/).
20*a1a3b679SAndreas Boehler * @author Evert Pot (http://www.rooftopsolutions.nl/)
21*a1a3b679SAndreas Boehler * @license http://sabre.io/license/ Modified BSD License
22*a1a3b679SAndreas Boehler */
23*a1a3b679SAndreas Boehlerclass LockDiscovery implements XmlSerializable {
24*a1a3b679SAndreas Boehler
25*a1a3b679SAndreas Boehler    /**
26*a1a3b679SAndreas Boehler     * locks
27*a1a3b679SAndreas Boehler     *
28*a1a3b679SAndreas Boehler     * @var LockInfo[]
29*a1a3b679SAndreas Boehler     */
30*a1a3b679SAndreas Boehler    public $locks;
31*a1a3b679SAndreas Boehler
32*a1a3b679SAndreas Boehler    /**
33*a1a3b679SAndreas Boehler     * Hides the {DAV:}lockroot element from the response.
34*a1a3b679SAndreas Boehler     *
35*a1a3b679SAndreas Boehler     * It was reported that showing the lockroot in the response can break
36*a1a3b679SAndreas Boehler     * Office 2000 compatibility.
37*a1a3b679SAndreas Boehler     *
38*a1a3b679SAndreas Boehler     * @var bool
39*a1a3b679SAndreas Boehler     */
40*a1a3b679SAndreas Boehler    static $hideLockRoot = false;
41*a1a3b679SAndreas Boehler
42*a1a3b679SAndreas Boehler    /**
43*a1a3b679SAndreas Boehler     * __construct
44*a1a3b679SAndreas Boehler     *
45*a1a3b679SAndreas Boehler     * @param LockInfo[] $locks
46*a1a3b679SAndreas Boehler     */
47*a1a3b679SAndreas Boehler    function __construct($locks) {
48*a1a3b679SAndreas Boehler
49*a1a3b679SAndreas Boehler        $this->locks = $locks;
50*a1a3b679SAndreas Boehler
51*a1a3b679SAndreas Boehler    }
52*a1a3b679SAndreas Boehler
53*a1a3b679SAndreas Boehler    /**
54*a1a3b679SAndreas Boehler     * The serialize method is called during xml writing.
55*a1a3b679SAndreas Boehler     *
56*a1a3b679SAndreas Boehler     * It should use the $writer argument to encode this object into XML.
57*a1a3b679SAndreas Boehler     *
58*a1a3b679SAndreas Boehler     * Important note: it is not needed to create the parent element. The
59*a1a3b679SAndreas Boehler     * parent element is already created, and we only have to worry about
60*a1a3b679SAndreas Boehler     * attributes, child elements and text (if any).
61*a1a3b679SAndreas Boehler     *
62*a1a3b679SAndreas Boehler     * Important note 2: If you are writing any new elements, you are also
63*a1a3b679SAndreas Boehler     * responsible for closing them.
64*a1a3b679SAndreas Boehler     *
65*a1a3b679SAndreas Boehler     * @param Writer $writer
66*a1a3b679SAndreas Boehler     * @return void
67*a1a3b679SAndreas Boehler     */
68*a1a3b679SAndreas Boehler    function xmlSerialize(Writer $writer) {
69*a1a3b679SAndreas Boehler
70*a1a3b679SAndreas Boehler        foreach ($this->locks as $lock) {
71*a1a3b679SAndreas Boehler
72*a1a3b679SAndreas Boehler            $writer->startElement('{DAV:}activelock');
73*a1a3b679SAndreas Boehler
74*a1a3b679SAndreas Boehler            $writer->startElement('{DAV:}lockscope');
75*a1a3b679SAndreas Boehler            if ($lock->scope === LockInfo::SHARED) {
76*a1a3b679SAndreas Boehler                $writer->writeElement('{DAV:}shared');
77*a1a3b679SAndreas Boehler            } else {
78*a1a3b679SAndreas Boehler                $writer->writeElement('{DAV:}exclusive');
79*a1a3b679SAndreas Boehler            }
80*a1a3b679SAndreas Boehler
81*a1a3b679SAndreas Boehler            $writer->endElement(); // {DAV:}lockscope
82*a1a3b679SAndreas Boehler
83*a1a3b679SAndreas Boehler            $writer->startElement('{DAV:}locktype');
84*a1a3b679SAndreas Boehler            $writer->writeElement('{DAV:}write');
85*a1a3b679SAndreas Boehler            $writer->endElement(); // {DAV:}locktype
86*a1a3b679SAndreas Boehler
87*a1a3b679SAndreas Boehler            if (!self::$hideLockRoot) {
88*a1a3b679SAndreas Boehler                $writer->startElement('{DAV:}lockroot');
89*a1a3b679SAndreas Boehler                $writer->writeElement('{DAV:}href', $writer->contextUri . $lock->uri);
90*a1a3b679SAndreas Boehler                $writer->endElement(); // {DAV:}lockroot
91*a1a3b679SAndreas Boehler            }
92*a1a3b679SAndreas Boehler            $writer->writeElement('{DAV:}depth', ($lock->depth == DAV\Server::DEPTH_INFINITY ? 'infinity' : $lock->depth));
93*a1a3b679SAndreas Boehler            $writer->writeElement('{DAV:}timeout', 'Second-' . $lock->timeout);
94*a1a3b679SAndreas Boehler
95*a1a3b679SAndreas Boehler            $writer->startElement('{DAV:}locktoken');
96*a1a3b679SAndreas Boehler            $writer->writeElement('{DAV:}href', 'opaquelocktoken:' . $lock->token);
97*a1a3b679SAndreas Boehler            $writer->endElement(); // {DAV:}locktoken
98*a1a3b679SAndreas Boehler
99*a1a3b679SAndreas Boehler            $writer->writeElement('{DAV:}owner', new XmlFragment($lock->owner));
100*a1a3b679SAndreas Boehler            $writer->endElement(); // {DAV:}activelock
101*a1a3b679SAndreas Boehler
102*a1a3b679SAndreas Boehler        }
103*a1a3b679SAndreas Boehler
104*a1a3b679SAndreas Boehler    }
105*a1a3b679SAndreas Boehler
106*a1a3b679SAndreas Boehler}
107