| 1 | <?php declare(strict_types=1); |
||
| 11 | final class Mapper |
||
| 12 | { |
||
| 13 | 1 | public static function mapInstantiated(string $path, ?Reader $reader = null): iterable |
|
| 14 | { |
||
| 15 | 1 | foreach (self::map($path, $reader) as $command => $handler) { |
|
| 16 | 1 | yield $command => new $handler(); |
|
| 17 | } |
||
| 18 | 1 | } |
|
| 19 | |||
| 20 | 2 | public static function map(string $path, ?Reader $reader = null): iterable |
|
| 21 | { |
||
| 22 | 2 | foreach (listClassesInDirectory($path) as $class) { |
|
| 23 | 2 | $handler = self::getHandlerByCommand($class, $reader); |
|
| 24 | |||
| 25 | 2 | if ($handler === null || !\class_exists($handler)) { |
|
| 26 | 2 | continue; |
|
| 27 | } |
||
| 28 | |||
| 29 | 2 | yield $class => $handler; |
|
| 30 | } |
||
| 31 | 2 | } |
|
| 32 | |||
| 33 | 4 | public static function getHandlerByCommand(string $command, ?Reader $reader = null): ?string |
|
| 43 | } |
||
| 44 |