1 | <?php |
||
14 | class PatternMatcher implements PatternMatcherInterface { |
||
15 | |||
16 | /** |
||
17 | * @var Collection[] |
||
18 | */ |
||
19 | protected $collections = []; |
||
20 | |||
21 | |||
22 | /** |
||
23 | * @param Collection $collection |
||
24 | */ |
||
25 | 201 | public function __construct(Collection $collection) { |
|
26 | 201 | $this->collections[] = $collection; |
|
27 | 201 | } |
|
28 | |||
29 | |||
30 | /** |
||
31 | * @inheritdoc |
||
32 | */ |
||
33 | 201 | public function apply(callable $pattern) { |
|
34 | |||
35 | # Clear current collections. |
||
36 | # We will add new one and iterate over current |
||
37 | |||
38 | 201 | $collections = $this->collections; |
|
39 | 201 | $this->collections = []; |
|
40 | |||
41 | 201 | foreach ($collections as $collection) { |
|
42 | |||
43 | 201 | $collectionsResult = $this->iterateOverCollections($pattern, $collection); |
|
44 | |||
45 | 189 | foreach ($collectionsResult as $resultCollection) { |
|
46 | 189 | $this->collections[] = $resultCollection; |
|
47 | } |
||
48 | |||
49 | } |
||
50 | |||
51 | 189 | return $this; |
|
52 | } |
||
53 | |||
54 | |||
55 | /** |
||
56 | * @inheritdoc |
||
57 | */ |
||
58 | 129 | public function getCollections() { |
|
59 | 129 | return $this->collections; |
|
60 | } |
||
61 | |||
62 | |||
63 | /** |
||
64 | * @param callable $pattern |
||
65 | * @param Collection $collection |
||
66 | * @return Collection[] |
||
67 | * @throws Exception |
||
68 | */ |
||
69 | 201 | protected function iterateOverCollections(callable $pattern, Collection $collection) { |
|
89 | |||
90 | |||
91 | } |