| @@ 18-55 (lines=38) @@ | ||
| 15 | * Note that the class should ideally have been in a Logical namespace, but it would have then be named 'And', |
|
| 16 | * and 'And' is a PHP reserved word. |
|
| 17 | */ |
|
| 18 | abstract class LogicalOperator extends Criterion |
|
| 19 | { |
|
| 20 | /** |
|
| 21 | * The set of criteria combined by the logical operator. |
|
| 22 | * |
|
| 23 | * @var Criterion[] |
|
| 24 | */ |
|
| 25 | public $criteria = array(); |
|
| 26 | ||
| 27 | /** |
|
| 28 | * Creates a Logic operation with the given criteria. |
|
| 29 | * |
|
| 30 | * @param Criterion[] $criteria |
|
| 31 | * |
|
| 32 | * @throws \InvalidArgumentException |
|
| 33 | */ |
|
| 34 | public function __construct(array $criteria) |
|
| 35 | { |
|
| 36 | foreach ($criteria as $key => $criterion) { |
|
| 37 | if (!$criterion instanceof Criterion) { |
|
| 38 | if ($criterion === null) { |
|
| 39 | $type = 'null'; |
|
| 40 | } elseif (is_object($criterion)) { |
|
| 41 | $type = get_class($criterion); |
|
| 42 | } elseif (is_array($criterion)) { |
|
| 43 | $type = 'Array, with keys: ' . implode(', ', array_keys($criterion)); |
|
| 44 | } else { |
|
| 45 | $type = gettype($criterion) . ", with value: '{$criterion}'"; |
|
| 46 | } |
|
| 47 | ||
| 48 | throw new InvalidArgumentException( |
|
| 49 | "Only Criterion objects are accepted, at index '{$key}': " . $type |
|
| 50 | ); |
|
| 51 | } |
|
| 52 | $this->criteria[] = $criterion; |
|
| 53 | } |
|
| 54 | } |
|
| 55 | } |
|
| 56 | ||
| @@ 12-50 (lines=39) @@ | ||
| 9 | use eZ\Publish\API\Repository\Values\URL\Query\Criterion; |
|
| 10 | use InvalidArgumentException; |
|
| 11 | ||
| 12 | abstract class LogicalOperator extends Criterion |
|
| 13 | { |
|
| 14 | /** |
|
| 15 | * The set of criteria combined by the logical operator. |
|
| 16 | * |
|
| 17 | * @var Criterion[] |
|
| 18 | */ |
|
| 19 | public $criteria = []; |
|
| 20 | ||
| 21 | /** |
|
| 22 | * Creates a Logic operation with the given criteria. |
|
| 23 | * |
|
| 24 | * @param Criterion[] $criteria |
|
| 25 | * |
|
| 26 | * @throws \InvalidArgumentException |
|
| 27 | */ |
|
| 28 | public function __construct(array $criteria) |
|
| 29 | { |
|
| 30 | foreach ($criteria as $key => $criterion) { |
|
| 31 | if (!$criterion instanceof Criterion) { |
|
| 32 | if ($criterion === null) { |
|
| 33 | $type = 'null'; |
|
| 34 | } elseif (is_object($criterion)) { |
|
| 35 | $type = get_class($criterion); |
|
| 36 | } elseif (is_array($criterion)) { |
|
| 37 | $type = 'Array, with keys: ' . implode(', ', array_keys($criterion)); |
|
| 38 | } else { |
|
| 39 | $type = gettype($criterion) . ", with value: '{$criterion}'"; |
|
| 40 | } |
|
| 41 | ||
| 42 | throw new InvalidArgumentException( |
|
| 43 | "Only Criterion objects are accepted, at index '{$key}': " . $type |
|
| 44 | ); |
|
| 45 | } |
|
| 46 | ||
| 47 | $this->criteria[] = $criterion; |
|
| 48 | } |
|
| 49 | } |
|
| 50 | } |
|
| 51 | ||