1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/** |
4
|
|
|
* File containing the eZ\Publish\API\Repository\Values\Content\Query\Criterion\ContentId 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
|
|
|
|
14
|
|
|
/** |
15
|
|
|
* A criterion that matches content based on its id. |
16
|
|
|
* |
17
|
|
|
* Supported operators: |
18
|
|
|
* - IN: will match from a list of ContentId |
19
|
|
|
* - EQ: will match against one ContentId |
20
|
|
|
*/ |
21
|
|
View Code Duplication |
class ContentId extends Criterion |
|
|
|
|
22
|
|
|
{ |
23
|
|
|
/** |
24
|
|
|
* Creates a new ContentId criterion. |
25
|
|
|
* |
26
|
|
|
* @param int|int[] $value One or more content Id that must be matched. |
27
|
|
|
* |
28
|
|
|
* @throws \InvalidArgumentException if a non numeric id is given |
29
|
|
|
* @throws \InvalidArgumentException if the value type doesn't match the operator |
30
|
|
|
*/ |
31
|
|
|
public function __construct($value) |
32
|
|
|
{ |
33
|
|
|
parent::__construct(null, null, $value); |
34
|
|
|
} |
35
|
|
|
|
36
|
|
|
public function getSpecifications() |
37
|
|
|
{ |
38
|
|
|
$types = Specifications::TYPE_INTEGER | Specifications::TYPE_STRING; |
39
|
|
|
|
40
|
|
|
return [ |
41
|
|
|
new Specifications(Operator::IN, Specifications::FORMAT_ARRAY, $types), |
42
|
|
|
new Specifications(Operator::EQ, Specifications::FORMAT_SINGLE, $types), |
43
|
|
|
]; |
44
|
|
|
} |
45
|
|
|
|
46
|
|
|
/** |
47
|
|
|
* @deprecated since 7.2, will be removed in 8.0. Use the constructor directly instead. |
48
|
|
|
*/ |
49
|
|
|
public static function createFromQueryBuilder($target, $operator, $value) |
50
|
|
|
{ |
51
|
|
|
@trigger_error('The ' . __METHOD__ . ' method is deprecated since version 7.2 and will be removed in 8.0.', E_USER_DEPRECATED); |
|
|
|
|
52
|
|
|
|
53
|
|
|
return new self($value); |
54
|
|
|
} |
55
|
|
|
} |
56
|
|
|
|
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.