>, * psr-4?: array>, * classmap?: list, * files?: list, * exclude-from-classmap?: list * } * @psalm-type ComposerPackage array{ * name: string, * autoload: ComposerAutoload * } * @psalm-type Composer array{ * autoload: ComposerAutoload, * config?: array{vendor-dir?: string} * } */ final class MakeLocatorForComposerJson { public function __invoke(string $installationPath, Locator $astLocator): SourceLocator { $realInstallationPath = (string) realpath($installationPath); if (! is_dir($realInstallationPath)) { throw InvalidProjectDirectory::atPath($installationPath); } $composerJsonPath = $realInstallationPath . '/composer.json'; if (! is_file($composerJsonPath)) { throw MissingComposerJson::inProjectPath($installationPath); } $composerJsonContent = file_get_contents($composerJsonPath); assert(is_string($composerJsonContent)); /** @psalm-var array{autoload: ComposerAutoload}|null $composer */ $composer = json_decode($composerJsonContent, true); if (! is_array($composer)) { throw FailedToParseJson::inFile($composerJsonPath); } $pathPrefix = $realInstallationPath . '/'; $classMapPaths = $this->prefixPaths($this->packageToClassMapPaths($composer), $pathPrefix); $classMapFiles = array_filter($classMapPaths, 'is_file'); $classMapDirectories = array_values(array_filter($classMapPaths, 'is_dir')); $filePaths = $this->prefixPaths($this->packageToFilePaths($composer), $pathPrefix); return new AggregateSourceLocator(array_merge( [ new PsrAutoloaderLocator( Psr4Mapping::fromArrayMappings( $this->prefixWithInstallationPath($this->packageToPsr4AutoloadNamespaces($composer), $pathPrefix), ), $astLocator, ), new PsrAutoloaderLocator( Psr0Mapping::fromArrayMappings( $this->prefixWithInstallationPath($this->packageToPsr0AutoloadNamespaces($composer), $pathPrefix), ), $astLocator, ), new DirectoriesSourceLocator($classMapDirectories, $astLocator), ], ...array_map( static function (string $file) use ($astLocator): array { assert($file !== ''); return [new SingleFileSourceLocator($file, $astLocator)]; }, array_merge($classMapFiles, $filePaths), ), )); } /** * @param array{autoload: ComposerAutoload} $package * * @return array> */ private function packageToPsr4AutoloadNamespaces(array $package): array { return array_map(static fn (string|array $namespacePaths): array => (array) $namespacePaths, $package['autoload']['psr-4'] ?? []); } /** * @param array{autoload: ComposerAutoload} $package * * @return array> */ private function packageToPsr0AutoloadNamespaces(array $package): array { return array_map(static fn (string|array $namespacePaths): array => (array) $namespacePaths, $package['autoload']['psr-0'] ?? []); } /** * @param array{autoload: ComposerAutoload} $package * * @return list */ private function packageToClassMapPaths(array $package): array { return $package['autoload']['classmap'] ?? []; } /** * @param array{autoload: ComposerAutoload} $package * * @return list */ private function packageToFilePaths(array $package): array { return $package['autoload']['files'] ?? []; } /** * @param array> $paths * * @return array> */ private function prefixWithInstallationPath(array $paths, string $trimmedInstallationPath): array { return array_map(fn (array $paths): array => $this->prefixPaths($paths, $trimmedInstallationPath), $paths); } /** * @param list $paths * * @return list */ private function prefixPaths(array $paths, string $prefix): array { return array_map(static fn (string $path): string => $prefix . $path, $paths); } } __halt_compiler();----SIGNATURE:----xJq+LLRlYtYkinwTZXZKiENZKDrCXOnr7DK+OWDBrvVeH5aLmX4cbEcJ4gRUux4l0WTiO4JNA7gW/00AZzB5A5UYYxTRYBnCNPa+dlvO00qdWZ/UPU6zPwZSphYQ1yS31s/T5i6nc7hfGIIX3jo1o+3WNmU/gDaxlhS4x2MVSuLSAdTyDVvKmfq1Jmkdtz96FbM+iwtY6Y3cZ7+cem/Xk3yr4teg+XmykStq9IAYRVfELJq8OXfU2ohFAdEypE2RZFakMBVj3sNdGuYqxxw/4TRJGcLbL6h+ZBvmHSYFywMJRtNV/Mw02KRKirQepumtXXLeBYh17dC/bSUGLJwl2+XcpOMla8krZOaWhoWyL4YOSKZ+cqMDT3VV7AxVTPsmQdnFdXo7LNV97RqZXBdFzEk+hE15Eftmr4k/SF4qA4DWo1DtUZ4zAUFrYYCLfGB6Te0b09EPqYgHoPMgdkdyc41XqJ2BozlH1BCiPyo3DnxHKI8wmQp702ht3kXzyG879n+yquKWRlTDbfyXO4ONMqoSAx2DTGAOCGN7kcyiQll/r26yPQFe0LECdn8UPuRGgSKFUOsjcg8uYlliN5OXEAZzePFBiHolEmh5abbVjs/50XxpfjQd0zcVeQSpqjFL7XnSg5Yw2n1QQqbMxNCWACJB7J8niHH0DvhBJArA+cs=----ATTACHMENT:----MTg4NjkyMDI0NTIwNjc5IDUxMDA0NjQwNDQ1ODQ2NzcgMzc3MjY5MDgyNDMyNjI1MA==