1 | <?php |
||
12 | final class Mapper |
||
13 | { |
||
14 | /** |
||
15 | * @param string $path |
||
16 | * @param string $namespace |
||
17 | * @return array |
||
18 | */ |
||
19 | public static function mapInstantiated($path, $namespace) |
||
29 | |||
30 | /** |
||
31 | * @param string $path |
||
32 | * @param string $namespace |
||
33 | * @return array |
||
34 | */ |
||
35 | 1 | public static function map($path, $namespace) |
|
36 | { |
||
37 | 1 | $reader = new AnnotationReader(); |
|
38 | 1 | $mapping = []; |
|
39 | |||
40 | 1 | $directory = new RecursiveDirectoryIterator($path); |
|
41 | 1 | $directory = new RecursiveIteratorIterator($directory); |
|
42 | |||
43 | 1 | foreach ($directory as $node) { |
|
44 | 1 | if (!is_file($node->getPathname())) { |
|
45 | 1 | continue; |
|
46 | } |
||
47 | |||
48 | 1 | $file = substr($node->getPathname(), strlen($path)); |
|
49 | 1 | $file = ltrim($file, DIRECTORY_SEPARATOR); |
|
50 | 1 | $file = rtrim($file, '.php'); |
|
51 | |||
52 | 1 | $class = $namespace . '\\' . str_replace(DIRECTORY_SEPARATOR, '\\', $file); |
|
53 | |||
54 | 1 | if (!class_exists($class)) { |
|
55 | continue; |
||
56 | } |
||
57 | |||
58 | 1 | $handler = self::getHandlerByCommand($class, $reader); |
|
59 | |||
60 | if (!class_exists($handler)) { |
||
61 | continue; |
||
62 | } |
||
63 | |||
64 | $mapping[$class] = $handler; |
||
65 | } |
||
66 | |||
67 | return $mapping; |
||
68 | } |
||
69 | |||
70 | /** |
||
71 | * @param string $command |
||
72 | * @param Reader $reader |
||
73 | * @return string |
||
74 | */ |
||
75 | 3 | public static function getHandlerByCommand($command, Reader $reader) |
|
85 | } |
||
86 |