1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/** |
4
|
|
|
* This file is part of the eZ Publish Kernel package. |
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
|
|
|
* A criterion that matches content that is ancestor to the given Location path string. |
17
|
|
|
* |
18
|
|
|
* Content will be matched if it is part of at least one of the given subtree path strings. |
19
|
|
|
*/ |
20
|
|
View Code Duplication |
class Ancestor extends Criterion |
|
|
|
|
21
|
|
|
{ |
22
|
|
|
/** |
23
|
|
|
* Creates a new Ancestor criterion. |
24
|
|
|
* |
25
|
|
|
* @param string $value Location path string |
26
|
|
|
* |
27
|
|
|
* @throws \InvalidArgumentException if a non integer or string id 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( |
35
|
|
|
"value '$pathString' must follow the pathString format, eg /1/2/" |
36
|
|
|
); |
37
|
|
|
} |
38
|
|
|
} |
39
|
|
|
|
40
|
|
|
parent::__construct(null, null, $value); |
41
|
|
|
} |
42
|
|
|
|
43
|
|
|
public function getSpecifications() |
44
|
|
|
{ |
45
|
|
|
return [ |
46
|
|
|
new Specifications( |
47
|
|
|
Operator::EQ, |
48
|
|
|
Specifications::FORMAT_SINGLE, |
49
|
|
|
Specifications::TYPE_STRING |
50
|
|
|
), |
51
|
|
|
new Specifications( |
52
|
|
|
Operator::IN, |
53
|
|
|
Specifications::FORMAT_ARRAY, |
54
|
|
|
Specifications::TYPE_STRING |
55
|
|
|
), |
56
|
|
|
]; |
57
|
|
|
} |
58
|
|
|
|
59
|
|
|
/** |
60
|
|
|
* @deprecated since 7.2, will be removed in 8.0. Use the constructor directly instead. |
61
|
|
|
*/ |
62
|
|
|
public static function createFromQueryBuilder($target, $operator, $value) |
63
|
|
|
{ |
64
|
|
|
@trigger_error('The ' . __METHOD__ . ' method is deprecated since version 7.2 and will be removed in 8.0.', E_USER_DEPRECATED); |
|
|
|
|
65
|
|
|
|
66
|
|
|
return new self($value); |
67
|
|
|
} |
68
|
|
|
} |
69
|
|
|
|
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.