Remove duplication of branch alias parsing code
parent
774021bf99
commit
26e8217db7
|
@ -134,28 +134,9 @@ class ArrayLoader implements LoaderInterface
|
|||
$package->setDistSha1Checksum(isset($config['dist']['shasum']) ? $config['dist']['shasum'] : null);
|
||||
}
|
||||
|
||||
// check for a branch alias (dev-master => 1.0.x-dev for example) if this is a named branch
|
||||
if ('dev-' === substr($package->getPrettyVersion(), 0, 4) && isset($config['extra']['branch-alias']) && is_array($config['extra']['branch-alias'])) {
|
||||
foreach ($config['extra']['branch-alias'] as $sourceBranch => $targetBranch) {
|
||||
// ensure it is an alias to a -dev package
|
||||
if ('-dev' !== substr($targetBranch, -4)) {
|
||||
continue;
|
||||
}
|
||||
// normalize without -dev and ensure it's a numeric branch that is parseable
|
||||
$validatedTargetBranch = $this->versionParser->normalizeBranch(substr($targetBranch, 0, -4));
|
||||
if ('-dev' !== substr($validatedTargetBranch, -4)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
// ensure that it is the current branch aliasing itself
|
||||
if (strtolower($package->getPrettyVersion()) !== strtolower($sourceBranch)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$package->setAlias($validatedTargetBranch);
|
||||
$package->setPrettyAlias(preg_replace('{(\.9{7})+}', '.x', $validatedTargetBranch));
|
||||
break;
|
||||
}
|
||||
if ($aliasNormalized = $this->getBranchAlias($config)) {
|
||||
$package->setAlias($aliasNormalized);
|
||||
$package->setPrettyAlias(preg_replace('{(\.9{7})+}', '.x', $aliasNormalized));
|
||||
}
|
||||
|
||||
foreach (Package\BasePackage::$supportedLinkTypes as $type => $opts) {
|
||||
|
@ -191,6 +172,42 @@ class ArrayLoader implements LoaderInterface
|
|||
return $package;
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieves a branch alias (dev-master => 1.0.x-dev for example) if it exists
|
||||
*
|
||||
* @param array $config the entire package config
|
||||
* @return string|null normalized version of the branch alias or null if there is none
|
||||
*/
|
||||
public function getBranchAlias(array $config)
|
||||
{
|
||||
if ('dev-' !== substr($config['version'], 0, 4)
|
||||
|| !isset($config['extra']['branch-alias'])
|
||||
|| !is_array($config['extra']['branch-alias'])
|
||||
) {
|
||||
return;
|
||||
}
|
||||
|
||||
foreach ($config['extra']['branch-alias'] as $sourceBranch => $targetBranch) {
|
||||
// ensure it is an alias to a -dev package
|
||||
if ('-dev' !== substr($targetBranch, -4)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
// normalize without -dev and ensure it's a numeric branch that is parseable
|
||||
$validatedTargetBranch = $this->versionParser->normalizeBranch(substr($targetBranch, 0, -4));
|
||||
if ('-dev' !== substr($validatedTargetBranch, -4)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
// ensure that it is the current branch aliasing itself
|
||||
if (strtolower($config['version']) !== strtolower($sourceBranch)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
return $validatedTargetBranch;
|
||||
}
|
||||
}
|
||||
|
||||
private function loadLinksFromConfig($package, $description, array $linksSpecs)
|
||||
{
|
||||
$links = array();
|
||||
|
|
|
@ -108,29 +108,9 @@ class ComposerRepository extends ArrayRepository implements NotifiableRepository
|
|||
}
|
||||
|
||||
// add branch aliases
|
||||
if ('dev-' === substr($package['version'], 0, 4) && isset($package['extra']['branch-alias']) && is_array($package['extra']['branch-alias'])) {
|
||||
foreach ($package['extra']['branch-alias'] as $sourceBranch => $targetBranch) {
|
||||
// ensure it is an alias to a -dev package
|
||||
if ('-dev' !== substr($targetBranch, -4)) {
|
||||
continue;
|
||||
}
|
||||
// normalize without -dev and ensure it's a numeric branch that is parseable
|
||||
$validatedTargetBranch = $versionParser->normalizeBranch(substr($targetBranch, 0, -4));
|
||||
if ('-dev' !== substr($validatedTargetBranch, -4)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
// ensure that it is the current branch aliasing itself
|
||||
if (strtolower($package['version']) !== strtolower($sourceBranch)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$alias = preg_replace('{(\.9{7})+}', '.x', $validatedTargetBranch);
|
||||
$aliasNormalized = $validatedTargetBranch;
|
||||
$data['alias'] = $alias;
|
||||
if ($aliasNormalized = $this->loader->getBranchAlias($package)) {
|
||||
$data['alias'] = preg_replace('{(\.9{7})+}', '.x', $aliasNormalized);
|
||||
$data['alias_normalized'] = $aliasNormalized;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
$this->minimalPackages[] = $data;
|
||||
|
|
Loading…
Reference in New Issue