add support for package based install type preferences
parent
e5985a9b55
commit
bf08b6eb90
|
@ -117,8 +117,8 @@
|
||||||
"description": "If true, the Composer autoloader will also look for classes in the PHP include path."
|
"description": "If true, the Composer autoloader will also look for classes in the PHP include path."
|
||||||
},
|
},
|
||||||
"preferred-install": {
|
"preferred-install": {
|
||||||
"type": "string",
|
"type": ["string", "object"],
|
||||||
"description": "The install method Composer will prefer to use, defaults to auto and can be any of source, dist or auto."
|
"description": "The install method Composer will prefer to use, defaults to auto and can be any of source, dist, auto, or a hash of {\"pattern\": \"preference\"}."
|
||||||
},
|
},
|
||||||
"notify-on-install": {
|
"notify-on-install": {
|
||||||
"type": "boolean",
|
"type": "boolean",
|
||||||
|
|
|
@ -108,6 +108,20 @@ class Config
|
||||||
foreach ($config['config'] as $key => $val) {
|
foreach ($config['config'] as $key => $val) {
|
||||||
if (in_array($key, array('github-oauth', 'http-basic')) && isset($this->config[$key])) {
|
if (in_array($key, array('github-oauth', 'http-basic')) && isset($this->config[$key])) {
|
||||||
$this->config[$key] = array_merge($this->config[$key], $val);
|
$this->config[$key] = array_merge($this->config[$key], $val);
|
||||||
|
} elseif ('preferred-install' === $key && isset($this->config[$key])) {
|
||||||
|
if (is_string($val)) {
|
||||||
|
$val = array('*' => $val);
|
||||||
|
}
|
||||||
|
if (is_string($this->config[$key])) {
|
||||||
|
$this->config[$key] = array('*' => $this->config[$key]);
|
||||||
|
}
|
||||||
|
$this->config[$key] = array_merge($this->config[$key], $val);
|
||||||
|
// the full match pattern needs to be last
|
||||||
|
if (isset($this->config[$key]['*'])) {
|
||||||
|
$wildcard = $this->config[$key]['*'];
|
||||||
|
unset($this->config[$key]['*']);
|
||||||
|
$this->config[$key]['*'] = $wildcard;
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
$this->config[$key] = $val;
|
$this->config[$key] = $val;
|
||||||
}
|
}
|
||||||
|
|
|
@ -26,6 +26,7 @@ class DownloadManager
|
||||||
private $io;
|
private $io;
|
||||||
private $preferDist = false;
|
private $preferDist = false;
|
||||||
private $preferSource = false;
|
private $preferSource = false;
|
||||||
|
private $packagePreferences = array();
|
||||||
private $filesystem;
|
private $filesystem;
|
||||||
private $downloaders = array();
|
private $downloaders = array();
|
||||||
|
|
||||||
|
@ -69,6 +70,19 @@ class DownloadManager
|
||||||
return $this;
|
return $this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sets fine tuned preference settings for package level source/dist selection.
|
||||||
|
*
|
||||||
|
* @param array $preferences array of preferences by package patterns
|
||||||
|
* @return DownloadManager
|
||||||
|
*/
|
||||||
|
public function setPreferences(array $preferences)
|
||||||
|
{
|
||||||
|
$this->packagePreferences = $preferences;
|
||||||
|
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Sets whether to output download progress information for all registered
|
* Sets whether to output download progress information for all registered
|
||||||
* downloaders
|
* downloaders
|
||||||
|
@ -184,7 +198,17 @@ class DownloadManager
|
||||||
throw new \InvalidArgumentException('Package '.$package.' must have a source or dist specified');
|
throw new \InvalidArgumentException('Package '.$package.' must have a source or dist specified');
|
||||||
}
|
}
|
||||||
|
|
||||||
if ((!$package->isDev() || $this->preferDist) && !$preferSource) {
|
if (!$this->preferDist && !$preferSource) {
|
||||||
|
foreach ($this->packagePreferences as $pattern => $preference) {
|
||||||
|
$pattern = '{^'.str_replace('*', '.*', $pattern).'$}i';
|
||||||
|
if (preg_match($pattern, $package->getName())) {
|
||||||
|
if ('dist' === $preference || (!$package->isDev() && 'auto' === $preference)) {
|
||||||
|
$sources = array_reverse($sources);
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} elseif ((!$package->isDev() || $this->preferDist) && !$preferSource) {
|
||||||
$sources = array_reverse($sources);
|
$sources = array_reverse($sources);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -383,7 +383,7 @@ class Factory
|
||||||
}
|
}
|
||||||
|
|
||||||
$dm = new Downloader\DownloadManager($io);
|
$dm = new Downloader\DownloadManager($io);
|
||||||
switch ($config->get('preferred-install')) {
|
switch ($preferred = $config->get('preferred-install')) {
|
||||||
case 'dist':
|
case 'dist':
|
||||||
$dm->setPreferDist(true);
|
$dm->setPreferDist(true);
|
||||||
break;
|
break;
|
||||||
|
@ -396,6 +396,10 @@ class Factory
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (is_array($preferred)) {
|
||||||
|
$dm->setPreferences($preferred);
|
||||||
|
}
|
||||||
|
|
||||||
$dm->setDownloader('git', new Downloader\GitDownloader($io, $config));
|
$dm->setDownloader('git', new Downloader\GitDownloader($io, $config));
|
||||||
$dm->setDownloader('svn', new Downloader\SvnDownloader($io, $config));
|
$dm->setDownloader('svn', new Downloader\SvnDownloader($io, $config));
|
||||||
$dm->setDownloader('hg', new Downloader\HgDownloader($io, $config));
|
$dm->setDownloader('hg', new Downloader\HgDownloader($io, $config));
|
||||||
|
|
Loading…
Reference in New Issue