|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/** |
|
4
|
|
|
* File containing the eZ\Publish\API\Repository\Values\Content\Query\Criterion\Subtree 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\API\Repository\Values\Content\Query\Criterion; |
|
10
|
|
|
|
|
11
|
|
|
use eZ\Publish\API\Repository\Values\Content\Query\Criterion; |
|
12
|
|
|
use eZ\Publish\API\Repository\Values\Content\Query\Criterion\Operator\Specifications; |
|
13
|
|
|
use InvalidArgumentException; |
|
14
|
|
|
|
|
15
|
|
|
/** |
|
16
|
|
|
* Criterion that matches content that belongs to a given (list of) Subtree(s). |
|
17
|
|
|
* |
|
18
|
|
|
* Content will be matched if it is part of at least one of the given subtree path strings |
|
19
|
|
|
*/ |
|
20
|
|
|
class Subtree extends Criterion |
|
21
|
|
|
{ |
|
22
|
|
|
/** |
|
23
|
|
|
* Creates a new SubTree criterion. |
|
24
|
|
|
* |
|
25
|
|
|
* @param string|string[] $value an array of subtree path strings, eg: /1/2/ |
|
26
|
|
|
* |
|
27
|
|
|
* @throws InvalidArgumentException if a non path string is given |
|
28
|
|
|
* @throws InvalidArgumentException if the value type doesn't match the operator |
|
29
|
|
|
*/ |
|
30
|
|
|
public function __construct($value) |
|
31
|
|
|
{ |
|
32
|
|
|
foreach ((array)$value as $pathString) { |
|
33
|
|
|
if (preg_match('/^(\/\w+)+\/$/', $pathString) !== 1) { |
|
34
|
|
|
throw new InvalidArgumentException("'$pathString' value must follow the pathString format, e.g. /1/2/"); |
|
35
|
|
|
} |
|
36
|
|
|
} |
|
37
|
|
|
|
|
38
|
|
|
parent::__construct(null, null, $value); |
|
39
|
|
|
} |
|
40
|
|
|
|
|
41
|
|
|
public function getSpecifications() |
|
42
|
|
|
{ |
|
43
|
|
|
return [ |
|
44
|
|
|
new Specifications( |
|
45
|
|
|
Operator::EQ, |
|
46
|
|
|
Specifications::FORMAT_SINGLE, |
|
47
|
|
|
Specifications::TYPE_STRING |
|
48
|
|
|
), |
|
49
|
|
|
new Specifications( |
|
50
|
|
|
Operator::IN, |
|
51
|
|
|
Specifications::FORMAT_ARRAY, |
|
52
|
|
|
Specifications::TYPE_STRING |
|
53
|
|
|
), |
|
54
|
|
|
]; |
|
55
|
|
|
} |
|
56
|
|
|
} |
|
57
|
|
|
|