1
0
Fork 0

Allow autodetection of the version

pull/413/head
Jordi Boggiano 2012-03-08 18:12:21 +01:00
parent 347f8feeec
commit ea593fdb10
1 changed files with 12 additions and 4 deletions

View File

@ -102,16 +102,24 @@ EOT
throw new \InvalidArgumentException("Invalid repository url given. Has to be a .json file or an http url."); throw new \InvalidArgumentException("Invalid repository url given. Has to be a .json file or an http url.");
} }
$package = $sourceRepo->findPackage($packageName, $version); $candidates = $sourceRepo->findPackages($packageName, $version);
if (!$package) { if (!$candidates) {
throw new \InvalidArgumentException("Could not find package $packageName with version $version."); throw new \InvalidArgumentException("Could not find package $packageName" . ($version ? " with version $version." : ''));
} }
if (null === $directory) { if (null === $directory) {
$parts = explode("/", $packageName); $parts = explode("/", $packageName, 2);
$directory = getcwd() . DIRECTORY_SEPARATOR . array_pop($parts); $directory = getcwd() . DIRECTORY_SEPARATOR . array_pop($parts);
} }
// select highest version if we have many
$package = $candidates[0];
foreach ($candidates as $candidate) {
if (version_compare($package->getVersion(), $candidate->getVersion(), '<')) {
$package = $candidate;
}
}
$io->write('<info>Installing ' . $package->getName() . ' as new project.</info>', true); $io->write('<info>Installing ' . $package->getName() . ' as new project.</info>', true);
$projectInstaller = new ProjectInstaller($directory, $dm); $projectInstaller = new ProjectInstaller($directory, $dm);
$projectInstaller->install($package); $projectInstaller->install($package);