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\DAV; |
23
|
|
|
|
24
|
|
|
use Sabre\Xml\Element; |
25
|
|
|
use Sabre\Xml\Reader; |
26
|
|
|
use Sabre\Xml\Service; |
27
|
|
|
use SearchDAV\XML\BasicSearch; |
28
|
|
|
use SearchDAV\XML\Limit; |
29
|
|
|
use SearchDAV\XML\Literal; |
30
|
|
|
use SearchDAV\XML\Operator; |
31
|
|
|
use SearchDAV\XML\Order; |
32
|
|
|
use SearchDAV\XML\Scope; |
33
|
|
|
|
34
|
|
|
class QueryParser extends Service { |
35
|
|
|
public $namespaceMap = [ |
36
|
|
|
'DAV:' => 'd', |
37
|
|
|
'http://sabredav.org/ns' => 's', |
38
|
|
|
'http://www.w3.org/2001/XMLSchema' => 'xs', |
39
|
|
|
SearchPlugin::SEARCHDAV_NS => 'sd' |
40
|
|
|
]; |
41
|
|
|
|
42
|
|
|
public function __construct() { |
43
|
|
|
$this->elementMap = [ |
44
|
|
|
'{DAV:}literal' => Literal::class, |
45
|
|
|
'{DAV:}searchrequest' => Element\KeyValue::class, |
46
|
|
|
'{DAV:}query-schema-discovery' => Element\KeyValue::class, |
47
|
|
|
'{DAV:}basicsearch' => BasicSearch::class, |
48
|
|
|
'{DAV:}select' => function (Reader $reader) { |
49
|
|
|
return \Sabre\Xml\Deserializer\keyValue($reader, '{DAV:}scope')['{DAV:}prop']; |
50
|
|
|
}, |
51
|
|
|
'{DAV:}from' => function (Reader $reader) { |
52
|
|
|
return \Sabre\Xml\Deserializer\repeatingElements($reader, '{DAV:}scope'); |
53
|
|
|
}, |
54
|
|
|
'{DAV:}orderby' => function (Reader $reader) { |
55
|
|
|
return \Sabre\Xml\Deserializer\repeatingElements($reader, '{DAV:}order'); |
56
|
|
|
}, |
57
|
|
|
'{DAV:}scope' => Scope::class, |
58
|
|
|
'{DAV:}where' => function (Reader $reader) { |
59
|
|
|
$operators = array_map(function ($element) { |
60
|
|
|
return $element['value']; |
61
|
|
|
}, $reader->parseGetElements()); |
62
|
|
|
return (isset($operators[0])) ? $operators[0] : null; |
63
|
|
|
}, |
64
|
|
|
'{DAV:}prop' => Element\Elements::class, |
65
|
|
|
'{DAV:}order' => Order::class, |
66
|
|
|
'{DAV:}eq' => Operator::class, |
67
|
|
|
'{DAV:}gt' => Operator::class, |
68
|
|
|
'{DAV:}gte' => Operator::class, |
69
|
|
|
'{DAV:}lt' => Operator::class, |
70
|
|
|
'{DAV:}lte' => Operator::class, |
71
|
|
|
'{DAV:}and' => Operator::class, |
72
|
|
|
'{DAV:}or' => Operator::class, |
73
|
|
|
'{DAV:}like' => Operator::class, |
74
|
|
|
'{DAV:}contains' => Operator::class, |
75
|
|
|
'{DAV:}not' => Operator::class, |
76
|
|
|
'{DAV:}is-collection' => Operator::class, |
77
|
|
|
'{DAV:}limit' => Limit::class, |
78
|
|
|
]; |
79
|
|
|
} |
80
|
|
|
} |
81
|
|
|
|