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,66 @@
<?php
declare(strict_types=1);
namespace Sabre\CardDAV\Xml\Filter;
use Sabre\Xml\Reader;
use Sabre\Xml\XmlDeserializable;
/**
* AddressData parser.
*
* This class parses the {urn:ietf:params:xml:ns:carddav}address-data XML
* element, as defined in:
*
* http://tools.ietf.org/html/rfc6352#section-10.4
*
* This element is used in two distinct places, but this one specifically
* encodes the address-data element as it appears in the addressbook-query
* adressbook-multiget REPORT requests.
*
* @copyright Copyright (C) fruux GmbH (https://fruux.com/)
* @author Evert Pot (http://www.rooftopsolutions.nl/)
* @license http://sabre.io/license/ Modified BSD License
*/
class AddressData 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)
{
$result = [
'contentType' => $reader->getAttribute('content-type') ?: 'text/vcard',
'version' => $reader->getAttribute('version') ?: '3.0',
];
$elems = (array) $reader->parseInnerTree();
$elems = array_filter($elems, function ($element) {
return '{urn:ietf:params:xml:ns:carddav}prop' === $element['name'] &&
isset($element['attributes']['name']);
});
$result['addressDataProperties'] = array_map(function ($element) {
return $element['attributes']['name'];
}, $elems);
return $result;
}
}

View File

@ -0,0 +1,86 @@
<?php
declare(strict_types=1);
namespace Sabre\CardDAV\Xml\Filter;
use Sabre\CardDAV\Plugin;
use Sabre\DAV\Exception\BadRequest;
use Sabre\Xml\Element;
use Sabre\Xml\Reader;
/**
* ParamFilter parser.
*
* This class parses the {urn:ietf:params:xml:ns:carddav}param-filter XML
* element, as defined in:
*
* http://tools.ietf.org/html/rfc6352#section-10.5.2
*
* The result will be spit out as an array.
*
* @copyright Copyright (C) fruux GmbH (https://fruux.com/)
* @author Evert Pot (http://evertpot.com/)
* @license http://sabre.io/license/ Modified BSD License
*/
abstract class ParamFilter implements Element
{
/**
* 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 = [
'name' => null,
'is-not-defined' => false,
'text-match' => null,
];
$att = $reader->parseAttributes();
$result['name'] = $att['name'];
$elems = $reader->parseInnerTree();
if (is_array($elems)) {
foreach ($elems as $elem) {
switch ($elem['name']) {
case '{'.Plugin::NS_CARDDAV.'}is-not-defined':
$result['is-not-defined'] = true;
break;
case '{'.Plugin::NS_CARDDAV.'}text-match':
$matchType = isset($elem['attributes']['match-type']) ? $elem['attributes']['match-type'] : 'contains';
if (!in_array($matchType, ['contains', 'equals', 'starts-with', 'ends-with'])) {
throw new BadRequest('Unknown match-type: '.$matchType);
}
$result['text-match'] = [
'negate-condition' => isset($elem['attributes']['negate-condition']) && 'yes' === $elem['attributes']['negate-condition'],
'collation' => isset($elem['attributes']['collation']) ? $elem['attributes']['collation'] : 'i;unicode-casemap',
'value' => $elem['value'],
'match-type' => $matchType,
];
break;
}
}
}
return $result;
}
}

View File

@ -0,0 +1,95 @@
<?php
declare(strict_types=1);
namespace Sabre\CardDAV\Xml\Filter;
use Sabre\CardDAV\Plugin;
use Sabre\DAV\Exception\BadRequest;
use Sabre\Xml\Reader;
use Sabre\Xml\XmlDeserializable;
/**
* PropFilter parser.
*
* This class parses the {urn:ietf:params:xml:ns:carddav}prop-filter XML
* element, as defined in:
*
* http://tools.ietf.org/html/rfc6352#section-10.5.1
*
* The result will be spit out as an array.
*
* @copyright Copyright (C) fruux GmbH (https://fruux.com/)
* @author Evert Pot (http://evertpot.com/)
* @license http://sabre.io/license/ Modified BSD License
*/
class PropFilter 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)
{
$result = [
'name' => null,
'test' => 'anyof',
'is-not-defined' => false,
'param-filters' => [],
'text-matches' => [],
];
$att = $reader->parseAttributes();
$result['name'] = $att['name'];
if (isset($att['test']) && 'allof' === $att['test']) {
$result['test'] = 'allof';
}
$elems = $reader->parseInnerTree();
if (is_array($elems)) {
foreach ($elems as $elem) {
switch ($elem['name']) {
case '{'.Plugin::NS_CARDDAV.'}param-filter':
$result['param-filters'][] = $elem['value'];
break;
case '{'.Plugin::NS_CARDDAV.'}is-not-defined':
$result['is-not-defined'] = true;
break;
case '{'.Plugin::NS_CARDDAV.'}text-match':
$matchType = isset($elem['attributes']['match-type']) ? $elem['attributes']['match-type'] : 'contains';
if (!in_array($matchType, ['contains', 'equals', 'starts-with', 'ends-with'])) {
throw new BadRequest('Unknown match-type: '.$matchType);
}
$result['text-matches'][] = [
'negate-condition' => isset($elem['attributes']['negate-condition']) && 'yes' === $elem['attributes']['negate-condition'],
'collation' => isset($elem['attributes']['collation']) ? $elem['attributes']['collation'] : 'i;unicode-casemap',
'value' => $elem['value'],
'match-type' => $matchType,
];
break;
}
}
}
return $result;
}
}

View File

@ -0,0 +1,77 @@
<?php
declare(strict_types=1);
namespace Sabre\CardDAV\Xml\Property;
use Sabre\CardDAV\Plugin;
use Sabre\Xml\Writer;
use Sabre\Xml\XmlSerializable;
/**
* Supported-address-data property.
*
* This property is a representation of the supported-address-data property
* in the CardDAV namespace.
*
* This property is defined in:
*
* http://tools.ietf.org/html/rfc6352#section-6.2.2
*
* @copyright Copyright (C) fruux GmbH (https://fruux.com/)
* @author Evert Pot (http://evertpot.com/)
* @license http://sabre.io/license/ Modified BSD License
*/
class SupportedAddressData implements XmlSerializable
{
/**
* supported versions.
*
* @var array
*/
protected $supportedData = [];
/**
* Creates the property.
*/
public function __construct(array $supportedData = null)
{
if (is_null($supportedData)) {
$supportedData = [
['contentType' => 'text/vcard', 'version' => '3.0'],
['contentType' => 'text/vcard', 'version' => '4.0'],
['contentType' => 'application/vcard+json', 'version' => '4.0'],
];
}
$this->supportedData = $supportedData;
}
/**
* 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->supportedData as $supported) {
$writer->startElement('{'.Plugin::NS_CARDDAV.'}address-data-type');
$writer->writeAttributes([
'content-type' => $supported['contentType'],
'version' => $supported['version'],
]);
$writer->endElement(); // address-data-type
}
}
}

View File

@ -0,0 +1,44 @@
<?php
declare(strict_types=1);
namespace Sabre\CardDAV\Xml\Property;
use Sabre\Xml\Writer;
use Sabre\Xml\XmlSerializable;
/**
* supported-collation-set property.
*
* This property is a representation of the supported-collation-set property
* in the CardDAV namespace.
*
* @copyright Copyright (C) fruux GmbH (https://fruux.com/)
* @author Evert Pot (http://evertpot.com/)
* @license http://sabre.io/license/ Modified BSD License
*/
class SupportedCollationSet 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)
{
foreach (['i;ascii-casemap', 'i;octet', 'i;unicode-casemap'] as $coll) {
$writer->writeElement('{urn:ietf:params:xml:ns:carddav}supported-collation', $coll);
}
}
}

View File

@ -0,0 +1,109 @@
<?php
declare(strict_types=1);
namespace Sabre\CardDAV\Xml\Request;
use Sabre\CardDAV\Plugin;
use Sabre\Uri;
use Sabre\Xml\Reader;
use Sabre\Xml\XmlDeserializable;
/**
* AddressBookMultiGetReport request parser.
*
* This class parses the {urn:ietf:params:xml:ns:carddav}addressbook-multiget
* REPORT, as defined in:
*
* http://tools.ietf.org/html/rfc6352#section-8.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 AddressBookMultiGetReport implements XmlDeserializable
{
/**
* An array with requested properties.
*
* @var array
*/
public $properties;
/**
* This is an array with the urls that are being requested.
*
* @var array
*/
public $hrefs;
/**
* The mimetype of the content that should be returend. Usually
* text/vcard.
*
* @var string
*/
public $contentType = null;
/**
* The version of vcard data that should be returned. Usually 3.0,
* referring to vCard 3.0.
*
* @var string
*/
public $version = null;
/**
* 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([
'{urn:ietf:params:xml:ns:carddav}address-data' => 'Sabre\\CardDAV\\Xml\\Filter\\AddressData',
'{DAV:}prop' => 'Sabre\\Xml\\Element\\KeyValue',
]);
$newProps = [
'hrefs' => [],
'properties' => [],
];
foreach ($elems as $elem) {
switch ($elem['name']) {
case '{DAV:}prop':
$newProps['properties'] = array_keys($elem['value']);
if (isset($elem['value']['{'.Plugin::NS_CARDDAV.'}address-data'])) {
$newProps += $elem['value']['{'.Plugin::NS_CARDDAV.'}address-data'];
}
break;
case '{DAV:}href':
$newProps['hrefs'][] = Uri\resolve($reader->contextUri, $elem['value']);
break;
}
}
$obj = new self();
foreach ($newProps as $key => $value) {
$obj->$key = $value;
}
return $obj;
}
}

View File

@ -0,0 +1,194 @@
<?php
declare(strict_types=1);
namespace Sabre\CardDAV\Xml\Request;
use Sabre\CardDAV\Plugin;
use Sabre\DAV\Exception\BadRequest;
use Sabre\Xml\Reader;
use Sabre\Xml\XmlDeserializable;
/**
* AddressBookQueryReport request parser.
*
* This class parses the {urn:ietf:params:xml:ns:carddav}addressbook-query
* REPORT, as defined in:
*
* http://tools.ietf.org/html/rfc6352#section-8.6
*
* @copyright Copyright (C) fruux GmbH (https://fruux.com/)
* @author Evert Pot (http://www.rooftopsolutions.nl/)
* @license http://sabre.io/license/ Modified BSD License
*/
class AddressBookQueryReport implements XmlDeserializable
{
/**
* An array with requested properties.
*
* @var array
*/
public $properties;
/**
* An array with requested vcard properties.
*
* @var array
*/
public $addressDataProperties = [];
/**
* List of property/component filters.
*
* This is an array with filters. Every item is a property filter. Every
* property filter has the following keys:
* * name - name of the component to filter on
* * test - anyof or allof
* * is-not-defined - Test for non-existence
* * param-filters - A list of parameter filters on the property
* * text-matches - A list of text values the filter needs to match
*
* Each param-filter has the following keys:
* * name - name of the parameter
* * is-not-defined - Test for non-existence
* * text-match - Match the parameter value
*
* Each text-match in property filters, and the single text-match in
* param-filters have the following keys:
*
* * value - value to match
* * match-type - contains, starts-with, ends-with, equals
* * negate-condition - Do the opposite match
* * collation - Usually i;unicode-casemap
*
* @var array
*/
public $filters;
/**
* The number of results the client wants.
*
* null means it wasn't specified, which in most cases means 'all results'.
*
* @var int|null
*/
public $limit;
/**
* Either 'anyof' or 'allof'.
*
* @var string
*/
public $test;
/**
* The mimetype of the content that should be returend. Usually
* text/vcard.
*
* @var string
*/
public $contentType = null;
/**
* The version of vcard data that should be returned. Usually 3.0,
* referring to vCard 3.0.
*
* @var string
*/
public $version = null;
/**
* 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 = (array) $reader->parseInnerTree([
'{urn:ietf:params:xml:ns:carddav}prop-filter' => 'Sabre\\CardDAV\\Xml\\Filter\\PropFilter',
'{urn:ietf:params:xml:ns:carddav}param-filter' => 'Sabre\\CardDAV\\Xml\\Filter\\ParamFilter',
'{urn:ietf:params:xml:ns:carddav}address-data' => 'Sabre\\CardDAV\\Xml\\Filter\\AddressData',
'{DAV:}prop' => 'Sabre\\Xml\\Element\\KeyValue',
]);
$newProps = [
'filters' => null,
'properties' => [],
'test' => 'anyof',
'limit' => null,
];
if (!is_array($elems)) {
$elems = [];
}
foreach ($elems as $elem) {
switch ($elem['name']) {
case '{DAV:}prop':
$newProps['properties'] = array_keys($elem['value']);
if (isset($elem['value']['{'.Plugin::NS_CARDDAV.'}address-data'])) {
$newProps += $elem['value']['{'.Plugin::NS_CARDDAV.'}address-data'];
}
break;
case '{'.Plugin::NS_CARDDAV.'}filter':
if (!is_null($newProps['filters'])) {
throw new BadRequest('You can only include 1 {'.Plugin::NS_CARDDAV.'}filter element');
}
if (isset($elem['attributes']['test'])) {
$newProps['test'] = $elem['attributes']['test'];
if ('allof' !== $newProps['test'] && 'anyof' !== $newProps['test']) {
throw new BadRequest('The "test" attribute must be one of "allof" or "anyof"');
}
}
$newProps['filters'] = [];
foreach ((array) $elem['value'] as $subElem) {
if ($subElem['name'] === '{'.Plugin::NS_CARDDAV.'}prop-filter') {
$newProps['filters'][] = $subElem['value'];
}
}
break;
case '{'.Plugin::NS_CARDDAV.'}limit':
foreach ($elem['value'] as $child) {
if ($child['name'] === '{'.Plugin::NS_CARDDAV.'}nresults') {
$newProps['limit'] = (int) $child['value'];
}
}
break;
}
}
if (is_null($newProps['filters'])) {
/*
* We are supposed to throw this error, but KDE sometimes does not
* include the filter element, and we need to treat it as if no
* filters are supplied
*/
//throw new BadRequest('The {' . Plugin::NS_CARDDAV . '}filter element is required for this request');
$newProps['filters'] = [];
}
$obj = new self();
foreach ($newProps as $key => $value) {
$obj->$key = $value;
}
return $obj;
}
}