|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/** |
|
4
|
|
|
* File containing the eZ\Publish\API\Repository\Values\Content\Query\Criterion\LanguageCode 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 eZ\Publish\Core\Base\Exceptions\InvalidArgumentType; |
|
14
|
|
|
|
|
15
|
|
|
/** |
|
16
|
|
|
* A criterion that matches content based on its language code and always-available state. |
|
17
|
|
|
* |
|
18
|
|
|
* Supported operators: |
|
19
|
|
|
* - IN: matches against a list of language codes |
|
20
|
|
|
* - EQ: matches against one language code |
|
21
|
|
|
*/ |
|
22
|
|
|
class LanguageCode extends Criterion |
|
23
|
|
|
{ |
|
24
|
|
|
/** |
|
25
|
|
|
* Switch for matching Content that is always-available. |
|
26
|
|
|
* |
|
27
|
|
|
* @var bool |
|
28
|
|
|
*/ |
|
29
|
|
|
public $matchAlwaysAvailable; |
|
30
|
|
|
|
|
31
|
|
|
/** |
|
32
|
|
|
* Creates a new LanguageCode criterion. |
|
33
|
|
|
* |
|
34
|
|
|
* @param string|string[] $value One or more language codes that must be matched |
|
35
|
|
|
* @param bool $matchAlwaysAvailable Denotes if always-available Content is to be matched regardless |
|
36
|
|
|
* of language codes, this is the default behaviour |
|
37
|
|
|
* |
|
38
|
|
|
* @throws \InvalidArgumentException if non string value is given |
|
39
|
|
|
* @throws \InvalidArgumentException if the value type doesn't match the operator |
|
40
|
|
|
*/ |
|
41
|
|
|
public function __construct($value, $matchAlwaysAvailable = true) |
|
42
|
|
|
{ |
|
43
|
|
|
if (!is_bool($matchAlwaysAvailable)) { |
|
44
|
|
|
throw new InvalidArgumentType('matchAlwaysAvailable', 'boolean', $matchAlwaysAvailable); |
|
45
|
|
|
} |
|
46
|
|
|
|
|
47
|
|
|
$this->matchAlwaysAvailable = $matchAlwaysAvailable; |
|
48
|
|
|
parent::__construct(null, null, $value); |
|
49
|
|
|
} |
|
50
|
|
|
|
|
51
|
|
|
public function getSpecifications() |
|
52
|
|
|
{ |
|
53
|
|
|
return [ |
|
54
|
|
|
new Specifications( |
|
55
|
|
|
Operator::IN, |
|
56
|
|
|
Specifications::FORMAT_ARRAY, |
|
57
|
|
|
Specifications::TYPE_STRING |
|
58
|
|
|
), |
|
59
|
|
|
new Specifications( |
|
60
|
|
|
Operator::EQ, |
|
61
|
|
|
Specifications::FORMAT_SINGLE, |
|
62
|
|
|
Specifications::TYPE_STRING |
|
63
|
|
|
), |
|
64
|
|
|
]; |
|
65
|
|
|
} |
|
66
|
|
|
} |
|
67
|
|
|
|