1 | <?php |
||
35 | class ClassMapList implements FileListInterface, \Countable |
||
36 | { |
||
37 | use IteratorTrait; |
||
38 | |||
39 | protected $list = array(); |
||
40 | |||
41 | /** |
||
42 | * Add an SPL-File-Info to the filelist |
||
43 | * |
||
44 | * @param \SplFileInfo $file |
||
45 | * |
||
46 | * @return void |
||
47 | */ |
||
48 | 4 | public function add(\SplFileInfo $file) |
|
49 | { |
||
50 | 4 | $content = new \Org_Heigl\FileFinder\Service\Tokenlist(file_get_contents($file->getPathname())); |
|
51 | 4 | $classname = $content->getClassName(); |
|
52 | 4 | if (! $classname) { |
|
53 | 1 | return; |
|
54 | } |
||
55 | |||
56 | 4 | $class = $content->getNamespace(); |
|
57 | 4 | $class[] = $classname; |
|
58 | |||
59 | 4 | $key = str_replace('\\\\', '\\', '\\' . implode('\\', $class)); |
|
60 | |||
61 | 4 | $this->list[$key] = realpath($file->getPathname()); |
|
62 | 4 | } |
|
63 | |||
64 | /** |
||
65 | * Clear all entries from the filelist |
||
66 | * |
||
67 | * @return void |
||
68 | */ |
||
69 | 3 | public function clear() |
|
70 | { |
||
71 | 3 | $this->list = array(); |
|
72 | 3 | } |
|
73 | |||
74 | /** |
||
75 | * (PHP 5 >= 5.1.0)<br/> |
||
76 | * Count elements of an object |
||
77 | * |
||
78 | * @link http://php.net/manual/en/countable.count.php |
||
79 | * @return int The custom count as an integer. |
||
80 | * </p> |
||
81 | * <p> |
||
82 | * The return value is cast to an integer. |
||
83 | */ |
||
84 | 1 | public function count() |
|
85 | { |
||
86 | 1 | return count($this->list); |
|
87 | } |
||
88 | |||
89 | /** |
||
90 | * Get the content as array |
||
91 | * |
||
92 | * @return array |
||
93 | */ |
||
94 | 2 | public function toArray() |
|
98 | |||
99 | /** |
||
100 | * Get the array the iterator shall iterate over. |
||
101 | * |
||
102 | * @return mixed |
||
103 | */ |
||
104 | 1 | protected function & getIteratorArray() |
|
108 | } |
||
109 |