1*a1a3b679SAndreas Boehler<?php 2*a1a3b679SAndreas Boehler 3*a1a3b679SAndreas Boehlernamespace Sabre\DAV\Xml\Request; 4*a1a3b679SAndreas Boehler 5*a1a3b679SAndreas Boehleruse Sabre\DAV\Locks\LockInfo; 6*a1a3b679SAndreas Boehleruse Sabre\Xml\Element\KeyValue; 7*a1a3b679SAndreas Boehleruse Sabre\Xml\Reader; 8*a1a3b679SAndreas Boehleruse Sabre\Xml\XmlDeserializable; 9*a1a3b679SAndreas Boehler 10*a1a3b679SAndreas Boehler/** 11*a1a3b679SAndreas Boehler * WebDAV LOCK request parser. 12*a1a3b679SAndreas Boehler * 13*a1a3b679SAndreas Boehler * This class parses the {DAV:}lockinfo request, as defined in: 14*a1a3b679SAndreas Boehler * 15*a1a3b679SAndreas Boehler * http://tools.ietf.org/html/rfc4918#section-9.10 16*a1a3b679SAndreas Boehler * 17*a1a3b679SAndreas Boehler * @copyright Copyright (C) 2007-2015 fruux GmbH (https://fruux.com/). 18*a1a3b679SAndreas Boehler * @author Evert Pot (http://evertpot.com/) 19*a1a3b679SAndreas Boehler * @license http://sabre.io/license/ Modified BSD License 20*a1a3b679SAndreas Boehler */ 21*a1a3b679SAndreas Boehlerclass Lock implements XmlDeserializable { 22*a1a3b679SAndreas Boehler 23*a1a3b679SAndreas Boehler /** 24*a1a3b679SAndreas Boehler * Owner of the lock 25*a1a3b679SAndreas Boehler * 26*a1a3b679SAndreas Boehler * @var string 27*a1a3b679SAndreas Boehler */ 28*a1a3b679SAndreas Boehler public $owner; 29*a1a3b679SAndreas Boehler 30*a1a3b679SAndreas Boehler /** 31*a1a3b679SAndreas Boehler * Scope of the lock. 32*a1a3b679SAndreas Boehler * 33*a1a3b679SAndreas Boehler * Either LockInfo::SHARED or LockInfo::EXCLUSIVE 34*a1a3b679SAndreas Boehler * @var int 35*a1a3b679SAndreas Boehler */ 36*a1a3b679SAndreas Boehler public $scope; 37*a1a3b679SAndreas Boehler 38*a1a3b679SAndreas Boehler /** 39*a1a3b679SAndreas Boehler * The deserialize method is called during xml parsing. 40*a1a3b679SAndreas Boehler * 41*a1a3b679SAndreas Boehler * This method is called statictly, this is because in theory this method 42*a1a3b679SAndreas Boehler * may be used as a type of constructor, or factory method. 43*a1a3b679SAndreas Boehler * 44*a1a3b679SAndreas Boehler * Often you want to return an instance of the current class, but you are 45*a1a3b679SAndreas Boehler * free to return other data as well. 46*a1a3b679SAndreas Boehler * 47*a1a3b679SAndreas Boehler * You are responsible for advancing the reader to the next element. Not 48*a1a3b679SAndreas Boehler * doing anything will result in a never-ending loop. 49*a1a3b679SAndreas Boehler * 50*a1a3b679SAndreas Boehler * If you just want to skip parsing for this element altogether, you can 51*a1a3b679SAndreas Boehler * just call $reader->next(); 52*a1a3b679SAndreas Boehler * 53*a1a3b679SAndreas Boehler * $reader->parseInnerTree() will parse the entire sub-tree, and advance to 54*a1a3b679SAndreas Boehler * the next element. 55*a1a3b679SAndreas Boehler * 56*a1a3b679SAndreas Boehler * @param Reader $reader 57*a1a3b679SAndreas Boehler * @return mixed 58*a1a3b679SAndreas Boehler */ 59*a1a3b679SAndreas Boehler static function xmlDeserialize(Reader $reader) { 60*a1a3b679SAndreas Boehler 61*a1a3b679SAndreas Boehler $reader->pushContext(); 62*a1a3b679SAndreas Boehler $reader->elementMap['{DAV:}owner'] = 'Sabre\\Xml\\Element\\XmlFragment'; 63*a1a3b679SAndreas Boehler 64*a1a3b679SAndreas Boehler $values = KeyValue::xmlDeserialize($reader); 65*a1a3b679SAndreas Boehler 66*a1a3b679SAndreas Boehler $reader->popContext(); 67*a1a3b679SAndreas Boehler 68*a1a3b679SAndreas Boehler $new = new self(); 69*a1a3b679SAndreas Boehler $new->owner = !empty($values['{DAV:}owner']) ? $values['{DAV:}owner']->getXml() : null; 70*a1a3b679SAndreas Boehler $new->scope = LockInfo::SHARED; 71*a1a3b679SAndreas Boehler 72*a1a3b679SAndreas Boehler if (isset($values['{DAV:}lockscope'])) { 73*a1a3b679SAndreas Boehler foreach ($values['{DAV:}lockscope'] as $elem) { 74*a1a3b679SAndreas Boehler if ($elem['name'] === '{DAV:}exclusive') $new->scope = LockInfo::EXCLUSIVE; 75*a1a3b679SAndreas Boehler } 76*a1a3b679SAndreas Boehler } 77*a1a3b679SAndreas Boehler return $new; 78*a1a3b679SAndreas Boehler 79*a1a3b679SAndreas Boehler } 80*a1a3b679SAndreas Boehler 81*a1a3b679SAndreas Boehler} 82