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,257 @@
<?php
declare(strict_types=1);
namespace Sabre\DAVACL\Xml\Property;
use Sabre\DAV;
use Sabre\DAV\Browser\HtmlOutput;
use Sabre\DAV\Browser\HtmlOutputHelper;
use Sabre\Xml\Element;
use Sabre\Xml\Reader;
use Sabre\Xml\Writer;
/**
* This class represents the {DAV:}acl property.
*
* The {DAV:}acl property is a full list of access control entries for a
* resource.
*
* {DAV:}acl is used as a WebDAV property, but it is also used within the body
* of the ACL request.
*
* See:
* http://tools.ietf.org/html/rfc3744#section-5.5
*
* @copyright Copyright (C) fruux GmbH (https://fruux.com/)
* @author Evert Pot (http://evertpot.com/)
* @license http://sabre.io/license/ Modified BSD License
*/
class Acl implements Element, HtmlOutput
{
/**
* List of privileges.
*
* @var array
*/
protected $privileges;
/**
* Whether or not the server base url is required to be prefixed when
* serializing the property.
*
* @var bool
*/
protected $prefixBaseUrl;
/**
* Constructor.
*
* This object requires a structure similar to the return value from
* Sabre\DAVACL\Plugin::getACL().
*
* Each privilege is a an array with at least a 'privilege' property, and a
* 'principal' property. A privilege may have a 'protected' property as
* well.
*
* The prefixBaseUrl should be set to false, if the supplied principal urls
* are already full urls. If this is kept to true, the servers base url
* will automatically be prefixed.
*
* @param bool $prefixBaseUrl
*/
public function __construct(array $privileges, $prefixBaseUrl = true)
{
$this->privileges = $privileges;
$this->prefixBaseUrl = $prefixBaseUrl;
}
/**
* Returns the list of privileges for this property.
*
* @return array
*/
public function getPrivileges()
{
return $this->privileges;
}
/**
* 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->privileges as $ace) {
$this->serializeAce($writer, $ace);
}
}
/**
* 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)
{
ob_start();
echo '<table>';
echo '<tr><th>Principal</th><th>Privilege</th><th></th></tr>';
foreach ($this->privileges as $privilege) {
echo '<tr>';
// if it starts with a {, it's a special principal
if ('{' === $privilege['principal'][0]) {
echo '<td>', $html->xmlName($privilege['principal']), '</td>';
} else {
echo '<td>', $html->link($privilege['principal']), '</td>';
}
echo '<td>', $html->xmlName($privilege['privilege']), '</td>';
echo '<td>';
if (!empty($privilege['protected'])) {
echo '(protected)';
}
echo '</td>';
echo '</tr>';
}
echo '</table>';
return ob_get_clean();
}
/**
* 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)
{
$elementMap = [
'{DAV:}ace' => 'Sabre\Xml\Element\KeyValue',
'{DAV:}privilege' => 'Sabre\Xml\Element\Elements',
'{DAV:}principal' => 'Sabre\DAVACL\Xml\Property\Principal',
];
$privileges = [];
foreach ((array) $reader->parseInnerTree($elementMap) as $element) {
if ('{DAV:}ace' !== $element['name']) {
continue;
}
$ace = $element['value'];
if (empty($ace['{DAV:}principal'])) {
throw new DAV\Exception\BadRequest('Each {DAV:}ace element must have one {DAV:}principal element');
}
$principal = $ace['{DAV:}principal'];
switch ($principal->getType()) {
case Principal::HREF:
$principal = $principal->getHref();
break;
case Principal::AUTHENTICATED:
$principal = '{DAV:}authenticated';
break;
case Principal::UNAUTHENTICATED:
$principal = '{DAV:}unauthenticated';
break;
case Principal::ALL:
$principal = '{DAV:}all';
break;
}
$protected = array_key_exists('{DAV:}protected', $ace);
if (!isset($ace['{DAV:}grant'])) {
throw new DAV\Exception\NotImplemented('Every {DAV:}ace element must have a {DAV:}grant element. {DAV:}deny is not yet supported');
}
foreach ($ace['{DAV:}grant'] as $elem) {
if ('{DAV:}privilege' !== $elem['name']) {
continue;
}
foreach ($elem['value'] as $priv) {
$privileges[] = [
'principal' => $principal,
'protected' => $protected,
'privilege' => $priv,
];
}
}
}
return new self($privileges);
}
/**
* Serializes a single access control entry.
*/
private function serializeAce(Writer $writer, array $ace)
{
$writer->startElement('{DAV:}ace');
switch ($ace['principal']) {
case '{DAV:}authenticated':
$principal = new Principal(Principal::AUTHENTICATED);
break;
case '{DAV:}unauthenticated':
$principal = new Principal(Principal::UNAUTHENTICATED);
break;
case '{DAV:}all':
$principal = new Principal(Principal::ALL);
break;
default:
$principal = new Principal(Principal::HREF, $ace['principal']);
break;
}
$writer->writeElement('{DAV:}principal', $principal);
$writer->startElement('{DAV:}grant');
$writer->startElement('{DAV:}privilege');
$writer->writeElement($ace['privilege']);
$writer->endElement(); // privilege
$writer->endElement(); // grant
if (!empty($ace['protected'])) {
$writer->writeElement('{DAV:}protected');
}
$writer->endElement(); // ace
}
}

View File

@ -0,0 +1,42 @@
<?php
declare(strict_types=1);
namespace Sabre\DAVACL\Xml\Property;
use Sabre\Xml\Writer;
use Sabre\Xml\XmlSerializable;
/**
* AclRestrictions property.
*
* This property represents {DAV:}acl-restrictions, as defined in RFC3744.
*
* @copyright Copyright (C) fruux GmbH (https://fruux.com/)
* @author Evert Pot (http://evertpot.com/)
* @license http://sabre.io/license/ Modified BSD License
*/
class AclRestrictions 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:}grant-only');
$writer->writeElement('{DAV:}no-invert');
}
}

View File

@ -0,0 +1,145 @@
<?php
declare(strict_types=1);
namespace Sabre\DAVACL\Xml\Property;
use Sabre\DAV\Browser\HtmlOutput;
use Sabre\DAV\Browser\HtmlOutputHelper;
use Sabre\Xml\Element;
use Sabre\Xml\Reader;
use Sabre\Xml\Writer;
/**
* CurrentUserPrivilegeSet.
*
* This class represents the current-user-privilege-set property. When
* requested, it contain all the privileges a user has on a specific node.
*
* @copyright Copyright (C) fruux GmbH (https://fruux.com/)
* @author Evert Pot (http://evertpot.com/)
* @license http://sabre.io/license/ Modified BSD License
*/
class CurrentUserPrivilegeSet implements Element, HtmlOutput
{
/**
* List of privileges.
*
* @var array
*/
private $privileges;
/**
* Creates the object.
*
* Pass the privileges in clark-notation
*/
public function __construct(array $privileges)
{
$this->privileges = $privileges;
}
/**
* 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->privileges as $privName) {
$writer->startElement('{DAV:}privilege');
$writer->writeElement($privName);
$writer->endElement();
}
}
/**
* Returns true or false, whether the specified principal appears in the
* list.
*
* @param string $privilegeName
*
* @return bool
*/
public function has($privilegeName)
{
return in_array($privilegeName, $this->privileges);
}
/**
* Returns the list of privileges.
*
* @return array
*/
public function getValue()
{
return $this->privileges;
}
/**
* 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)
{
$result = [];
$tree = $reader->parseInnerTree(['{DAV:}privilege' => 'Sabre\\Xml\\Element\\Elements']);
foreach ($tree as $element) {
if ('{DAV:}privilege' !== $element['name']) {
continue;
}
$result[] = $element['value'][0];
}
return new self($result);
}
/**
* 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,184 @@
<?php
declare(strict_types=1);
namespace Sabre\DAVACL\Xml\Property;
use Sabre\DAV;
use Sabre\DAV\Browser\HtmlOutputHelper;
use Sabre\DAV\Exception\BadRequest;
use Sabre\Xml\Reader;
use Sabre\Xml\Writer;
/**
* Principal property.
*
* The principal property represents a principal from RFC3744 (ACL).
* The property can be used to specify a principal or pseudo principals.
*
* @copyright Copyright (C) fruux GmbH (https://fruux.com/)
* @author Evert Pot (http://evertpot.com/)
* @license http://sabre.io/license/ Modified BSD License
*/
class Principal extends DAV\Xml\Property\Href
{
/**
* To specify a not-logged-in user, use the UNAUTHENTICATED principal.
*/
const UNAUTHENTICATED = 1;
/**
* To specify any principal that is logged in, use AUTHENTICATED.
*/
const AUTHENTICATED = 2;
/**
* Specific principals can be specified with the HREF.
*/
const HREF = 3;
/**
* Everybody, basically.
*/
const ALL = 4;
/**
* Principal-type.
*
* Must be one of the UNAUTHENTICATED, AUTHENTICATED or HREF constants.
*
* @var int
*/
protected $type;
/**
* Creates the property.
*
* The 'type' argument must be one of the type constants defined in this class.
*
* 'href' is only required for the HREF type.
*
* @param int $type
* @param string|null $href
*/
public function __construct($type, $href = null)
{
$this->type = $type;
if (self::HREF === $type && is_null($href)) {
throw new DAV\Exception('The href argument must be specified for the HREF principal type.');
}
if ($href) {
$href = rtrim($href, '/').'/';
parent::__construct($href);
}
}
/**
* Returns the principal type.
*
* @return int
*/
public function getType()
{
return $this->type;
}
/**
* 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->type) {
case self::UNAUTHENTICATED:
$writer->writeElement('{DAV:}unauthenticated');
break;
case self::AUTHENTICATED:
$writer->writeElement('{DAV:}authenticated');
break;
case self::HREF:
parent::xmlSerialize($writer);
break;
case self::ALL:
$writer->writeElement('{DAV:}all');
break;
}
}
/**
* 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)
{
switch ($this->type) {
case self::UNAUTHENTICATED:
return '<em>unauthenticated</em>';
case self::AUTHENTICATED:
return '<em>authenticated</em>';
case self::HREF:
return parent::toHtml($html);
case self::ALL:
return '<em>all</em>';
}
}
/**
* The deserialize method is called during xml parsing.
*
* This method is called staticly, 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)
{
$tree = $reader->parseInnerTree()[0];
switch ($tree['name']) {
case '{DAV:}unauthenticated':
return new self(self::UNAUTHENTICATED);
case '{DAV:}authenticated':
return new self(self::AUTHENTICATED);
case '{DAV:}href':
return new self(self::HREF, $tree['value']);
case '{DAV:}all':
return new self(self::ALL);
default:
throw new BadRequest('Unknown or unsupported principal type: '.$tree['name']);
}
}
}

View File

@ -0,0 +1,146 @@
<?php
declare(strict_types=1);
namespace Sabre\DAVACL\Xml\Property;
use Sabre\DAV\Browser\HtmlOutput;
use Sabre\DAV\Browser\HtmlOutputHelper;
use Sabre\Xml\Writer;
use Sabre\Xml\XmlSerializable;
/**
* SupportedPrivilegeSet property.
*
* This property encodes the {DAV:}supported-privilege-set property, as defined
* in rfc3744. Please consult the rfc for details about it's structure.
*
* This class expects a structure like the one given from
* Sabre\DAVACL\Plugin::getSupportedPrivilegeSet as the argument in its
* constructor.
*
* @copyright Copyright (C) fruux GmbH (https://fruux.com/)
* @author Evert Pot (http://evertpot.com/)
* @license http://sabre.io/license/ Modified BSD License
*/
class SupportedPrivilegeSet implements XmlSerializable, HtmlOutput
{
/**
* privileges.
*
* @var array
*/
protected $privileges;
/**
* Constructor.
*/
public function __construct(array $privileges)
{
$this->privileges = $privileges;
}
/**
* Returns the privilege value.
*
* @return array
*/
public function getValue()
{
return $this->privileges;
}
/**
* 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)
{
$this->serializePriv($writer, '{DAV:}all', ['aggregates' => $this->privileges]);
}
/**
* 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)
{
$traverse = function ($privName, $priv) use (&$traverse, $html) {
echo '<li>';
echo $html->xmlName($privName);
if (isset($priv['abstract']) && $priv['abstract']) {
echo ' <i>(abstract)</i>';
}
if (isset($priv['description'])) {
echo ' '.$html->h($priv['description']);
}
if (isset($priv['aggregates'])) {
echo "\n<ul>\n";
foreach ($priv['aggregates'] as $subPrivName => $subPriv) {
$traverse($subPrivName, $subPriv);
}
echo '</ul>';
}
echo "</li>\n";
};
ob_start();
echo '<ul class="tree">';
$traverse('{DAV:}all', ['aggregates' => $this->getValue()]);
echo "</ul>\n";
return ob_get_clean();
}
/**
* Serializes a property.
*
* This is a recursive function.
*
* @param string $privName
* @param array $privilege
*/
private function serializePriv(Writer $writer, $privName, $privilege)
{
$writer->startElement('{DAV:}supported-privilege');
$writer->startElement('{DAV:}privilege');
$writer->writeElement($privName);
$writer->endElement(); // privilege
if (!empty($privilege['abstract'])) {
$writer->writeElement('{DAV:}abstract');
}
if (!empty($privilege['description'])) {
$writer->writeElement('{DAV:}description', $privilege['description']);
}
if (isset($privilege['aggregates'])) {
foreach ($privilege['aggregates'] as $subPrivName => $subPrivilege) {
$this->serializePriv($writer, $subPrivName, $subPrivilege);
}
}
$writer->endElement(); // supported-privilege
}
}

View File

@ -0,0 +1,66 @@
<?php
declare(strict_types=1);
namespace Sabre\DAVACL\Xml\Request;
use Sabre\Xml\Deserializer;
use Sabre\Xml\Reader;
use Sabre\Xml\XmlDeserializable;
/**
* AclPrincipalPropSet request parser.
*
* This class parses the {DAV:}acl-principal-prop-set REPORT, as defined in:
*
* https://tools.ietf.org/html/rfc3744#section-9.2
*
* @copyright Copyright (C) fruux GmbH (https://fruux.com/)
* @author Evert Pot (https://evertpot.com/)
* @license http://sabre.io/license/ Modified BSD License
*/
class AclPrincipalPropSetReport implements XmlDeserializable
{
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)
{
$reader->pushContext();
$reader->elementMap['{DAV:}prop'] = 'Sabre\Xml\Deserializer\enum';
$elems = Deserializer\keyValue(
$reader,
'DAV:'
);
$reader->popContext();
$report = new self();
if (!empty($elems['prop'])) {
$report->properties = $elems['prop'];
}
return $report;
}
}

View File

@ -0,0 +1,100 @@
<?php
declare(strict_types=1);
namespace Sabre\DAVACL\Xml\Request;
use Sabre\Xml\Reader;
use Sabre\Xml\XmlDeserializable;
/**
* ExpandProperty request parser.
*
* This class parses the {DAV:}expand-property REPORT, as defined in:
*
* http://tools.ietf.org/html/rfc3253#section-3.8
*
* @copyright Copyright (C) fruux GmbH (https://fruux.com/)
* @author Evert Pot (http://evertpot.com/)
* @license http://sabre.io/license/ Modified BSD License
*/
class ExpandPropertyReport implements XmlDeserializable
{
/**
* An array with requested properties.
*
* The requested properties will be used as keys in this array. The value
* is normally null.
*
* If the value is an array though, it means the property must be expanded.
* Within the array, the sub-properties, which themselves may be null or
* arrays.
*
* @var array
*/
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)
{
$elems = $reader->parseInnerTree();
$obj = new self();
$obj->properties = self::traverse($elems);
return $obj;
}
/**
* This method is used by deserializeXml, to recursively parse the
* {DAV:}property elements.
*
* @param array $elems
*
* @return array
*/
private static function traverse($elems)
{
$result = [];
foreach ($elems as $elem) {
if ('{DAV:}property' !== $elem['name']) {
continue;
}
$namespace = isset($elem['attributes']['namespace']) ?
$elem['attributes']['namespace'] :
'DAV:';
$propName = '{'.$namespace.'}'.$elem['attributes']['name'];
$value = null;
if (is_array($elem['value'])) {
$value = self::traverse($elem['value']);
}
$result[$propName] = $value;
}
return $result;
}
}

View File

@ -0,0 +1,106 @@
<?php
declare(strict_types=1);
namespace Sabre\DAVACL\Xml\Request;
use Sabre\Xml\Deserializer;
use Sabre\Xml\Reader;
use Sabre\Xml\XmlDeserializable;
/**
* PrincipalMatchReport request parser.
*
* This class parses the {DAV:}principal-match REPORT, as defined
* in:
*
* https://tools.ietf.org/html/rfc3744#section-9.3
*
* @copyright Copyright (C) fruux GmbH (https://fruux.com/)
* @author Evert Pot (http://evertpot.com/)
* @license http://sabre.io/license/ Modified BSD License
*/
class PrincipalMatchReport implements XmlDeserializable
{
/**
* Report on a list of principals that match the current principal.
*/
const SELF = 1;
/**
* Report on a property on resources, such as {DAV:}owner, that match the current principal.
*/
const PRINCIPAL_PROPERTY = 2;
/**
* Must be SELF or PRINCIPAL_PROPERTY.
*
* @var int
*/
public $type;
/**
* List of properties that are being requested for matching resources.
*
* @var string[]
*/
public $properties = [];
/**
* If $type = PRINCIPAL_PROPERTY, which WebDAV property we should compare
* to the current principal.
*
* @var string
*/
public $principalProperty;
/**
* 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:}prop'] = 'Sabre\Xml\Deserializer\enum';
$elems = Deserializer\keyValue(
$reader,
'DAV:'
);
$reader->popContext();
$principalMatch = new self();
if (array_key_exists('self', $elems)) {
$principalMatch->type = self::SELF;
}
if (array_key_exists('principal-property', $elems)) {
$principalMatch->type = self::PRINCIPAL_PROPERTY;
$principalMatch->principalProperty = $elems['principal-property'][0]['name'];
}
if (!empty($elems['prop'])) {
$principalMatch->properties = $elems['prop'];
}
return $principalMatch;
}
}

View File

@ -0,0 +1,122 @@
<?php
declare(strict_types=1);
namespace Sabre\DAVACL\Xml\Request;
use Sabre\DAV\Exception\BadRequest;
use Sabre\Xml\Reader;
use Sabre\Xml\XmlDeserializable;
/**
* PrincipalSearchPropertySetReport request parser.
*
* This class parses the {DAV:}principal-property-search REPORT, as defined
* in:
*
* https://tools.ietf.org/html/rfc3744#section-9.4
*
* @copyright Copyright (C) fruux GmbH (https://fruux.com/)
* @author Evert Pot (http://evertpot.com/)
* @license http://sabre.io/license/ Modified BSD License
*/
class PrincipalPropertySearchReport implements XmlDeserializable
{
/**
* The requested properties.
*
* @var array|null
*/
public $properties;
/**
* searchProperties.
*
* @var array
*/
public $searchProperties = [];
/**
* By default the property search will be conducted on the url of the http
* request. If this is set to true, it will be applied to the principal
* collection set instead.
*
* @var bool
*/
public $applyToPrincipalCollectionSet = false;
/**
* Search for principals matching ANY of the properties (OR) or a ALL of
* the properties (AND).
*
* This property is either "anyof" or "allof".
*
* @var string
*/
public $test;
/**
* 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();
$foundSearchProp = false;
$self->test = 'allof';
if ('anyof' === $reader->getAttribute('test')) {
$self->test = 'anyof';
}
$elemMap = [
'{DAV:}property-search' => 'Sabre\\Xml\\Element\\KeyValue',
'{DAV:}prop' => 'Sabre\\Xml\\Element\\KeyValue',
];
foreach ($reader->parseInnerTree($elemMap) as $elem) {
switch ($elem['name']) {
case '{DAV:}prop':
$self->properties = array_keys($elem['value']);
break;
case '{DAV:}property-search':
$foundSearchProp = true;
// This property has two sub-elements:
// {DAV:}prop - The property to be searched on. This may
// also be more than one
// {DAV:}match - The value to match with
if (!isset($elem['value']['{DAV:}prop']) || !isset($elem['value']['{DAV:}match'])) {
throw new BadRequest('The {DAV:}property-search element must contain one {DAV:}match and one {DAV:}prop element');
}
foreach ($elem['value']['{DAV:}prop'] as $propName => $discard) {
$self->searchProperties[$propName] = $elem['value']['{DAV:}match'];
}
break;
case '{DAV:}apply-to-principal-collection-set':
$self->applyToPrincipalCollectionSet = true;
break;
}
}
if (!$foundSearchProp) {
throw new BadRequest('The {DAV:}principal-property-search report must contain at least 1 {DAV:}property-search element');
}
return $self;
}
}

View File

@ -0,0 +1,58 @@
<?php
declare(strict_types=1);
namespace Sabre\DAVACL\Xml\Request;
use Sabre\DAV\Exception\BadRequest;
use Sabre\Xml\Reader;
use Sabre\Xml\XmlDeserializable;
/**
* PrincipalSearchPropertySetReport request parser.
*
* This class parses the {DAV:}principal-search-property-set REPORT, as defined
* in:
*
* https://tools.ietf.org/html/rfc3744#section-9.5
*
* @copyright Copyright (C) fruux GmbH (https://fruux.com/)
* @author Evert Pot (http://evertpot.com/)
* @license http://sabre.io/license/ Modified BSD License
*/
class PrincipalSearchPropertySetReport 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 (!$reader->isEmptyElement) {
throw new BadRequest('The {DAV:}principal-search-property-set element must be empty');
}
// The element is actually empty, so there's not much to do.
$reader->next();
$self = new self();
return $self;
}
}