1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/** |
4
|
|
|
* File containing the eZ\Publish\API\Repository\Values\Content\Query\Criterion\LogicalOperator 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\Exceptions\NotImplementedException; |
12
|
|
|
use eZ\Publish\API\Repository\Values\Content\Query\Criterion; |
13
|
|
|
use InvalidArgumentException; |
14
|
|
|
|
15
|
|
|
/** |
16
|
|
|
* Note that the class should ideally have been in a Logical namespace, but it would have then be named 'And', |
17
|
|
|
* and 'And' is a PHP reserved word. |
18
|
|
|
*/ |
19
|
|
|
abstract class LogicalOperator extends Criterion |
20
|
|
|
{ |
21
|
|
|
/** |
22
|
|
|
* The set of criteria combined by the logical operator. |
23
|
|
|
* |
24
|
|
|
* @var Criterion[] |
25
|
|
|
*/ |
26
|
|
|
public $criteria = array(); |
27
|
|
|
|
28
|
|
|
/** |
29
|
|
|
* Creates a Logic operation with the given criteria. |
30
|
|
|
* |
31
|
|
|
* @param Criterion[] $criteria |
32
|
|
|
* |
33
|
|
|
* @throws \InvalidArgumentException |
34
|
|
|
*/ |
35
|
|
|
public function __construct(array $criteria) |
36
|
|
|
{ |
37
|
|
|
foreach ($criteria as $key => $criterion) { |
38
|
|
|
if (!$criterion instanceof Criterion) { |
39
|
|
|
if ($criterion === null) { |
40
|
|
|
$type = 'null'; |
41
|
|
|
} elseif (is_object($criterion)) { |
42
|
|
|
$type = get_class($criterion); |
43
|
|
|
} elseif (is_array($criterion)) { |
44
|
|
|
$type = 'Array, with keys: ' . implode(', ', array_keys($criterion)); |
45
|
|
|
} else { |
46
|
|
|
$type = gettype($criterion) . ", with value: '{$criterion}'"; |
47
|
|
|
} |
48
|
|
|
|
49
|
|
|
throw new InvalidArgumentException( |
50
|
|
|
"Only Criterion objects are accepted, at index '{$key}': " . $type |
51
|
|
|
); |
52
|
|
|
} |
53
|
|
|
$this->criteria[] = $criterion; |
54
|
|
|
} |
55
|
|
|
} |
56
|
|
|
|
57
|
|
|
/** |
58
|
|
|
* @deprecated in LogicalOperators since 7.2. |
59
|
|
|
* It will be removed in 8.0 when Logical Operator no longer extends Criterion. |
60
|
|
|
*/ |
61
|
|
|
public function getSpecifications() |
62
|
|
|
{ |
63
|
|
|
@trigger_error('The ' . __METHOD__ . ' method is deprecated since version 7.2 and will be removed in 8.0.', E_USER_DEPRECATED); |
|
|
|
|
64
|
|
|
|
65
|
|
|
throw new NotImplementedException('getSpecifications() not implemented for LogicalOperators'); |
66
|
|
|
} |
67
|
|
|
} |
68
|
|
|
|
If you suppress an error, we recommend checking for the error condition explicitly: