@@ -11,23 +11,20 @@ class TocFileParser
1111{
1212 public function __construct (
1313 private readonly FlavorEnum $ flavor ,
14+ /**
15+ * @var array<string, string> [lowercase path => real path]
16+ */
17+ private readonly array $ normalizedPathsMap ,
1418 ) {
1519 }
1620
1721 public function findTocFile (string $ dirWithToc ): ?string
1822 {
19- $ dir = new DirectoryIterator ($ dirWithToc );
20- $ tocFiles = [];
21- foreach ($ dir as $ fileInfo ) {
22- if ($ fileInfo ->isFile () && $ fileInfo ->getExtension () === 'toc ' ) {
23- $ tocFiles [strtolower ($ fileInfo ->getFilename ())] = $ fileInfo ->getFilename ();
24- }
25- }
2623 $ dirName = basename ($ dirWithToc );
2724 foreach ($ this ->getSuffixesForFlavor ($ this ->flavor ) as $ suffix ) {
28- $ tocFileName = strtolower ($ dirName . $ suffix . '.toc ' );
29- if (isset ($ tocFiles [$ tocFileName ])) {
30- return $ dirWithToc . ' / ' . $ tocFiles [$ tocFileName ];
25+ $ tocFileName = strtolower ($ dirWithToc . ' / ' . $ dirName . $ suffix . '.toc ' );
26+ if (isset ($ this -> normalizedPathsMap [$ tocFileName ])) {
27+ return $ this -> normalizedPathsMap [$ tocFileName ];
3128 }
3229 }
3330
@@ -117,10 +114,14 @@ public function listFiles(string $tocFilePath): array
117114
118115 $ line = trim ($ line );
119116 $ filePath = $ dir . '/ ' . ltrim ($ line , '/ ' );
120- $ files [] = $ filePath ;
117+ $ realPath = $ this ->normalizedPathsMap [strtolower ($ filePath )] ?? null ;
118+ if (!$ realPath ) {
119+ continue ;
120+ }
121+ $ files [] = $ realPath ;
121122
122123 if (str_ends_with ($ line , '.xml ' )) {
123- $ files = array_merge ($ files , $ this ->parseXmlIncludes ($ filePath ));
124+ $ files = array_merge ($ files , $ this ->parseXmlIncludes ($ realPath ));
124125 }
125126 }
126127
@@ -195,10 +196,11 @@ private function parseXmlIncludes(string $filePath, ?array &$tree = null): array
195196 if ($ file ) {
196197 $ file = (string ) $ file ;
197198 $ filePath = dirname ($ filePath ) . '/ ' . ltrim ($ file , '/ ' );
198- if (is_file ($ filePath )) {
199- $ files [] = $ filePath ;
200- if (str_ends_with ($ filePath , '.xml ' )) {
201- $ files = array_merge ($ files , $ this ->parseXmlIncludes ($ filePath , $ tree ));
199+ $ realPath = $ this ->normalizedPathsMap [strtolower ($ filePath )] ?? null ;
200+ if ($ realPath ) {
201+ $ files [] = $ realPath ;
202+ if (str_ends_with ($ realPath , '.xml ' )) {
203+ $ files = array_merge ($ files , $ this ->parseXmlIncludes ($ realPath , $ tree ));
202204 }
203205 }
204206 }
0 commit comments