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

Ancestor::createFromQueryBuilder()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6

Duplication

Lines 6
Ratio 100 %

Importance

Changes 0
Metric Value
cc 1
nc 1
nop 3
dl 6
loc 6
rs 10
c 0
b 0
f 0
1
<?php
2
3
/**
4
 * This file is part of the eZ Publish Kernel package.
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 InvalidArgumentException;
14
15
/**
16
 * A criterion that matches content that is ancestor to the given Location path string.
17
 *
18
 * Content will be matched if it is part of at least one of the given subtree path strings.
19
 */
20
class Ancestor extends Criterion
21
{
22
    /**
23
     * Creates a new Ancestor criterion.
24
     *
25
     * @param string $value Location path string
26
     *
27
     * @throws \InvalidArgumentException if a non integer or string id is given
28
     * @throws \InvalidArgumentException if the value type doesn't match the operator
29
     */
30
    public function __construct($value)
31
    {
32
        foreach ((array)$value as $pathString) {
33
            if (preg_match('/^(\/\w+)+\/$/', $pathString) !== 1) {
34
                throw new InvalidArgumentException(
35
                    "'$pathString' value must follow the pathString format, e.g. /1/2/"
36
                );
37
            }
38
        }
39
40
        parent::__construct(null, null, $value);
41
    }
42
43
    public function getSpecifications()
44
    {
45
        return [
46
            new Specifications(
47
                Operator::EQ,
48
                Specifications::FORMAT_SINGLE,
49
                Specifications::TYPE_STRING
50
            ),
51
            new Specifications(
52
                Operator::IN,
53
                Specifications::FORMAT_ARRAY,
54
                Specifications::TYPE_STRING
55
            ),
56
        ];
57
    }
58
}
59