>, * 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:----vdHQ2QMhDsjcB0NWaQmNM/EDRoZf4o6XnWFG6BqnDk2BUdn0VH9WQ4Y1LmICNYYUQwMo45jnz9R84R83Zt9cVklLpQ4WAfXiOwgwM3wHF64oOEHnNlfaSRtSVYvhRRn8aP5U3Oktc6WqdlVrdtHG1MYdm1pAFX1IzsFP52bKkQR8CYGrL5UG83bu9pMeZuvCc/uVzNDJfVUp4z2TilJJ7lNW2jMeLmOmty7OxJPYFXxM/fY6QMzx9R2XsP+Sm8/lzYswfM2DsXEyjYNJFrZs93bh056ujlpR1KWvQ0nbeWcXZhzO2YUIQFwJL7qna5LnUmgHl3qx0j5akxVvYNkLs1xSHcmtcG0jagHsxGHbDk/Og4iiHZZ/Xo2uji3vcoWmMuVVfKCGt4GLgkYLhJ2qNq00LVsGOmfIWyVDu8e8TaVHoLvhOBOfABeDSGa1XMnIKq4KznqSn3OgxWPlTe1ADj4a12xqsBupAIVxaiiwNXfwzJprqJCYly+MD85MuM/Mg+0YZztbKzJWwEypSLKW6r1oVCvrv/HhJ6uNVYtYcPxNcRS8h+9K2JoUlnRKUS3LrnLdmbcayOY4dWaQGYt98QfmK/b4x72BxUqboNIBZ48rVz4dnVpAkApMXC1acXH5cwcS7xb/RKbR6Jh+NOGCUJSryWPKQiT5WR/amqPzZs4=----ATTACHMENT:----NzMyNDE2MzY5NDQ0ODE1NiA5MjM3NDAzMzI2MTkxMDk4IDI5MzQ4NDc2NDYzNjQ1NTg=