|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/** |
|
4
|
|
|
* File containing the facet builder User parser class. |
|
5
|
|
|
* |
|
6
|
|
|
* @copyright Copyright (C) eZ Systems AS. All rights reserved. |
|
7
|
|
|
* @license For full copyright and license information view LICENSE file distributed with this source code. |
|
8
|
|
|
*/ |
|
9
|
|
|
namespace eZ\Publish\Core\REST\Server\Input\Parser\FacetBuilder; |
|
10
|
|
|
|
|
11
|
|
|
use eZ\Publish\Core\REST\Common\Input\BaseParser; |
|
12
|
|
|
use eZ\Publish\Core\REST\Common\Input\ParsingDispatcher; |
|
13
|
|
|
use eZ\Publish\Core\REST\Common\Exceptions; |
|
14
|
|
|
use eZ\Publish\API\Repository\Values\Content\Query\FacetBuilder\UserFacetBuilder; |
|
15
|
|
|
|
|
16
|
|
|
/** |
|
17
|
|
|
* Parser for User facet builder. |
|
18
|
|
|
*/ |
|
19
|
|
|
class UserParser extends BaseParser |
|
20
|
|
|
{ |
|
21
|
|
|
/** |
|
22
|
|
|
* Parses input structure to a FacetBuilder object. |
|
23
|
|
|
* |
|
24
|
|
|
* @param array $data |
|
25
|
|
|
* @param \eZ\Publish\Core\REST\Common\Input\ParsingDispatcher $parsingDispatcher |
|
26
|
|
|
* |
|
27
|
|
|
* @throws \eZ\Publish\Core\REST\Common\Exceptions\Parser |
|
28
|
|
|
* |
|
29
|
|
|
* @return \eZ\Publish\API\Repository\Values\Content\Query\FacetBuilder\UserFacetBuilder |
|
30
|
|
|
*/ |
|
31
|
|
|
public function parse(array $data, ParsingDispatcher $parsingDispatcher) |
|
32
|
|
|
{ |
|
33
|
|
|
if (!array_key_exists('User', $data)) { |
|
34
|
|
|
throw new Exceptions\Parser('Invalid <User> format'); |
|
35
|
|
|
} |
|
36
|
|
|
|
|
37
|
|
|
$selectType = [ |
|
38
|
|
|
'OWNER' => UserFacetBuilder::OWNER, |
|
39
|
|
|
'GROUP' => UserFacetBuilder::GROUP, |
|
40
|
|
|
'MODIFIER' => UserFacetBuilder::MODIFIER, |
|
41
|
|
|
]; |
|
42
|
|
|
|
|
43
|
|
|
if (isset($data['User']['select'])) { |
|
44
|
|
|
$type = $data['User']['select']; |
|
45
|
|
|
|
|
46
|
|
|
if (!isset($selectType[$type])) { |
|
47
|
|
|
throw new Exceptions\Parser('<User> unknown type (supported: ' . implode(', ', array_keys($selectType)) . ')'); |
|
48
|
|
|
} |
|
49
|
|
|
|
|
50
|
|
|
$data['User']['type'] = $selectType[$type]; |
|
51
|
|
|
|
|
52
|
|
|
unset($data['User']['select']); |
|
53
|
|
|
} |
|
54
|
|
|
|
|
55
|
|
|
return new UserFacetBuilder($data['User']); |
|
56
|
|
|
} |
|
57
|
|
|
} |
|
58
|
|
|
|