|
7 | 7 |
|
8 | 8 | class ClassFilesIA_NamespaceDirectoryPsr4 implements ClassFilesIAInterface { |
9 | 9 |
|
10 | | - /** |
11 | | - * See http://php.net/manual/en/language.oop5.basic.php |
12 | | - */ |
13 | | - const CLASS_NAME_REGEX = /** @lang RegExp */ '/^[a-zA-Z_\x7f-\xff][a-zA-Z0-9_\x7f-\xff]*$/'; |
14 | | - |
15 | 10 | /** |
16 | 11 | * @param string $dir |
17 | 12 | * @param string $namespace |
@@ -78,48 +73,7 @@ public function withRealpathRoot(): static { |
78 | 73 | * {@inheritdoc} |
79 | 74 | */ |
80 | 75 | public function getIterator(): \Iterator { |
81 | | - return self::scan($this->directory, $this->terminatedNamespace); |
| 76 | + return NsDirUtil::iterate($this->directory, $this->terminatedNamespace); |
82 | 77 | } |
83 | 78 |
|
84 | | - /** |
85 | | - * @param string $dir |
86 | | - * @param string $terminatedNamespace |
87 | | - * |
88 | | - * @return \Iterator<string, class-string> |
89 | | - * Format: $[$file] = $class |
90 | | - */ |
91 | | - private static function scan(string $dir, string $terminatedNamespace): \Iterator { |
92 | | - $candidates = @\scandir($dir, \SCANDIR_SORT_ASCENDING); |
93 | | - if ($candidates === false) { |
94 | | - throw new \RuntimeException("Failed to scandir('$dir')."); |
95 | | - } |
96 | | - foreach ($candidates as $candidate) { |
97 | | - if ('.' === $candidate[0]) { |
98 | | - continue; |
99 | | - } |
100 | | - $path = $dir . '/' . $candidate; |
101 | | - if (str_ends_with($candidate, '.php')) { |
102 | | - if (!is_file($path)) { |
103 | | - continue; |
104 | | - } |
105 | | - $name = substr($candidate, 0, -4); |
106 | | - if (!preg_match(self::CLASS_NAME_REGEX, $name)) { |
107 | | - continue; |
108 | | - } |
109 | | - // The value is a class-string, but PhpStan does not know. |
110 | | - // @phpstan-ignore generator.valueType |
111 | | - yield $path => $terminatedNamespace . $name; |
112 | | - } |
113 | | - else { |
114 | | - if (!is_dir($path)) { |
115 | | - continue; |
116 | | - } |
117 | | - if (!preg_match(self::CLASS_NAME_REGEX, $candidate)) { |
118 | | - continue; |
119 | | - } |
120 | | - // @todo Make PHP 7 version with "yield from". |
121 | | - yield from self::scan($path, $terminatedNamespace . $candidate . '\\'); |
122 | | - } |
123 | | - } |
124 | | - } |
125 | 79 | } |
0 commit comments