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