|
1
|
|
|
<?php |
|
2
|
|
|
/** |
|
3
|
|
|
* This program is free software. It comes without any warranty, to |
|
4
|
|
|
* the extent permitted by applicable law. You can redistribute it |
|
5
|
|
|
* and/or modify it under the terms of the Do What The Fuck You Want |
|
6
|
|
|
* To Public License, Version 2, as published by Sam Hocevar. See |
|
7
|
|
|
* http://www.wtfpl.net/ for more details. |
|
8
|
|
|
*/ |
|
9
|
|
|
|
|
10
|
|
|
declare(strict_types = 1); |
|
11
|
|
|
|
|
12
|
|
|
namespace hanneskod\classtools\Iterator\Filter; |
|
13
|
|
|
|
|
14
|
|
|
use hanneskod\classtools\Iterator\ClassIteratorInterface; |
|
15
|
|
|
use hanneskod\classtools\Exception\LogicException; |
|
16
|
|
|
use hanneskod\classtools\Iterator\SplFileInfo; |
|
17
|
|
|
|
|
18
|
|
|
/** |
|
19
|
|
|
* Implementation of Filter |
|
20
|
|
|
* |
|
21
|
|
|
* @author Hannes Forsgård <[email protected]> |
|
22
|
|
|
*/ |
|
23
|
|
|
trait FilterTrait |
|
24
|
|
|
{ |
|
25
|
|
|
/** |
|
26
|
|
|
* @var ClassIteratorInterface Iterator filter is bound to |
|
27
|
|
|
*/ |
|
28
|
|
|
private $boundIterator; |
|
29
|
|
|
|
|
30
|
|
|
public function bindTo(ClassIteratorInterface $iterator): void |
|
31
|
|
|
{ |
|
32
|
|
|
$this->boundIterator = $iterator; |
|
33
|
|
|
} |
|
34
|
|
|
|
|
35
|
|
|
public function getBoundIterator(): ClassIteratorInterface |
|
36
|
|
|
{ |
|
37
|
|
|
if (!isset($this->boundIterator)) { |
|
38
|
|
|
throw new LogicException("Filter not bound to iterator."); |
|
39
|
|
|
} |
|
40
|
|
|
return $this->boundIterator; |
|
41
|
|
|
} |
|
42
|
|
|
|
|
43
|
|
|
/** |
|
44
|
|
|
* Get map of classnames to SplFileInfo objects |
|
45
|
|
|
* |
|
46
|
|
|
* @return SplFileInfo[] |
|
47
|
|
|
*/ |
|
48
|
|
|
public function getClassMap(): array |
|
49
|
|
|
{ |
|
50
|
|
|
$parentMap = $this->getBoundIterator()->getClassMap(); |
|
51
|
|
|
$map = iterator_to_array($this->getIterator()); |
|
52
|
|
|
|
|
53
|
|
|
foreach ($map as $name => &$fileinfo) { |
|
54
|
|
|
$fileinfo = $parentMap[$name]; |
|
55
|
|
|
} |
|
56
|
|
|
|
|
57
|
|
|
return $map; |
|
58
|
|
|
} |
|
59
|
|
|
|
|
60
|
|
|
/** |
|
61
|
|
|
* Get current iterator |
|
62
|
|
|
*/ |
|
63
|
|
|
abstract public function getIterator(): iterable; |
|
64
|
|
|
} |
|
65
|
|
|
|