@@ 22-48 (lines=27) @@ | ||
19 | * |
|
20 | * @author Hannes Forsgård <[email protected]> |
|
21 | */ |
|
22 | final class NameFilter extends ClassIterator implements Filter |
|
23 | { |
|
24 | use FilterTrait; |
|
25 | ||
26 | /** |
|
27 | * @var string Regular expression for matching definition names |
|
28 | */ |
|
29 | private $pattern; |
|
30 | ||
31 | /** |
|
32 | * Register matching regular expression |
|
33 | */ |
|
34 | public function __construct(string $pattern) |
|
35 | { |
|
36 | parent::__construct(); |
|
37 | $this->pattern = $pattern; |
|
38 | } |
|
39 | ||
40 | public function getIterator(): iterable |
|
41 | { |
|
42 | foreach ($this->getBoundIterator() as $className => $reflectedClass) { |
|
43 | if (preg_match($this->pattern, $className)) { |
|
44 | yield $className => $reflectedClass; |
|
45 | } |
|
46 | } |
|
47 | } |
|
48 | } |
|
49 |
@@ 23-49 (lines=27) @@ | ||
20 | * |
|
21 | * @author Hannes Forsgård <[email protected]> |
|
22 | */ |
|
23 | final class NamespaceFilter extends ClassIterator implements Filter |
|
24 | { |
|
25 | use FilterTrait; |
|
26 | ||
27 | /** |
|
28 | * @var string |
|
29 | */ |
|
30 | private $namespace; |
|
31 | ||
32 | /** |
|
33 | * Register namespace to filter on |
|
34 | */ |
|
35 | public function __construct(string $namespace) |
|
36 | { |
|
37 | parent::__construct(); |
|
38 | $this->namespace = new Name((string)$namespace); |
|
39 | } |
|
40 | ||
41 | public function getIterator(): iterable |
|
42 | { |
|
43 | foreach ($this->getBoundIterator() as $className => $reflectedClass) { |
|
44 | if ((new Name($className))->inNamespace($this->namespace)) { |
|
45 | yield $className => $reflectedClass; |
|
46 | } |
|
47 | } |
|
48 | } |
|
49 | } |
|
50 |