commit vendor

This commit is contained in:
2025-11-11 14:49:30 +01:00
parent f33121a308
commit 6d03080c00
2436 changed files with 483781 additions and 0 deletions

View File

@ -0,0 +1,110 @@
<?php
declare(strict_types=1);
namespace Sabre\DAV\Xml\Element;
use Sabre\DAV\Xml\Property\Complex;
use Sabre\Xml\Reader;
use Sabre\Xml\XmlDeserializable;
/**
* This class is responsible for decoding the {DAV:}prop element as it appears
* in {DAV:}property-update.
*
* This class doesn't return an instance of itself. It just returns a
* key->value array.
*
* @copyright Copyright (C) fruux GmbH (https://fruux.com/)
* @author Evert Pot (http://evertpot.com/)
* @license http://sabre.io/license/ Modified BSD License
*/
class Prop implements XmlDeserializable
{
/**
* The deserialize method is called during xml parsing.
*
* This method is called statically, this is because in theory this method
* may be used as a type of constructor, or factory method.
*
* Often you want to return an instance of the current class, but you are
* free to return other data as well.
*
* You are responsible for advancing the reader to the next element. Not
* doing anything will result in a never-ending loop.
*
* If you just want to skip parsing for this element altogether, you can
* just call $reader->next();
*
* $reader->parseInnerTree() will parse the entire sub-tree, and advance to
* the next element.
*
* @return mixed
*/
public static function xmlDeserialize(Reader $reader)
{
// If there's no children, we don't do anything.
if ($reader->isEmptyElement) {
$reader->next();
return [];
}
$values = [];
$reader->read();
do {
if (Reader::ELEMENT === $reader->nodeType) {
$clark = $reader->getClark();
$values[$clark] = self::parseCurrentElement($reader)['value'];
} else {
$reader->read();
}
} while (Reader::END_ELEMENT !== $reader->nodeType);
$reader->read();
return $values;
}
/**
* This function behaves similar to Sabre\Xml\Reader::parseCurrentElement,
* but instead of creating deep xml array structures, it will turn any
* top-level element it doesn't recognize into either a string, or an
* XmlFragment class.
*
* This method returns arn array with 2 properties:
* * name - A clark-notation XML element name.
* * value - The parsed value.
*
* @return array
*/
private static function parseCurrentElement(Reader $reader)
{
$name = $reader->getClark();
if (array_key_exists($name, $reader->elementMap)) {
$deserializer = $reader->elementMap[$name];
if (is_subclass_of($deserializer, 'Sabre\\Xml\\XmlDeserializable')) {
$value = call_user_func([$deserializer, 'xmlDeserialize'], $reader);
} elseif (is_callable($deserializer)) {
$value = call_user_func($deserializer, $reader);
} else {
$type = gettype($deserializer);
if ('string' === $type) {
$type .= ' ('.$deserializer.')';
} elseif ('object' === $type) {
$type .= ' ('.get_class($deserializer).')';
}
throw new \LogicException('Could not use this type as a deserializer: '.$type);
}
} else {
$value = Complex::xmlDeserialize($reader);
}
return [
'name' => $name,
'value' => $value,
];
}
}

View File

@ -0,0 +1,237 @@
<?php
declare(strict_types=1);
namespace Sabre\DAV\Xml\Element;
use Sabre\Xml\Element;
use Sabre\Xml\Reader;
use Sabre\Xml\Writer;
/**
* WebDAV {DAV:}response parser.
*
* This class parses the {DAV:}response element, as defined in:
*
* https://tools.ietf.org/html/rfc4918#section-14.24
*
* @copyright Copyright (C) fruux GmbH (https://fruux.com/)
* @author Evert Pot (http://www.rooftopsolutions.nl/)
* @license http://sabre.io/license/ Modified BSD License
*/
class Response implements Element
{
/**
* Url for the response.
*
* @var string
*/
protected $href;
/**
* Propertylist, ordered by HTTP status code.
*
* @var array
*/
protected $responseProperties;
/**
* The HTTP status for an entire response.
*
* This is currently only used in WebDAV-Sync
*
* @var string
*/
protected $httpStatus;
/**
* The href argument is a url relative to the root of the server. This
* class will calculate the full path.
*
* The responseProperties argument is a list of properties
* within an array with keys representing HTTP status codes
*
* Besides specific properties, the entire {DAV:}response element may also
* have a http status code.
* In most cases you don't need it.
*
* This is currently used by the Sync extension to indicate that a node is
* deleted.
*
* @param string $href
* @param string $httpStatus
*/
public function __construct($href, array $responseProperties, $httpStatus = null)
{
$this->href = $href;
$this->responseProperties = $responseProperties;
$this->httpStatus = $httpStatus;
}
/**
* Returns the url.
*
* @return string
*/
public function getHref()
{
return $this->href;
}
/**
* Returns the httpStatus value.
*
* @return string
*/
public function getHttpStatus()
{
return $this->httpStatus;
}
/**
* Returns the property list.
*
* @return array
*/
public function getResponseProperties()
{
return $this->responseProperties;
}
/**
* The serialize method is called during xml writing.
*
* It should use the $writer argument to encode this object into XML.
*
* Important note: it is not needed to create the parent element. The
* parent element is already created, and we only have to worry about
* attributes, child elements and text (if any).
*
* Important note 2: If you are writing any new elements, you are also
* responsible for closing them.
*/
public function xmlSerialize(Writer $writer)
{
if ($status = $this->getHTTPStatus()) {
$writer->writeElement('{DAV:}status', 'HTTP/1.1 '.$status.' '.\Sabre\HTTP\Response::$statusCodes[$status]);
}
$writer->writeElement('{DAV:}href', $writer->contextUri.\Sabre\HTTP\encodePath($this->getHref()));
$empty = true;
foreach ($this->getResponseProperties() as $status => $properties) {
// Skipping empty lists
if (!$properties || (!ctype_digit($status) && !is_int($status))) {
continue;
}
$empty = false;
$writer->startElement('{DAV:}propstat');
$writer->writeElement('{DAV:}prop', $properties);
$writer->writeElement('{DAV:}status', 'HTTP/1.1 '.$status.' '.\Sabre\HTTP\Response::$statusCodes[$status]);
$writer->endElement(); // {DAV:}propstat
}
if ($empty) {
/*
* The WebDAV spec _requires_ at least one DAV:propstat to appear for
* every DAV:response. In some circumstances however, there are no
* properties to encode.
*
* In those cases we MUST specify at least one DAV:propstat anyway, with
* no properties.
*/
$writer->writeElement('{DAV:}propstat', [
'{DAV:}prop' => [],
'{DAV:}status' => 'HTTP/1.1 418 '.\Sabre\HTTP\Response::$statusCodes[418],
]);
}
}
/**
* The deserialize method is called during xml parsing.
*
* This method is called statically, this is because in theory this method
* may be used as a type of constructor, or factory method.
*
* Often you want to return an instance of the current class, but you are
* free to return other data as well.
*
* You are responsible for advancing the reader to the next element. Not
* doing anything will result in a never-ending loop.
*
* If you just want to skip parsing for this element altogether, you can
* just call $reader->next();
*
* $reader->parseInnerTree() will parse the entire sub-tree, and advance to
* the next element.
*
* @return mixed
*/
public static function xmlDeserialize(Reader $reader)
{
$reader->pushContext();
$reader->elementMap['{DAV:}propstat'] = 'Sabre\\Xml\\Element\\KeyValue';
// We are overriding the parser for {DAV:}prop. This deserializer is
// almost identical to the one for Sabre\Xml\Element\KeyValue.
//
// The difference is that if there are any child-elements inside of
// {DAV:}prop, that have no value, normally any deserializers are
// called. But we don't want this, because a singular element without
// child-elements implies 'no value' in {DAV:}prop, so we want to skip
// deserializers and just set null for those.
$reader->elementMap['{DAV:}prop'] = function (Reader $reader) {
if ($reader->isEmptyElement) {
$reader->next();
return [];
}
$values = [];
$reader->read();
do {
if (Reader::ELEMENT === $reader->nodeType) {
$clark = $reader->getClark();
if ($reader->isEmptyElement) {
$values[$clark] = null;
$reader->next();
} else {
$values[$clark] = $reader->parseCurrentElement()['value'];
}
} else {
$reader->read();
}
} while (Reader::END_ELEMENT !== $reader->nodeType);
$reader->read();
return $values;
};
$elems = $reader->parseInnerTree();
$reader->popContext();
$href = null;
$propertyLists = [];
$statusCode = null;
foreach ($elems as $elem) {
switch ($elem['name']) {
case '{DAV:}href':
$href = $elem['value'];
break;
case '{DAV:}propstat':
$status = $elem['value']['{DAV:}status'];
list(, $status) = explode(' ', $status, 3);
$properties = isset($elem['value']['{DAV:}prop']) ? $elem['value']['{DAV:}prop'] : [];
if ($properties) {
$propertyLists[$status] = $properties;
}
break;
case '{DAV:}status':
list(, $statusCode) = explode(' ', $elem['value'], 3);
break;
}
}
return new self($href, $propertyLists, $statusCode);
}
}

View File

@ -0,0 +1,189 @@
<?php
declare(strict_types=1);
namespace Sabre\DAV\Xml\Element;
use Sabre\DAV\Exception\BadRequest;
use Sabre\DAV\Sharing\Plugin;
use Sabre\DAV\Xml\Property\Href;
use Sabre\DAV\Xml\Property\ShareAccess;
use Sabre\Xml\Deserializer;
use Sabre\Xml\Element;
use Sabre\Xml\Reader;
use Sabre\Xml\Writer;
/**
* This class represents the {DAV:}sharee element.
*
* @copyright Copyright (C) fruux GmbH. (https://fruux.com/)
* @author Evert Pot (http://evertpot.com/)
* @license http://sabre.io/license/ Modified BSD License
*/
class Sharee implements Element
{
/**
* A URL. Usually a mailto: address, could also be a principal url.
* This uniquely identifies the sharee.
*
* @var string
*/
public $href;
/**
* A local principal path. The server will do its best to locate the
* principal uri based on the given uri. If we could find a local matching
* principal uri, this property will contain the value.
*
* @var string|null
*/
public $principal;
/**
* A list of WebDAV properties that describe the sharee. This might for
* example contain a {DAV:}displayname with the real name of the user.
*
* @var array
*/
public $properties = [];
/**
* Share access level. One of the Sabre\DAV\Sharing\Plugin::ACCESS
* constants.
*
* Can be one of:
*
* ACCESS_READ
* ACCESS_READWRITE
* ACCESS_SHAREDOWNER
* ACCESS_NOACCESS
*
* depending on context.
*
* @var int
*/
public $access;
/**
* When a sharee is originally invited to a share, the sharer may add
* a comment. This will be placed in this property.
*
* @var string
*/
public $comment;
/**
* The status of the invite, should be one of the
* Sabre\DAV\Sharing\Plugin::INVITE constants.
*
* @var int
*/
public $inviteStatus;
/**
* Creates the object.
*
* $properties will be used to populate all internal properties.
*/
public function __construct(array $properties = [])
{
foreach ($properties as $k => $v) {
if (property_exists($this, $k)) {
$this->$k = $v;
} else {
throw new \InvalidArgumentException('Unknown property: '.$k);
}
}
}
/**
* The xmlSerialize method is called during xml writing.
*
* Use the $writer argument to write its own xml serialization.
*
* An important note: do _not_ create a parent element. Any element
* implementing XmlSerializable should only ever write what's considered
* its 'inner xml'.
*
* The parent of the current element is responsible for writing a
* containing element.
*
* This allows serializers to be re-used for different element names.
*
* If you are opening new elements, you must also close them again.
*/
public function xmlSerialize(Writer $writer)
{
$writer->write([
new Href($this->href),
'{DAV:}prop' => $this->properties,
'{DAV:}share-access' => new ShareAccess($this->access),
]);
switch ($this->inviteStatus) {
case Plugin::INVITE_NORESPONSE:
$writer->writeElement('{DAV:}invite-noresponse');
break;
case Plugin::INVITE_ACCEPTED:
$writer->writeElement('{DAV:}invite-accepted');
break;
case Plugin::INVITE_DECLINED:
$writer->writeElement('{DAV:}invite-declined');
break;
case Plugin::INVITE_INVALID:
$writer->writeElement('{DAV:}invite-invalid');
break;
}
}
/**
* The deserialize method is called during xml parsing.
*
* This method is called statically, this is because in theory this method
* may be used as a type of constructor, or factory method.
*
* Often you want to return an instance of the current class, but you are
* free to return other data as well.
*
* You are responsible for advancing the reader to the next element. Not
* doing anything will result in a never-ending loop.
*
* If you just want to skip parsing for this element altogether, you can
* just call $reader->next();
*
* $reader->parseInnerTree() will parse the entire sub-tree, and advance to
* the next element.
*
* @return mixed
*/
public static function xmlDeserialize(Reader $reader)
{
// Temporarily override configuration
$reader->pushContext();
$reader->elementMap['{DAV:}share-access'] = 'Sabre\DAV\Xml\Property\ShareAccess';
$reader->elementMap['{DAV:}prop'] = 'Sabre\Xml\Deserializer\keyValue';
$elems = Deserializer\keyValue($reader, 'DAV:');
// Restore previous configuration
$reader->popContext();
$sharee = new self();
if (!isset($elems['href'])) {
throw new BadRequest('Every {DAV:}sharee must have a {DAV:}href child-element');
}
$sharee->href = $elems['href'];
if (isset($elems['prop'])) {
$sharee->properties = $elems['prop'];
}
if (isset($elems['comment'])) {
$sharee->comment = $elems['comment'];
}
if (!isset($elems['share-access'])) {
throw new BadRequest('Every {DAV:}sharee must have a {DAV:}share-access child element');
}
$sharee->access = $elems['share-access']->getValue();
return $sharee;
}
}

View File

@ -0,0 +1,87 @@
<?php
declare(strict_types=1);
namespace Sabre\DAV\Xml\Property;
use Sabre\Xml\Element\XmlFragment;
use Sabre\Xml\Reader;
/**
* This class represents a 'complex' property that didn't have a default
* decoder.
*
* It's basically a container for an xml snippet.
*
* @copyright Copyright (C) fruux GmbH (https://fruux.com/)
* @author Evert Pot (http://evertpot.com/)
* @license http://sabre.io/license/ Modified BSD License
*/
class Complex extends XmlFragment
{
/**
* The deserialize method is called during xml parsing.
*
* This method is called statically, this is because in theory this method
* may be used as a type of constructor, or factory method.
*
* Often you want to return an instance of the current class, but you are
* free to return other data as well.
*
* You are responsible for advancing the reader to the next element. Not
* doing anything will result in a never-ending loop.
*
* If you just want to skip parsing for this element altogether, you can
* just call $reader->next();
*
* $reader->parseInnerTree() will parse the entire sub-tree, and advance to
* the next element.
*
* @return mixed
*/
public static function xmlDeserialize(Reader $reader)
{
$xml = $reader->readInnerXml();
if (Reader::ELEMENT === $reader->nodeType && $reader->isEmptyElement) {
// Easy!
$reader->next();
return null;
}
// Now we have a copy of the inner xml, we need to traverse it to get
// all the strings. If there's no non-string data, we just return the
// string, otherwise we return an instance of this class.
$reader->read();
$nonText = false;
$text = '';
while (true) {
switch ($reader->nodeType) {
case Reader::ELEMENT:
$nonText = true;
$reader->next();
continue 2;
case Reader::TEXT:
case Reader::CDATA:
$text .= $reader->value;
break;
case Reader::END_ELEMENT:
break 2;
}
$reader->read();
}
// Make sure we advance the cursor one step further.
$reader->read();
if ($nonText) {
$new = new self($xml);
return $new;
} else {
return $text;
}
}
}

View File

@ -0,0 +1,104 @@
<?php
declare(strict_types=1);
namespace Sabre\DAV\Xml\Property;
use DateTime;
use DateTimeZone;
use Sabre\HTTP;
use Sabre\Xml\Element;
use Sabre\Xml\Reader;
use Sabre\Xml\Writer;
/**
* This property represents the {DAV:}getlastmodified property.
*
* Defined in:
* http://tools.ietf.org/html/rfc4918#section-15.7
*
* @copyright Copyright (C) fruux GmbH (https://fruux.com/)
* @author Evert Pot (http://www.rooftopsolutions.nl/)
* @license http://sabre.io/license/ Modified BSD License
*/
class GetLastModified implements Element
{
/**
* time.
*
* @var DateTime
*/
public $time;
/**
* Constructor.
*
* @param int|DateTime $time
*/
public function __construct($time)
{
if ($time instanceof DateTime) {
$this->time = clone $time;
} else {
$this->time = new DateTime('@'.$time);
}
// Setting timezone to UTC
$this->time->setTimezone(new DateTimeZone('UTC'));
}
/**
* getTime.
*
* @return DateTime
*/
public function getTime()
{
return $this->time;
}
/**
* The serialize method is called during xml writing.
*
* It should use the $writer argument to encode this object into XML.
*
* Important note: it is not needed to create the parent element. The
* parent element is already created, and we only have to worry about
* attributes, child elements and text (if any).
*
* Important note 2: If you are writing any new elements, you are also
* responsible for closing them.
*/
public function xmlSerialize(Writer $writer)
{
$writer->write(
HTTP\toDate($this->time)
);
}
/**
* The deserialize method is called during xml parsing.
*
* This method is called statically, this is because in theory this method
* may be used as a type of constructor, or factory method.
*
* Often you want to return an instance of the current class, but you are
* free to return other data as well.
*
* Important note 2: You are responsible for advancing the reader to the
* next element. Not doing anything will result in a never-ending loop.
*
* If you just want to skip parsing for this element altogether, you can
* just call $reader->next();
*
* $reader->parseInnerTree() will parse the entire sub-tree, and advance to
* the next element.
*
* @return mixed
*/
public static function xmlDeserialize(Reader $reader)
{
return
new self(new DateTime($reader->parseInnerTree()));
}
}

View File

@ -0,0 +1,156 @@
<?php
declare(strict_types=1);
namespace Sabre\DAV\Xml\Property;
use Sabre\DAV\Browser\HtmlOutput;
use Sabre\DAV\Browser\HtmlOutputHelper;
use Sabre\Uri;
use Sabre\Xml\Element;
use Sabre\Xml\Reader;
use Sabre\Xml\Writer;
/**
* Href property.
*
* This class represents any WebDAV property that contains a {DAV:}href
* element, and there are many.
*
* It can support either 1 or more hrefs. If while unserializing no valid
* {DAV:}href elements were found, this property will unserialize itself as
* null.
*
* @copyright Copyright (C) fruux GmbH (https://fruux.com/)
* @author Evert Pot (http://www.rooftopsolutions.nl/)
* @license http://sabre.io/license/ Modified BSD License
*/
class Href implements Element, HtmlOutput
{
/**
* List of uris.
*
* @var array
*/
protected $hrefs;
/**
* Constructor.
*
* You must either pass a string for a single href, or an array of hrefs.
*
* If auto-prefix is set to false, the hrefs will be treated as absolute
* and not relative to the servers base uri.
*
* @param string|string[] $hrefs
*/
public function __construct($hrefs)
{
if (is_string($hrefs)) {
$hrefs = [$hrefs];
}
$this->hrefs = $hrefs;
}
/**
* Returns the first Href.
*
* @return string|null
*/
public function getHref()
{
return $this->hrefs[0] ?? null;
}
/**
* Returns the hrefs as an array.
*
* @return array
*/
public function getHrefs()
{
return $this->hrefs;
}
/**
* The xmlSerialize method is called during xml writing.
*
* Use the $writer argument to write its own xml serialization.
*
* An important note: do _not_ create a parent element. Any element
* implementing XmlSerializable should only ever write what's considered
* its 'inner xml'.
*
* The parent of the current element is responsible for writing a
* containing element.
*
* This allows serializers to be re-used for different element names.
*
* If you are opening new elements, you must also close them again.
*/
public function xmlSerialize(Writer $writer)
{
foreach ($this->getHrefs() as $href) {
$href = Uri\resolve($writer->contextUri, $href);
$writer->writeElement('{DAV:}href', $href);
}
}
/**
* Generate html representation for this value.
*
* The html output is 100% trusted, and no effort is being made to sanitize
* it. It's up to the implementor to sanitize user provided values.
*
* The output must be in UTF-8.
*
* The baseUri parameter is a url to the root of the application, and can
* be used to construct local links.
*
* @return string
*/
public function toHtml(HtmlOutputHelper $html)
{
$links = [];
foreach ($this->getHrefs() as $href) {
$links[] = $html->link($href);
}
return implode('<br />', $links);
}
/**
* The deserialize method is called during xml parsing.
*
* This method is called statically, this is because in theory this method
* may be used as a type of constructor, or factory method.
*
* Often you want to return an instance of the current class, but you are
* free to return other data as well.
*
* You are responsible for advancing the reader to the next element. Not
* doing anything will result in a never-ending loop.
*
* If you just want to skip parsing for this element altogether, you can
* just call $reader->next();
*
* $reader->parseInnerTree() will parse the entire sub-tree, and advance to
* the next element.
*
* @return mixed
*/
public static function xmlDeserialize(Reader $reader)
{
$hrefs = [];
foreach ((array) $reader->parseInnerTree() as $elem) {
if ('{DAV:}href' !== $elem['name']) {
continue;
}
$hrefs[] = $elem['value'];
}
if ($hrefs) {
return new self($hrefs);
}
}
}

View File

@ -0,0 +1,66 @@
<?php
declare(strict_types=1);
namespace Sabre\DAV\Xml\Property;
use Sabre\DAV\Xml\Element\Sharee;
use Sabre\Xml\Writer;
use Sabre\Xml\XmlSerializable;
/**
* This class represents the {DAV:}invite property.
*
* This property is defined here:
* https://tools.ietf.org/html/draft-pot-webdav-resource-sharing-03#section-4.4.2
*
* This property is used by clients to determine who currently has access to
* a shared resource, what their access level is and what their invite status
* is.
*
* @copyright Copyright (C) fruux GmbH (https://fruux.com/).
* @author Evert Pot (http://evertpot.com/)
* @license http://sabre.io/license/ Modified BSD License
*/
class Invite implements XmlSerializable
{
/**
* A list of sharees.
*
* @var Sharee[]
*/
public $sharees = [];
/**
* Creates the property.
*
* @param Sharee[] $sharees
*/
public function __construct(array $sharees)
{
$this->sharees = $sharees;
}
/**
* The xmlSerialize method is called during xml writing.
*
* Use the $writer argument to write its own xml serialization.
*
* An important note: do _not_ create a parent element. Any element
* implementing XmlSerializable should only ever write what's considered
* its 'inner xml'.
*
* The parent of the current element is responsible for writing a
* containing element.
*
* This allows serializers to be re-used for different element names.
*
* If you are opening new elements, you must also close them again.
*/
public function xmlSerialize(Writer $writer)
{
foreach ($this->sharees as $sharee) {
$writer->writeElement('{DAV:}sharee', $sharee);
}
}
}

View File

@ -0,0 +1,48 @@
<?php
declare(strict_types=1);
namespace Sabre\DAV\Xml\Property;
use Sabre\HTTP;
/**
* LocalHref property.
*
* Like the Href property, this element represents {DAV:}href. The difference
* is that this is used strictly for paths on the server. The LocalHref property
* will prepare the path so it's a valid URI.
*
* These two objects behave identically:
* new LocalHref($path)
* new Href(\Sabre\HTTP\encodePath($path))
*
* LocalPath basically ensures that your spaces are %20, and everything that
* needs to be is uri encoded.
*
* @copyright Copyright (C) fruux GmbH (https://fruux.com/)
* @author Evert Pot (http://www.rooftopsolutions.nl/)
* @license http://sabre.io/license/ Modified BSD License
*/
class LocalHref extends Href
{
/**
* Constructor.
*
* You must either pass a string for a single href, or an array of hrefs.
*
* If auto-prefix is set to false, the hrefs will be treated as absolute
* and not relative to the servers base uri.
*
* @param string|string[] $hrefs
*/
public function __construct($hrefs)
{
parent::__construct(array_map(
function ($href) {
return \Sabre\HTTP\encodePath($href);
},
(array) $hrefs
));
}
}

View File

@ -0,0 +1,105 @@
<?php
declare(strict_types=1);
namespace Sabre\DAV\Xml\Property;
use Sabre\DAV;
use Sabre\DAV\Locks\LockInfo;
use Sabre\Xml\Element\XmlFragment;
use Sabre\Xml\Writer;
use Sabre\Xml\XmlSerializable;
/**
* Represents {DAV:}lockdiscovery property.
*
* This property is defined here:
* http://tools.ietf.org/html/rfc4918#section-15.8
*
* This property contains all the open locks on a given resource
*
* @copyright Copyright (C) fruux GmbH (https://fruux.com/)
* @author Evert Pot (http://www.rooftopsolutions.nl/)
* @license http://sabre.io/license/ Modified BSD License
*/
class LockDiscovery implements XmlSerializable
{
/**
* locks.
*
* @var LockInfo[]
*/
public $locks;
/**
* Hides the {DAV:}lockroot element from the response.
*
* It was reported that showing the lockroot in the response can break
* Office 2000 compatibility.
*
* @var bool
*/
public static $hideLockRoot = false;
/**
* __construct.
*
* @param LockInfo[] $locks
*/
public function __construct($locks)
{
$this->locks = $locks;
}
/**
* The serialize method is called during xml writing.
*
* It should use the $writer argument to encode this object into XML.
*
* Important note: it is not needed to create the parent element. The
* parent element is already created, and we only have to worry about
* attributes, child elements and text (if any).
*
* Important note 2: If you are writing any new elements, you are also
* responsible for closing them.
*/
public function xmlSerialize(Writer $writer)
{
foreach ($this->locks as $lock) {
$writer->startElement('{DAV:}activelock');
$writer->startElement('{DAV:}lockscope');
if (LockInfo::SHARED === $lock->scope) {
$writer->writeElement('{DAV:}shared');
} else {
$writer->writeElement('{DAV:}exclusive');
}
$writer->endElement(); // {DAV:}lockscope
$writer->startElement('{DAV:}locktype');
$writer->writeElement('{DAV:}write');
$writer->endElement(); // {DAV:}locktype
if (!self::$hideLockRoot) {
$writer->startElement('{DAV:}lockroot');
$writer->writeElement('{DAV:}href', $writer->contextUri.$lock->uri);
$writer->endElement(); // {DAV:}lockroot
}
$writer->writeElement('{DAV:}depth', (DAV\Server::DEPTH_INFINITY == $lock->depth ? 'infinity' : $lock->depth));
$writer->writeElement('{DAV:}timeout', (LockInfo::TIMEOUT_INFINITE === $lock->timeout ? 'Infinite' : 'Second-'.$lock->timeout));
// optional according to https://tools.ietf.org/html/rfc4918#section-6.5
if (null !== $lock->token && '' !== $lock->token) {
$writer->startElement('{DAV:}locktoken');
$writer->writeElement('{DAV:}href', 'opaquelocktoken:'.$lock->token);
$writer->endElement(); // {DAV:}locktoken
}
if ($lock->owner) {
$writer->writeElement('{DAV:}owner', new XmlFragment($lock->owner));
}
$writer->endElement(); // {DAV:}activelock
}
}
}

View File

@ -0,0 +1,121 @@
<?php
declare(strict_types=1);
namespace Sabre\DAV\Xml\Property;
use Sabre\DAV\Browser\HtmlOutput;
use Sabre\DAV\Browser\HtmlOutputHelper;
use Sabre\Xml\Element;
use Sabre\Xml\Reader;
/**
* {DAV:}resourcetype property.
*
* This class represents the {DAV:}resourcetype property, as defined in:
*
* https://tools.ietf.org/html/rfc4918#section-15.9
*
* @copyright Copyright (C) fruux GmbH (https://fruux.com/)
* @author Evert Pot (http://evertpot.com/)
* @license http://sabre.io/license/ Modified BSD License
*/
class ResourceType extends Element\Elements implements HtmlOutput
{
/**
* Constructor.
*
* You can either pass null (for no resourcetype), a string (for a single
* resourcetype) or an array (for multiple).
*
* The resourcetype must be specified in clark-notation
*
* @param array|string|null $resourceTypes
*/
public function __construct($resourceTypes = null)
{
parent::__construct((array) $resourceTypes);
}
/**
* Returns the values in clark-notation.
*
* For example array('{DAV:}collection')
*
* @return array
*/
public function getValue()
{
return $this->value;
}
/**
* Checks if the principal contains a certain value.
*
* @param string $type
*
* @return bool
*/
public function is($type)
{
return in_array($type, $this->value);
}
/**
* Adds a resourcetype value to this property.
*
* @param string $type
*/
public function add($type)
{
$this->value[] = $type;
$this->value = array_unique($this->value);
}
/**
* The deserialize method is called during xml parsing.
*
* This method is called statically, this is because in theory this method
* may be used as a type of constructor, or factory method.
*
* Often you want to return an instance of the current class, but you are
* free to return other data as well.
*
* Important note 2: You are responsible for advancing the reader to the
* next element. Not doing anything will result in a never-ending loop.
*
* If you just want to skip parsing for this element altogether, you can
* just call $reader->next();
*
* $reader->parseInnerTree() will parse the entire sub-tree, and advance to
* the next element.
*
* @return mixed
*/
public static function xmlDeserialize(Reader $reader)
{
return
new self(parent::xmlDeserialize($reader));
}
/**
* Generate html representation for this value.
*
* The html output is 100% trusted, and no effort is being made to sanitize
* it. It's up to the implementor to sanitize user provided values.
*
* The output must be in UTF-8.
*
* The baseUri parameter is a url to the root of the application, and can
* be used to construct local links.
*
* @return string
*/
public function toHtml(HtmlOutputHelper $html)
{
return implode(
', ',
array_map([$html, 'xmlName'], $this->getValue())
);
}
}

View File

@ -0,0 +1,135 @@
<?php
declare(strict_types=1);
namespace Sabre\DAV\Xml\Property;
use Sabre\DAV\Exception\BadRequest;
use Sabre\DAV\Sharing\Plugin as SharingPlugin;
use Sabre\Xml\Element;
use Sabre\Xml\Reader;
use Sabre\Xml\Writer;
/**
* This class represents the {DAV:}share-access property.
*
* This property is defined here:
* https://tools.ietf.org/html/draft-pot-webdav-resource-sharing-03#section-4.4.1
*
* This property is used to indicate if a resource is a shared resource, and
* whether the instance of the shared resource is the original instance, or
* an instance belonging to a sharee.
*
* @copyright Copyright (C) fruux GmbH (https://fruux.com/).
* @author Evert Pot (http://evertpot.com/)
* @license http://sabre.io/license/ Modified BSD License
*/
class ShareAccess implements Element
{
/**
* Either SHARED or SHAREDOWNER.
*
* @var int
*/
protected $value;
/**
* Creates the property.
*
* The constructor value must be one of the
* \Sabre\DAV\Sharing\Plugin::ACCESS_ constants.
*
* @param int $shareAccess
*/
public function __construct($shareAccess)
{
$this->value = $shareAccess;
}
/**
* Returns the current value.
*
* @return int
*/
public function getValue()
{
return $this->value;
}
/**
* The xmlSerialize method is called during xml writing.
*
* Use the $writer argument to write its own xml serialization.
*
* An important note: do _not_ create a parent element. Any element
* implementing XmlSerializable should only ever write what's considered
* its 'inner xml'.
*
* The parent of the current element is responsible for writing a
* containing element.
*
* This allows serializers to be re-used for different element names.
*
* If you are opening new elements, you must also close them again.
*/
public function xmlSerialize(Writer $writer)
{
switch ($this->value) {
case SharingPlugin::ACCESS_NOTSHARED:
$writer->writeElement('{DAV:}not-shared');
break;
case SharingPlugin::ACCESS_SHAREDOWNER:
$writer->writeElement('{DAV:}shared-owner');
break;
case SharingPlugin::ACCESS_READ:
$writer->writeElement('{DAV:}read');
break;
case SharingPlugin::ACCESS_READWRITE:
$writer->writeElement('{DAV:}read-write');
break;
case SharingPlugin::ACCESS_NOACCESS:
$writer->writeElement('{DAV:}no-access');
break;
}
}
/**
* The deserialize method is called during xml parsing.
*
* This method is called statically, this is because in theory this method
* may be used as a type of constructor, or factory method.
*
* Often you want to return an instance of the current class, but you are
* free to return other data as well.
*
* You are responsible for advancing the reader to the next element. Not
* doing anything will result in a never-ending loop.
*
* If you just want to skip parsing for this element altogether, you can
* just call $reader->next();
*
* $reader->parseInnerTree() will parse the entire sub-tree, and advance to
* the next element.
*
* @return mixed
*/
public static function xmlDeserialize(Reader $reader)
{
$elems = $reader->parseInnerTree();
foreach ($elems as $elem) {
switch ($elem['name']) {
case '{DAV:}not-shared':
return new self(SharingPlugin::ACCESS_NOTSHARED);
case '{DAV:}shared-owner':
return new self(SharingPlugin::ACCESS_SHAREDOWNER);
case '{DAV:}read':
return new self(SharingPlugin::ACCESS_READ);
case '{DAV:}read-write':
return new self(SharingPlugin::ACCESS_READWRITE);
case '{DAV:}no-access':
return new self(SharingPlugin::ACCESS_NOACCESS);
}
}
throw new BadRequest('Invalid value for {DAV:}share-access element');
}
}

View File

@ -0,0 +1,52 @@
<?php
declare(strict_types=1);
namespace Sabre\DAV\Xml\Property;
use Sabre\Xml\Writer;
use Sabre\Xml\XmlSerializable;
/**
* This class represents the {DAV:}supportedlock property.
*
* This property is defined here:
* http://tools.ietf.org/html/rfc4918#section-15.10
*
* This property contains information about what kind of locks
* this server supports.
*
* @copyright Copyright (C) fruux GmbH (https://fruux.com/)
* @author Evert Pot (http://www.rooftopsolutions.nl/)
* @license http://sabre.io/license/ Modified BSD License
*/
class SupportedLock implements XmlSerializable
{
/**
* The xmlSerialize method is called during xml writing.
*
* Use the $writer argument to write its own xml serialization.
*
* An important note: do _not_ create a parent element. Any element
* implementing XmlSerializable should only ever write what's considered
* its 'inner xml'.
*
* The parent of the current element is responsible for writing a
* containing element.
*
* This allows serializers to be re-used for different element names.
*
* If you are opening new elements, you must also close them again.
*/
public function xmlSerialize(Writer $writer)
{
$writer->writeElement('{DAV:}lockentry', [
'{DAV:}lockscope' => ['{DAV:}exclusive' => null],
'{DAV:}locktype' => ['{DAV:}write' => null],
]);
$writer->writeElement('{DAV:}lockentry', [
'{DAV:}lockscope' => ['{DAV:}shared' => null],
'{DAV:}locktype' => ['{DAV:}write' => null],
]);
}
}

View File

@ -0,0 +1,114 @@
<?php
declare(strict_types=1);
namespace Sabre\DAV\Xml\Property;
use Sabre\DAV\Browser\HtmlOutput;
use Sabre\DAV\Browser\HtmlOutputHelper;
use Sabre\Xml\Writer;
use Sabre\Xml\XmlSerializable;
/**
* supported-method-set property.
*
* This property is defined in RFC3253, but since it's
* so common in other webdav-related specs, it is part of the core server.
*
* This property is defined here:
* http://tools.ietf.org/html/rfc3253#section-3.1.3
*
* @copyright Copyright (C) fruux GmbH (https://fruux.com/)
* @author Evert Pot (http://evertpot.com/)
* @license http://sabre.io/license/ Modified BSD License
*/
class SupportedMethodSet implements XmlSerializable, HtmlOutput
{
/**
* List of methods.
*
* @var string[]
*/
protected $methods = [];
/**
* Creates the property.
*
* @param string[] $methods
*/
public function __construct(array $methods)
{
$this->methods = $methods;
}
/**
* Returns the list of supported http methods.
*
* @return string[]
*/
public function getValue()
{
return $this->methods;
}
/**
* Returns true or false if the property contains a specific method.
*
* @param string $methodName
*
* @return bool
*/
public function has($methodName)
{
return in_array(
$methodName,
$this->methods
);
}
/**
* The xmlSerialize method is called during xml writing.
*
* Use the $writer argument to write its own xml serialization.
*
* An important note: do _not_ create a parent element. Any element
* implementing XmlSerializable should only ever write what's considered
* its 'inner xml'.
*
* The parent of the current element is responsible for writing a
* containing element.
*
* This allows serializers to be re-used for different element names.
*
* If you are opening new elements, you must also close them again.
*/
public function xmlSerialize(Writer $writer)
{
foreach ($this->getValue() as $val) {
$writer->startElement('{DAV:}supported-method');
$writer->writeAttribute('name', $val);
$writer->endElement();
}
}
/**
* Generate html representation for this value.
*
* The html output is 100% trusted, and no effort is being made to sanitize
* it. It's up to the implementor to sanitize user provided values.
*
* The output must be in UTF-8.
*
* The baseUri parameter is a url to the root of the application, and can
* be used to construct local links.
*
* @return string
*/
public function toHtml(HtmlOutputHelper $html)
{
return implode(
', ',
array_map([$html, 'h'], $this->getValue())
);
}
}

View File

@ -0,0 +1,144 @@
<?php
declare(strict_types=1);
namespace Sabre\DAV\Xml\Property;
use Sabre\DAV;
use Sabre\DAV\Browser\HtmlOutput;
use Sabre\DAV\Browser\HtmlOutputHelper;
use Sabre\Xml\Writer;
use Sabre\Xml\XmlSerializable;
/**
* supported-report-set property.
*
* This property is defined in RFC3253, but since it's
* so common in other webdav-related specs, it is part of the core server.
*
* This property is defined here:
* http://tools.ietf.org/html/rfc3253#section-3.1.5
*
* @copyright Copyright (C) fruux GmbH (https://fruux.com/)
* @author Evert Pot (http://www.rooftopsolutions.nl/)
* @license http://sabre.io/license/ Modified BSD License
*/
class SupportedReportSet implements XmlSerializable, HtmlOutput
{
/**
* List of reports.
*
* @var array
*/
protected $reports = [];
/**
* Creates the property.
*
* Any reports passed in the constructor
* should be valid report-types in clark-notation.
*
* Either a string or an array of strings must be passed.
*
* @param string|string[] $reports
*/
public function __construct($reports = null)
{
if (!is_null($reports)) {
$this->addReport($reports);
}
}
/**
* Adds a report to this property.
*
* The report must be a string in clark-notation.
* Multiple reports can be specified as an array.
*
* @param mixed $report
*/
public function addReport($report)
{
$report = (array) $report;
foreach ($report as $r) {
if (!preg_match('/^{([^}]*)}(.*)$/', $r)) {
throw new DAV\Exception('Reportname must be in clark-notation');
}
$this->reports[] = $r;
}
}
/**
* Returns the list of supported reports.
*
* @return string[]
*/
public function getValue()
{
return $this->reports;
}
/**
* Returns true or false if the property contains a specific report.
*
* @param string $reportName
*
* @return bool
*/
public function has($reportName)
{
return in_array(
$reportName,
$this->reports
);
}
/**
* The xmlSerialize method is called during xml writing.
*
* Use the $writer argument to write its own xml serialization.
*
* An important note: do _not_ create a parent element. Any element
* implementing XmlSerializable should only ever write what's considered
* its 'inner xml'.
*
* The parent of the current element is responsible for writing a
* containing element.
*
* This allows serializers to be re-used for different element names.
*
* If you are opening new elements, you must also close them again.
*/
public function xmlSerialize(Writer $writer)
{
foreach ($this->getValue() as $val) {
$writer->startElement('{DAV:}supported-report');
$writer->startElement('{DAV:}report');
$writer->writeElement($val);
$writer->endElement();
$writer->endElement();
}
}
/**
* Generate html representation for this value.
*
* The html output is 100% trusted, and no effort is being made to sanitize
* it. It's up to the implementor to sanitize user provided values.
*
* The output must be in UTF-8.
*
* The baseUri parameter is a url to the root of the application, and can
* be used to construct local links.
*
* @return string
*/
public function toHtml(HtmlOutputHelper $html)
{
return implode(
', ',
array_map([$html, 'xmlName'], $this->getValue())
);
}
}

View File

@ -0,0 +1,84 @@
<?php
declare(strict_types=1);
namespace Sabre\DAV\Xml\Request;
use Sabre\DAV\Locks\LockInfo;
use Sabre\Xml\Element\KeyValue;
use Sabre\Xml\Reader;
use Sabre\Xml\XmlDeserializable;
/**
* WebDAV LOCK request parser.
*
* This class parses the {DAV:}lockinfo request, as defined in:
*
* http://tools.ietf.org/html/rfc4918#section-9.10
*
* @copyright Copyright (C) fruux GmbH (https://fruux.com/)
* @author Evert Pot (http://evertpot.com/)
* @license http://sabre.io/license/ Modified BSD License
*/
class Lock implements XmlDeserializable
{
/**
* Owner of the lock.
*
* @var string
*/
public $owner;
/**
* Scope of the lock.
*
* Either LockInfo::SHARED or LockInfo::EXCLUSIVE
*
* @var int
*/
public $scope;
/**
* The deserialize method is called during xml parsing.
*
* This method is called statically, this is because in theory this method
* may be used as a type of constructor, or factory method.
*
* Often you want to return an instance of the current class, but you are
* free to return other data as well.
*
* You are responsible for advancing the reader to the next element. Not
* doing anything will result in a never-ending loop.
*
* If you just want to skip parsing for this element altogether, you can
* just call $reader->next();
*
* $reader->parseInnerTree() will parse the entire sub-tree, and advance to
* the next element.
*
* @return mixed
*/
public static function xmlDeserialize(Reader $reader)
{
$reader->pushContext();
$reader->elementMap['{DAV:}owner'] = 'Sabre\\Xml\\Element\\XmlFragment';
$values = KeyValue::xmlDeserialize($reader);
$reader->popContext();
$new = new self();
$new->owner = !empty($values['{DAV:}owner']) ? $values['{DAV:}owner']->getXml() : null;
$new->scope = LockInfo::SHARED;
if (isset($values['{DAV:}lockscope'])) {
foreach ($values['{DAV:}lockscope'] as $elem) {
if ('{DAV:}exclusive' === $elem['name']) {
$new->scope = LockInfo::EXCLUSIVE;
}
}
}
return $new;
}
}

View File

@ -0,0 +1,80 @@
<?php
declare(strict_types=1);
namespace Sabre\DAV\Xml\Request;
use Sabre\Xml\Reader;
use Sabre\Xml\XmlDeserializable;
/**
* WebDAV Extended MKCOL request parser.
*
* This class parses the {DAV:}mkol request, as defined in:
*
* https://tools.ietf.org/html/rfc5689#section-5.1
*
* @copyright Copyright (C) fruux GmbH (https://fruux.com/)
* @author Evert Pot (http://evertpot.com/)
* @license http://sabre.io/license/ Modified BSD License
*/
class MkCol implements XmlDeserializable
{
/**
* The list of properties that will be set.
*
* @var array
*/
protected $properties = [];
/**
* Returns a key=>value array with properties that are supposed to get set
* during creation of the new collection.
*
* @return array
*/
public function getProperties()
{
return $this->properties;
}
/**
* The deserialize method is called during xml parsing.
*
* This method is called statically, this is because in theory this method
* may be used as a type of constructor, or factory method.
*
* Often you want to return an instance of the current class, but you are
* free to return other data as well.
*
* You are responsible for advancing the reader to the next element. Not
* doing anything will result in a never-ending loop.
*
* If you just want to skip parsing for this element altogether, you can
* just call $reader->next();
*
* $reader->parseInnerTree() will parse the entire sub-tree, and advance to
* the next element.
*
* @return mixed
*/
public static function xmlDeserialize(Reader $reader)
{
$self = new self();
$elementMap = $reader->elementMap;
$elementMap['{DAV:}prop'] = 'Sabre\DAV\Xml\Element\Prop';
$elementMap['{DAV:}set'] = 'Sabre\Xml\Element\KeyValue';
$elementMap['{DAV:}remove'] = 'Sabre\Xml\Element\KeyValue';
$elems = $reader->parseInnerTree($elementMap);
foreach ($elems as $elem) {
if ('{DAV:}set' === $elem['name']) {
$self->properties = array_merge($self->properties, $elem['value']['{DAV:}prop']);
}
}
return $self;
}
}

View File

@ -0,0 +1,79 @@
<?php
declare(strict_types=1);
namespace Sabre\DAV\Xml\Request;
use Sabre\Xml\Element\KeyValue;
use Sabre\Xml\Reader;
use Sabre\Xml\XmlDeserializable;
/**
* WebDAV PROPFIND request parser.
*
* This class parses the {DAV:}propfind request, as defined in:
*
* https://tools.ietf.org/html/rfc4918#section-14.20
*
* @copyright Copyright (C) fruux GmbH (https://fruux.com/)
* @author Evert Pot (http://www.rooftopsolutions.nl/)
* @license http://sabre.io/license/ Modified BSD License
*/
class PropFind implements XmlDeserializable
{
/**
* If this is set to true, this was an 'allprop' request.
*
* @var bool
*/
public $allProp = false;
/**
* The property list.
*
* @var array|null
*/
public $properties;
/**
* The deserialize method is called during xml parsing.
*
* This method is called statically, this is because in theory this method
* may be used as a type of constructor, or factory method.
*
* Often you want to return an instance of the current class, but you are
* free to return other data as well.
*
* You are responsible for advancing the reader to the next element. Not
* doing anything will result in a never-ending loop.
*
* If you just want to skip parsing for this element altogether, you can
* just call $reader->next();
*
* $reader->parseInnerTree() will parse the entire sub-tree, and advance to
* the next element.
*
* @return mixed
*/
public static function xmlDeserialize(Reader $reader)
{
$self = new self();
$reader->pushContext();
$reader->elementMap['{DAV:}prop'] = 'Sabre\Xml\Element\Elements';
foreach (KeyValue::xmlDeserialize($reader) as $k => $v) {
switch ($k) {
case '{DAV:}prop':
$self->properties = $v;
break;
case '{DAV:}allprop':
$self->allProp = true;
}
}
$reader->popContext();
return $self;
}
}

View File

@ -0,0 +1,109 @@
<?php
declare(strict_types=1);
namespace Sabre\DAV\Xml\Request;
use Sabre\Xml\Element;
use Sabre\Xml\Reader;
use Sabre\Xml\Writer;
/**
* WebDAV PROPPATCH request parser.
*
* This class parses the {DAV:}propertyupdate request, as defined in:
*
* https://tools.ietf.org/html/rfc4918#section-14.20
*
* @copyright Copyright (C) fruux GmbH (https://fruux.com/)
* @author Evert Pot (http://www.rooftopsolutions.nl/)
* @license http://sabre.io/license/ Modified BSD License
*/
class PropPatch implements Element
{
/**
* The list of properties that will be updated and removed.
*
* If a property will be removed, it's value will be set to null.
*
* @var array
*/
public $properties = [];
/**
* The xmlSerialize method is called during xml writing.
*
* Use the $writer argument to write its own xml serialization.
*
* An important note: do _not_ create a parent element. Any element
* implementing XmlSerializable should only ever write what's considered
* its 'inner xml'.
*
* The parent of the current element is responsible for writing a
* containing element.
*
* This allows serializers to be re-used for different element names.
*
* If you are opening new elements, you must also close them again.
*/
public function xmlSerialize(Writer $writer)
{
foreach ($this->properties as $propertyName => $propertyValue) {
if (is_null($propertyValue)) {
$writer->startElement('{DAV:}remove');
$writer->write(['{DAV:}prop' => [$propertyName => $propertyValue]]);
$writer->endElement();
} else {
$writer->startElement('{DAV:}set');
$writer->write(['{DAV:}prop' => [$propertyName => $propertyValue]]);
$writer->endElement();
}
}
}
/**
* The deserialize method is called during xml parsing.
*
* This method is called statically, this is because in theory this method
* may be used as a type of constructor, or factory method.
*
* Often you want to return an instance of the current class, but you are
* free to return other data as well.
*
* You are responsible for advancing the reader to the next element. Not
* doing anything will result in a never-ending loop.
*
* If you just want to skip parsing for this element altogether, you can
* just call $reader->next();
*
* $reader->parseInnerTree() will parse the entire sub-tree, and advance to
* the next element.
*
* @return mixed
*/
public static function xmlDeserialize(Reader $reader)
{
$self = new self();
$elementMap = $reader->elementMap;
$elementMap['{DAV:}prop'] = 'Sabre\DAV\Xml\Element\Prop';
$elementMap['{DAV:}set'] = 'Sabre\Xml\Element\KeyValue';
$elementMap['{DAV:}remove'] = 'Sabre\Xml\Element\KeyValue';
$elems = $reader->parseInnerTree($elementMap);
foreach ($elems as $elem) {
if ('{DAV:}set' === $elem['name']) {
$self->properties = array_merge($self->properties, $elem['value']['{DAV:}prop']);
}
if ('{DAV:}remove' === $elem['name']) {
// Ensuring there are no values.
foreach ($elem['value']['{DAV:}prop'] as $remove => $value) {
$self->properties[$remove] = null;
}
}
}
return $self;
}
}

View File

@ -0,0 +1,80 @@
<?php
declare(strict_types=1);
namespace Sabre\DAV\Xml\Request;
use Sabre\DAV\Xml\Element\Sharee;
use Sabre\Xml\Reader;
use Sabre\Xml\XmlDeserializable;
/**
* ShareResource request parser.
*
* This class parses the {DAV:}share-resource POST request as defined in:
*
* https://tools.ietf.org/html/draft-pot-webdav-resource-sharing-01#section-5.3.2.1
*
* @copyright Copyright (C) 2007-2015 fruux GmbH (https://fruux.com/).
* @author Evert Pot (http://www.rooftopsolutions.nl/)
* @license http://sabre.io/license/ Modified BSD License
*/
class ShareResource implements XmlDeserializable
{
/**
* The list of new people added or updated or removed from the share.
*
* @var Sharee[]
*/
public $sharees = [];
/**
* Constructor.
*
* @param Sharee[] $sharees
*/
public function __construct(array $sharees)
{
$this->sharees = $sharees;
}
/**
* The deserialize method is called during xml parsing.
*
* This method is called statically, this is because in theory this method
* may be used as a type of constructor, or factory method.
*
* Often you want to return an instance of the current class, but you are
* free to return other data as well.
*
* You are responsible for advancing the reader to the next element. Not
* doing anything will result in a never-ending loop.
*
* If you just want to skip parsing for this element altogether, you can
* just call $reader->next();
*
* $reader->parseInnerTree() will parse the entire sub-tree, and advance to
* the next element.
*
* @return mixed
*/
public static function xmlDeserialize(Reader $reader)
{
$elems = $reader->parseInnerTree([
'{DAV:}sharee' => 'Sabre\DAV\Xml\Element\Sharee',
'{DAV:}share-access' => 'Sabre\DAV\Xml\Property\ShareAccess',
'{DAV:}prop' => 'Sabre\Xml\Deserializer\keyValue',
]);
$sharees = [];
foreach ($elems as $elem) {
if ('{DAV:}sharee' !== $elem['name']) {
continue;
}
$sharees[] = $elem['value'];
}
return new self($sharees);
}
}

View File

@ -0,0 +1,118 @@
<?php
declare(strict_types=1);
namespace Sabre\DAV\Xml\Request;
use Sabre\DAV\Exception\BadRequest;
use Sabre\Xml\Element\KeyValue;
use Sabre\Xml\Reader;
use Sabre\Xml\XmlDeserializable;
/**
* SyncCollection request parser.
*
* This class parses the {DAV:}sync-collection reprot, as defined in:
*
* http://tools.ietf.org/html/rfc6578#section-3.2
*
* @copyright Copyright (C) fruux GmbH (https://fruux.com/)
* @author Evert Pot (http://www.rooftopsolutions.nl/)
* @license http://sabre.io/license/ Modified BSD License
*/
class SyncCollectionReport implements XmlDeserializable
{
/**
* The sync-token the client supplied for the report.
*
* @var string|null
*/
public $syncToken;
/**
* The 'depth' of the sync the client is interested in.
*
* @var int
*/
public $syncLevel;
/**
* Maximum amount of items returned.
*
* @var int|null
*/
public $limit;
/**
* The list of properties that are being requested for every change.
*
* @var array|null
*/
public $properties;
/**
* The deserialize method is called during xml parsing.
*
* This method is called statically, this is because in theory this method
* may be used as a type of constructor, or factory method.
*
* Often you want to return an instance of the current class, but you are
* free to return other data as well.
*
* You are responsible for advancing the reader to the next element. Not
* doing anything will result in a never-ending loop.
*
* If you just want to skip parsing for this element altogether, you can
* just call $reader->next();
*
* $reader->parseInnerTree() will parse the entire sub-tree, and advance to
* the next element.
*
* @return mixed
*/
public static function xmlDeserialize(Reader $reader)
{
$self = new self();
$reader->pushContext();
$reader->elementMap['{DAV:}prop'] = 'Sabre\Xml\Element\Elements';
$elems = KeyValue::xmlDeserialize($reader);
$reader->popContext();
$required = [
'{DAV:}sync-token',
'{DAV:}prop',
];
foreach ($required as $elem) {
if (!array_key_exists($elem, $elems)) {
throw new BadRequest('The '.$elem.' element in the {DAV:}sync-collection report is required');
}
}
$self->properties = $elems['{DAV:}prop'];
$self->syncToken = $elems['{DAV:}sync-token'];
if (isset($elems['{DAV:}limit'])) {
$nresults = null;
foreach ($elems['{DAV:}limit'] as $child) {
if ('{DAV:}nresults' === $child['name']) {
$nresults = (int) $child['value'];
}
}
$self->limit = $nresults;
}
if (isset($elems['{DAV:}sync-level'])) {
$value = $elems['{DAV:}sync-level'];
if ('infinity' === $value) {
$value = \Sabre\DAV\Server::DEPTH_INFINITY;
}
$self->syncLevel = $value;
}
return $self;
}
}

View File

@ -0,0 +1,136 @@
<?php
declare(strict_types=1);
namespace Sabre\DAV\Xml\Response;
use Sabre\Xml\Element;
use Sabre\Xml\Reader;
use Sabre\Xml\Writer;
/**
* WebDAV MultiStatus parser.
*
* This class parses the {DAV:}multistatus response, as defined in:
* https://tools.ietf.org/html/rfc4918#section-14.16
*
* And it also adds the {DAV:}synctoken change from:
* http://tools.ietf.org/html/rfc6578#section-6.4
*
* @copyright Copyright (C) fruux GmbH (https://fruux.com/)
* @author Evert Pot (http://evertpot.com/)
* @license http://sabre.io/license/ Modified BSD License
*/
class MultiStatus implements Element
{
/**
* The responses.
*
* @var \Sabre\DAV\Xml\Element\Response[]
*/
protected $responses;
/**
* A sync token (from RFC6578).
*
* @var string
*/
protected $syncToken;
/**
* Constructor.
*
* @param \Sabre\DAV\Xml\Element\Response[] $responses
* @param string $syncToken
*/
public function __construct(array $responses, $syncToken = null)
{
$this->responses = $responses;
$this->syncToken = $syncToken;
}
/**
* Returns the response list.
*
* @return \Sabre\DAV\Xml\Element\Response[]
*/
public function getResponses()
{
return $this->responses;
}
/**
* Returns the sync-token, if available.
*
* @return string|null
*/
public function getSyncToken()
{
return $this->syncToken;
}
/**
* The serialize method is called during xml writing.
*
* It should use the $writer argument to encode this object into XML.
*
* Important note: it is not needed to create the parent element. The
* parent element is already created, and we only have to worry about
* attributes, child elements and text (if any).
*
* Important note 2: If you are writing any new elements, you are also
* responsible for closing them.
*/
public function xmlSerialize(Writer $writer)
{
foreach ($this->getResponses() as $response) {
$writer->writeElement('{DAV:}response', $response);
}
if ($syncToken = $this->getSyncToken()) {
$writer->writeElement('{DAV:}sync-token', $syncToken);
}
}
/**
* The deserialize method is called during xml parsing.
*
* This method is called statically, this is because in theory this method
* may be used as a type of constructor, or factory method.
*
* Often you want to return an instance of the current class, but you are
* free to return other data as well.
*
* You are responsible for advancing the reader to the next element. Not
* doing anything will result in a never-ending loop.
*
* If you just want to skip parsing for this element altogether, you can
* just call $reader->next();
*
* $reader->parseInnerTree() will parse the entire sub-tree, and advance to
* the next element.
*
* @return mixed
*/
public static function xmlDeserialize(Reader $reader)
{
$elementMap = $reader->elementMap;
$elementMap['{DAV:}prop'] = 'Sabre\\DAV\\Xml\\Element\\Prop';
$elements = $reader->parseInnerTree($elementMap);
$responses = [];
$syncToken = null;
if ($elements) {
foreach ($elements as $elem) {
if ('{DAV:}response' === $elem['name']) {
$responses[] = $elem['value'];
}
if ('{DAV:}sync-token' === $elem['name']) {
$syncToken = $elem['value'];
}
}
}
return new self($responses, $syncToken);
}
}

View File

@ -0,0 +1,47 @@
<?php
declare(strict_types=1);
namespace Sabre\DAV\Xml;
/**
* XML service for WebDAV.
*
* @copyright Copyright (C) fruux GmbH (https://fruux.com/)
* @author Evert Pot (http://evertpot.com/)
* @license http://sabre.io/license/ Modified BSD License
*/
class Service extends \Sabre\Xml\Service
{
/**
* This is a list of XML elements that we automatically map to PHP classes.
*
* For instance, this list may contain an entry `{DAV:}propfind` that would
* be mapped to Sabre\DAV\Xml\Request\PropFind
*/
public $elementMap = [
'{DAV:}multistatus' => 'Sabre\\DAV\\Xml\\Response\\MultiStatus',
'{DAV:}response' => 'Sabre\\DAV\\Xml\\Element\\Response',
// Requests
'{DAV:}propfind' => 'Sabre\\DAV\\Xml\\Request\\PropFind',
'{DAV:}propertyupdate' => 'Sabre\\DAV\\Xml\\Request\\PropPatch',
'{DAV:}mkcol' => 'Sabre\\DAV\\Xml\\Request\\MkCol',
// Properties
'{DAV:}resourcetype' => 'Sabre\\DAV\\Xml\\Property\\ResourceType',
];
/**
* This is a default list of namespaces.
*
* If you are defining your own custom namespace, add it here to reduce
* bandwidth and improve legibility of xml bodies.
*
* @var array
*/
public $namespaceMap = [
'DAV:' => 'd',
'http://sabredav.org/ns' => 's',
];
}