From ea593fdb108b78f9337e584b84af91f129072c70 Mon Sep 17 00:00:00 2001 From: Jordi Boggiano Date: Thu, 8 Mar 2012 18:12:21 +0100 Subject: [PATCH] Allow autodetection of the version --- src/Composer/Command/CreateProjectCommand.php | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/src/Composer/Command/CreateProjectCommand.php b/src/Composer/Command/CreateProjectCommand.php index 007252969..d21fafb64 100644 --- a/src/Composer/Command/CreateProjectCommand.php +++ b/src/Composer/Command/CreateProjectCommand.php @@ -102,16 +102,24 @@ EOT throw new \InvalidArgumentException("Invalid repository url given. Has to be a .json file or an http url."); } - $package = $sourceRepo->findPackage($packageName, $version); - if (!$package) { - throw new \InvalidArgumentException("Could not find package $packageName with version $version."); + $candidates = $sourceRepo->findPackages($packageName, $version); + if (!$candidates) { + throw new \InvalidArgumentException("Could not find package $packageName" . ($version ? " with version $version." : '')); } if (null === $directory) { - $parts = explode("/", $packageName); + $parts = explode("/", $packageName, 2); $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('Installing ' . $package->getName() . ' as new project.', true); $projectInstaller = new ProjectInstaller($directory, $dm); $projectInstaller->install($package);