Completed
Push — create_from_qb ( 323041 )
by
unknown
12:48
created

LanguageCode::createFromQueryBuilder()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
nc 1
nop 3
dl 0
loc 6
rs 10
c 0
b 0
f 0
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