|
18 | 18 | use Composer\IO\IOInterface; |
19 | 19 | use Composer\Package\AliasPackage; |
20 | 20 | use Composer\Package\PackageInterface; |
| 21 | +use Composer\Package\RootPackageInterface; |
21 | 22 | use Composer\Repository\InstalledRepositoryInterface; |
22 | 23 | use Composer\Repository\PlatformRepository; |
23 | 24 | use Composer\Semver\Constraint\Bound; |
@@ -136,7 +137,7 @@ public function setIgnorePlatformRequirements($ignorePlatformReqs) |
136 | 137 | } |
137 | 138 | } |
138 | 139 |
|
139 | | - public function dump(Config $config, InstalledRepositoryInterface $localRepo, PackageInterface $mainPackage, InstallationManager $installationManager, $targetDir, $scanPsrPackages = false, $suffix = '') |
| 140 | + public function dump(Config $config, InstalledRepositoryInterface $localRepo, RootPackageInterface $rootPackage, InstallationManager $installationManager, $targetDir, $scanPsrPackages = false, $suffix = '') |
140 | 141 | { |
141 | 142 | if ($this->classMapAuthoritative) { |
142 | 143 | // Force scanPsrPackages when classmap is authoritative |
@@ -193,8 +194,8 @@ public function dump(Config $config, InstalledRepositoryInterface $localRepo, Pa |
193 | 194 |
|
194 | 195 | // Collect information from all packages. |
195 | 196 | $devPackageNames = $localRepo->getDevPackageNames(); |
196 | | - $packageMap = $this->buildPackageMap($installationManager, $mainPackage, $localRepo->getCanonicalPackages()); |
197 | | - $autoloads = $this->parseAutoloads($packageMap, $mainPackage, $this->devMode === false); |
| 197 | + $packageMap = $this->buildPackageMap($installationManager, $rootPackage, $localRepo->getCanonicalPackages()); |
| 198 | + $autoloads = $this->parseAutoloads($packageMap, $rootPackage, $this->devMode === false); |
198 | 199 |
|
199 | 200 | // Process the 'psr-0' base directories. |
200 | 201 | foreach ($autoloads['psr-0'] as $namespace => $paths) { |
@@ -234,9 +235,9 @@ public function dump(Config $config, InstalledRepositoryInterface $localRepo, Pa |
234 | 235 |
|
235 | 236 | // add custom psr-0 autoloading if the root package has a target dir |
236 | 237 | $targetDirLoader = null; |
237 | | - $mainAutoload = $mainPackage->getAutoload(); |
238 | | - if ($mainPackage->getTargetDir() && !empty($mainAutoload['psr-0'])) { |
239 | | - $levels = substr_count($filesystem->normalizePath($mainPackage->getTargetDir()), '/') + 1; |
| 238 | + $mainAutoload = $rootPackage->getAutoload(); |
| 239 | + if ($rootPackage->getTargetDir() && !empty($mainAutoload['psr-0'])) { |
| 240 | + $levels = substr_count($filesystem->normalizePath($rootPackage->getTargetDir()), '/') + 1; |
240 | 241 | $prefixes = implode(', ', array_map(function ($prefix) { |
241 | 242 | return var_export($prefix, true); |
242 | 243 | }, array_keys($mainAutoload['psr-0']))); |
@@ -395,10 +396,13 @@ private function generateClassMap($dir, $excluded, $namespaceFilter, $autoloadTy |
395 | 396 | return ClassMapGenerator::createMap($dir, $excluded, $showAmbiguousWarning ? $this->io : null, $namespaceFilter, $autoloadType, $scannedFiles); |
396 | 397 | } |
397 | 398 |
|
398 | | - public function buildPackageMap(InstallationManager $installationManager, PackageInterface $mainPackage, array $packages) |
| 399 | + /** |
| 400 | + * @param RootPackageInterface $rootPackage |
| 401 | + */ |
| 402 | + public function buildPackageMap(InstallationManager $installationManager, PackageInterface $rootPackage, array $packages) |
399 | 403 | { |
400 | 404 | // build package => install path map |
401 | | - $packageMap = array(array($mainPackage, '')); |
| 405 | + $packageMap = array(array($rootPackage, '')); |
402 | 406 |
|
403 | 407 | foreach ($packages as $package) { |
404 | 408 | if ($package instanceof AliasPackage) { |
@@ -440,26 +444,26 @@ protected function validatePackage(PackageInterface $package) |
440 | 444 | /** |
441 | 445 | * Compiles an ordered list of namespace => path mappings |
442 | 446 | * |
443 | | - * @param array $packageMap array of array(package, installDir-relative-to-composer.json) |
444 | | - * @param PackageInterface $mainPackage root package instance |
445 | | - * @param bool $filterOutRequireDevPackages whether to filter out require-dev packages |
446 | | - * @return array array('psr-0' => array('Ns\\Foo' => array('installDir'))) |
| 447 | + * @param array $packageMap array of array(package, installDir-relative-to-composer.json) |
| 448 | + * @param RootPackageInterface $rootPackage root package instance |
| 449 | + * @param bool $filterOutRequireDevPackages whether to filter out require-dev packages |
| 450 | + * @return array array('psr-0' => array('Ns\\Foo' => array('installDir'))) |
447 | 451 | */ |
448 | | - public function parseAutoloads(array $packageMap, PackageInterface $mainPackage, $filterOutRequireDevPackages = false) |
| 452 | + public function parseAutoloads(array $packageMap, PackageInterface $rootPackage, $filterOutRequireDevPackages = false) |
449 | 453 | { |
450 | | - $mainPackageMap = array_shift($packageMap); |
| 454 | + $rootPackageMap = array_shift($packageMap); |
451 | 455 | if ($filterOutRequireDevPackages) { |
452 | | - $packageMap = $this->filterPackageMap($packageMap, $mainPackage); |
| 456 | + $packageMap = $this->filterPackageMap($packageMap, $rootPackage); |
453 | 457 | } |
454 | 458 | $sortedPackageMap = $this->sortPackageMap($packageMap); |
455 | | - $sortedPackageMap[] = $mainPackageMap; |
456 | | - array_unshift($packageMap, $mainPackageMap); |
| 459 | + $sortedPackageMap[] = $rootPackageMap; |
| 460 | + array_unshift($packageMap, $rootPackageMap); |
457 | 461 |
|
458 | | - $psr0 = $this->parseAutoloadsType($packageMap, 'psr-0', $mainPackage); |
459 | | - $psr4 = $this->parseAutoloadsType($packageMap, 'psr-4', $mainPackage); |
460 | | - $classmap = $this->parseAutoloadsType(array_reverse($sortedPackageMap), 'classmap', $mainPackage); |
461 | | - $files = $this->parseAutoloadsType($sortedPackageMap, 'files', $mainPackage); |
462 | | - $exclude = $this->parseAutoloadsType($sortedPackageMap, 'exclude-from-classmap', $mainPackage); |
| 462 | + $psr0 = $this->parseAutoloadsType($packageMap, 'psr-0', $rootPackage); |
| 463 | + $psr4 = $this->parseAutoloadsType($packageMap, 'psr-4', $rootPackage); |
| 464 | + $classmap = $this->parseAutoloadsType(array_reverse($sortedPackageMap), 'classmap', $rootPackage); |
| 465 | + $files = $this->parseAutoloadsType($sortedPackageMap, 'files', $rootPackage); |
| 466 | + $exclude = $this->parseAutoloadsType($sortedPackageMap, 'exclude-from-classmap', $rootPackage); |
463 | 467 |
|
464 | 468 | krsort($psr0); |
465 | 469 | krsort($psr4); |
@@ -1051,31 +1055,31 @@ public static function getInitializer(ClassLoader \$loader) |
1051 | 1055 | INITIALIZER; |
1052 | 1056 | } |
1053 | 1057 |
|
1054 | | - protected function parseAutoloadsType(array $packageMap, $type, PackageInterface $mainPackage) |
| 1058 | + protected function parseAutoloadsType(array $packageMap, $type, RootPackageInterface $rootPackage) |
1055 | 1059 | { |
1056 | 1060 | $autoloads = array(); |
1057 | 1061 |
|
1058 | 1062 | foreach ($packageMap as $item) { |
1059 | 1063 | list($package, $installPath) = $item; |
1060 | 1064 |
|
1061 | 1065 | $autoload = $package->getAutoload(); |
1062 | | - if ($this->devMode && $package === $mainPackage) { |
| 1066 | + if ($this->devMode && $package === $rootPackage) { |
1063 | 1067 | $autoload = array_merge_recursive($autoload, $package->getDevAutoload()); |
1064 | 1068 | } |
1065 | 1069 |
|
1066 | 1070 | // skip misconfigured packages |
1067 | 1071 | if (!isset($autoload[$type]) || !is_array($autoload[$type])) { |
1068 | 1072 | continue; |
1069 | 1073 | } |
1070 | | - if (null !== $package->getTargetDir() && $package !== $mainPackage) { |
| 1074 | + if (null !== $package->getTargetDir() && $package !== $rootPackage) { |
1071 | 1075 | $installPath = substr($installPath, 0, -strlen('/'.$package->getTargetDir())); |
1072 | 1076 | } |
1073 | 1077 |
|
1074 | 1078 | foreach ($autoload[$type] as $namespace => $paths) { |
1075 | 1079 | foreach ((array) $paths as $path) { |
1076 | 1080 | if (($type === 'files' || $type === 'classmap' || $type === 'exclude-from-classmap') && $package->getTargetDir() && !is_readable($installPath.'/'.$path)) { |
1077 | 1081 | // remove target-dir from file paths of the root package |
1078 | | - if ($package === $mainPackage) { |
| 1082 | + if ($package === $rootPackage) { |
1079 | 1083 | $targetDir = str_replace('\\<dirsep\\>', '[\\\\/]', preg_quote(str_replace(array('/', '\\'), '<dirsep>', $package->getTargetDir()))); |
1080 | 1084 | $path = ltrim(preg_replace('{^'.$targetDir.'}', '', ltrim($path, '\\/')), '\\/'); |
1081 | 1085 | } else { |
@@ -1141,11 +1145,11 @@ protected function getFileIdentifier(PackageInterface $package, $path) |
1141 | 1145 | /** |
1142 | 1146 | * Filters out dev-dependencies |
1143 | 1147 | * |
1144 | | - * @param array $packageMap |
1145 | | - * @param PackageInterface $mainPackage |
| 1148 | + * @param array $packageMap |
| 1149 | + * @param RootPackageInterface $rootPackage |
1146 | 1150 | * @return array |
1147 | 1151 | */ |
1148 | | - protected function filterPackageMap(array $packageMap, PackageInterface $mainPackage) |
| 1152 | + protected function filterPackageMap(array $packageMap, RootPackageInterface $rootPackage) |
1149 | 1153 | { |
1150 | 1154 | $packages = array(); |
1151 | 1155 | $include = array(); |
@@ -1174,7 +1178,7 @@ protected function filterPackageMap(array $packageMap, PackageInterface $mainPac |
1174 | 1178 | } |
1175 | 1179 | } |
1176 | 1180 | }; |
1177 | | - $add($mainPackage); |
| 1181 | + $add($rootPackage); |
1178 | 1182 |
|
1179 | 1183 | return array_filter( |
1180 | 1184 | $packageMap, |
|
0 commit comments