1
|
|
|
<?php declare(strict_types=1); |
2
|
|
|
/** |
3
|
|
|
* @copyright Copyright (c) 2017 Robin Appelman <[email protected]> |
4
|
|
|
* |
5
|
|
|
* @license GNU AGPL version 3 or any later version |
6
|
|
|
* |
7
|
|
|
* This program is free software: you can redistribute it and/or modify |
8
|
|
|
* it under the terms of the GNU Affero General Public License as |
9
|
|
|
* published by the Free Software Foundation, either version 3 of the |
10
|
|
|
* License, or (at your option) any later version. |
11
|
|
|
* |
12
|
|
|
* This program is distributed in the hope that it will be useful, |
13
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
14
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
15
|
|
|
* GNU Affero General Public License for more details. |
16
|
|
|
* |
17
|
|
|
* You should have received a copy of the GNU Affero General Public License |
18
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>. |
19
|
|
|
* |
20
|
|
|
*/ |
21
|
|
|
|
22
|
|
|
namespace SearchDAV\XML; |
23
|
|
|
|
24
|
|
|
use Sabre\Xml\ParseException; |
25
|
|
|
use Sabre\Xml\Reader; |
26
|
|
|
use Sabre\Xml\XmlDeserializable; |
27
|
|
|
|
28
|
|
|
/** |
29
|
|
|
* The object representation of a search query made by the client |
30
|
|
|
*/ |
31
|
|
|
class BasicSearch implements XmlDeserializable { |
32
|
|
|
/** |
33
|
|
|
* @var string[] |
34
|
|
|
* |
35
|
|
|
* The list of properties to be selected, specified in clark notation |
36
|
|
|
*/ |
37
|
|
|
public $select; |
38
|
|
|
/** |
39
|
|
|
* @var Scope[] |
40
|
|
|
* |
41
|
|
|
* The collections to perform the search in |
42
|
|
|
*/ |
43
|
|
|
public $from; |
44
|
|
|
/** |
45
|
|
|
* @var Operator |
46
|
|
|
* |
47
|
|
|
* The search operator, either a comparison ('gt', 'eq', ...) or a boolean operator ('and', 'or', 'not') |
48
|
|
|
*/ |
49
|
|
|
public $where; |
50
|
|
|
/** |
51
|
|
|
* @var Order[] |
52
|
|
|
* |
53
|
|
|
* The list of order operations that should be used to order the results. |
54
|
|
|
* |
55
|
|
|
* Each order operations consists of a property to sort on and a sort direction. |
56
|
|
|
* If more then one order operations are specified, the comparisons for ordering should |
57
|
|
|
* be applied in the order that the order operations are defined in with the earlier comparisons being |
58
|
|
|
* more significant. |
59
|
|
|
*/ |
60
|
|
|
public $orderBy; |
61
|
|
|
/** |
62
|
|
|
* @var Limit |
63
|
|
|
* |
64
|
|
|
* The limit and offset for the search query |
65
|
|
|
*/ |
66
|
|
|
public $limit; |
67
|
|
|
|
68
|
|
|
/** |
69
|
|
|
* @param Reader $reader |
70
|
|
|
* @return BasicSearch |
71
|
|
|
* @throws ParseException |
72
|
|
|
*/ |
73
|
|
|
static function xmlDeserialize(Reader $reader): BasicSearch { |
74
|
|
|
$search = new self(); |
75
|
|
|
|
76
|
|
|
$elements = \Sabre\Xml\Deserializer\keyValue($reader); |
77
|
|
|
|
78
|
|
|
if (!isset($elements['{DAV:}from'])) { |
79
|
|
|
throw new ParseException('Missing {DAV:}from when parsing {DAV:}basicsearch'); |
80
|
|
|
} |
81
|
|
|
|
82
|
|
|
$search->select = isset($elements['{DAV:}select']) ? $elements['{DAV:}select'] : []; |
83
|
|
|
$search->from = $elements['{DAV:}from']; |
84
|
|
|
$search->where = isset($elements['{DAV:}where']) ? $elements['{DAV:}where'] : null; |
85
|
|
|
$search->orderBy = isset($elements['{DAV:}orderby']) ? $elements['{DAV:}orderby'] : []; |
86
|
|
|
$search->limit = isset($elements['{DAV:}limit']) ? $elements['{DAV:}limit'] : new Limit(); |
87
|
|
|
|
88
|
|
|
return $search; |
89
|
|
|
} |
90
|
|
|
} |
91
|
|
|
|