diff --git a/src/Composer/Command/InitCommand.php b/src/Composer/Command/InitCommand.php
index 577b73979..33df93a8b 100644
--- a/src/Composer/Command/InitCommand.php
+++ b/src/Composer/Command/InitCommand.php
@@ -385,9 +385,12 @@ EOT
foreach ($requires as $requirement) {
if (!isset($requirement['version'])) {
// determine the best version automatically
- $version = $this->findBestVersionForPackage($input, $requirement['name'], $phpVersion, $preferredStability);
+ list($name, $version) = $this->findBestVersionAndNameForPackage($input, $requirement['name'], $phpVersion, $preferredStability);
$requirement['version'] = $version;
+ // replace package name from packagist.org
+ $requirement['name'] = $name;
+
$io->writeError(sprintf(
'Using version %s for %s',
$requirement['version'],
@@ -395,7 +398,10 @@ EOT
));
} else {
// check that the specified version/constraint exists before we proceed
- $this->findBestVersionForPackage($input, $requirement['name'], $phpVersion, $preferredStability, $requirement['version'], 'dev');
+ list($name, $version) = $this->findBestVersionAndNameForPackage($input, $requirement['name'], $phpVersion, $preferredStability, $requirement['version'], 'dev');
+
+ // replace package name from packagist.org
+ $requirement['name'] = $name;
}
$result[] = $requirement['name'] . ' ' . $requirement['version'];
@@ -493,7 +499,7 @@ EOT
);
if (false === $constraint) {
- $constraint = $this->findBestVersionForPackage($input, $package, $phpVersion, $preferredStability);
+ list($name, $constraint) = $this->findBestVersionAndNameForPackage($input, $package, $phpVersion, $preferredStability);
$io->writeError(sprintf(
'Using version %s for %s',
@@ -665,9 +671,9 @@ EOT
* @param string|null $requiredVersion
* @param string $minimumStability
* @throws \InvalidArgumentException
- * @return string
+ * @return array name version
*/
- private function findBestVersionForPackage(InputInterface $input, $name, $phpVersion, $preferredStability = 'stable', $requiredVersion = null, $minimumStability = null)
+ private function findBestVersionAndNameForPackage(InputInterface $input, $name, $phpVersion, $preferredStability = 'stable', $requiredVersion = null, $minimumStability = null)
{
// find the latest version allowed in this pool
$versionSelector = new VersionSelector($this->getPool($input, $minimumStability));
@@ -715,7 +721,10 @@ EOT
));
}
- return $versionSelector->findRecommendedRequireVersion($package);
+ return array(
+ $package->getPrettyName(),
+ $versionSelector->findRecommendedRequireVersion($package)
+ );
}
private function findSimilar($package)
diff --git a/src/Composer/Package/Version/VersionParser.php b/src/Composer/Package/Version/VersionParser.php
index 54d7f09c0..22b6dad50 100644
--- a/src/Composer/Package/Version/VersionParser.php
+++ b/src/Composer/Package/Version/VersionParser.php
@@ -54,7 +54,7 @@ class VersionParser extends SemverVersionParser
}
if (strpos($pair, ' ')) {
- list($name, $version) = explode(" ", $pair, 2);
+ list($name, $version) = explode(' ', $pair, 2);
$result[] = array('name' => $name, 'version' => $version);
} else {
$result[] = array('name' => $pair);