@@ 13-59 (lines=47) @@ | ||
10 | * @author Krzysztof Gzocha <[email protected]> |
|
11 | * @author Daniel Ribeiro <[email protected]> |
|
12 | */ |
|
13 | class CriteriaCollection extends AbstractCollection implements CriteriaCollectionInterface |
|
14 | { |
|
15 | /** |
|
16 | * @param CriteriaInterface[] $criteria array or \Traversable object |
|
17 | */ |
|
18 | public function __construct($criteria = []) |
|
19 | { |
|
20 | parent::__construct($criteria); |
|
21 | } |
|
22 | ||
23 | /** |
|
24 | * {@inheritdoc} |
|
25 | */ |
|
26 | public function getApplicableCriteria(): CriteriaCollectionInterface |
|
27 | { |
|
28 | return new self(array_filter( |
|
29 | $this->getItems(), |
|
30 | function (CriteriaInterface $criteria) { |
|
31 | return $criteria->shouldBeApplied(); |
|
32 | } |
|
33 | )); |
|
34 | } |
|
35 | ||
36 | /** |
|
37 | * {@inheritdoc} |
|
38 | */ |
|
39 | public function getCriteria() |
|
40 | { |
|
41 | return $this->getItems(); |
|
42 | } |
|
43 | ||
44 | /** |
|
45 | * {@inheritdoc} |
|
46 | */ |
|
47 | public function addCriteria(CriteriaInterface $criteria): CriteriaCollectionInterface |
|
48 | { |
|
49 | return $this->addItem($criteria); |
|
50 | } |
|
51 | ||
52 | /** |
|
53 | * {@inheritdoc} |
|
54 | */ |
|
55 | protected function isItemValid($item): bool |
|
56 | { |
|
57 | return $item instanceof CriteriaInterface; |
|
58 | } |
|
59 | } |
|
60 |
@@ 13-61 (lines=49) @@ | ||
10 | /** |
|
11 | * @author Krzysztof Gzocha <[email protected]> |
|
12 | */ |
|
13 | class CriteriaBuilderCollection extends AbstractCollection implements CriteriaBuilderCollectionInterface |
|
14 | { |
|
15 | /** |
|
16 | * @param CriteriaBuilderInterface[] $builders array or \Traversable object |
|
17 | */ |
|
18 | public function __construct($builders = []) |
|
19 | { |
|
20 | parent::__construct($builders); |
|
21 | } |
|
22 | ||
23 | /** |
|
24 | * {@inheritdoc} |
|
25 | */ |
|
26 | public function addCriteriaBuilder(CriteriaBuilderInterface $criteriaBuilder): CriteriaBuilderCollectionInterface |
|
27 | { |
|
28 | return $this->addItem($criteriaBuilder); |
|
29 | } |
|
30 | ||
31 | /** |
|
32 | * {@inheritdoc} |
|
33 | */ |
|
34 | public function getCriteriaBuilders() |
|
35 | { |
|
36 | return $this->getItems(); |
|
37 | } |
|
38 | ||
39 | /** |
|
40 | * {@inheritdoc} |
|
41 | */ |
|
42 | public function getCriteriaBuildersForContext( |
|
43 | SearchingContextInterface $searchingContext |
|
44 | ): CriteriaBuilderCollectionInterface { |
|
45 | return new self(array_filter( |
|
46 | $this->getItems(), |
|
47 | function (CriteriaBuilderInterface $criteriaBuilder) use ($searchingContext) { |
|
48 | return $criteriaBuilder->supportsSearchingContext($searchingContext); |
|
49 | } |
|
50 | )); |
|
51 | } |
|
52 | ||
53 | /** |
|
54 | * {@inheritdoc} |
|
55 | */ |
|
56 | protected function isItemValid($item): bool |
|
57 | { |
|
58 | return $item instanceof CriteriaBuilderInterface; |
|
59 | } |
|
60 | } |
|
61 |