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,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())
);
}
}