Skip to content

Commit 196bbaf

Browse files
author
Christian Opitz
committed
Include replacing packages into package providers (composer#367)
1 parent aa25081 commit 196bbaf

File tree

1 file changed

+31
-3
lines changed

1 file changed

+31
-3
lines changed

src/Builder/PackagesBuilder.php

+31-3
Original file line numberDiff line numberDiff line change
@@ -70,12 +70,18 @@ public function dump(array $packages)
7070
}
7171
$repo['providers'] = [];
7272
$i = 1;
73+
// Give each version a unique ID
7374
foreach ($packagesByName as $packageName => $versionPackages) {
74-
foreach ($versionPackages as $version => &$versionPackage) {
75-
$versionPackage['uid'] = $i++;
75+
foreach ($versionPackages as $version => $versionPackage) {
76+
$packagesByName[$packageName][$version]['uid'] = $i++;
7677
}
78+
}
79+
// Dump the packages along with packages they're replaced by
80+
foreach ($packagesByName as $packageName => $versionPackages) {
81+
$dumpPackages = $this->findReplacements($packagesByName, $packageName);
82+
$dumpPackages[$packageName] = $versionPackages;
7783
$includes = $this->dumpPackageIncludeJson(
78-
[$packageName => $versionPackages],
84+
$dumpPackages,
7985
str_replace('%package%', $packageName, $providersUrl),
8086
'sha256'
8187
);
@@ -90,6 +96,28 @@ public function dump(array $packages)
9096
$this->pruneIncludeDirectories();
9197
}
9298

99+
/**
100+
* Find packages replacing the $replaced packages
101+
*
102+
* @param array $packages
103+
* @param string $replaced
104+
*
105+
* @return array
106+
*/
107+
private function findReplacements($packages, $replaced)
108+
{
109+
$replacements = array();
110+
foreach ($packages as $packageName => $packageConfig) {
111+
foreach ($packageConfig as $versionConfig) {
112+
if (!empty($versionConfig['replace']) && array_key_exists($replaced, $versionConfig['replace'])) {
113+
$replacements[$packageName] = $packageConfig;
114+
break;
115+
}
116+
}
117+
}
118+
return $replacements;
119+
}
120+
93121
/**
94122
* Remove all files matching the includeUrl pattern next to just created include jsons
95123
*/

0 commit comments

Comments
 (0)