Explorar o código

Allow autodetection of the version

Jordi Boggiano %!s(int64=13) %!d(string=hai) anos
pai
achega
ea593fdb10
Modificáronse 1 ficheiros con 12 adicións e 4 borrados
  1. 12 4
      src/Composer/Command/CreateProjectCommand.php

+ 12 - 4
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('<info>Installing ' . $package->getName() . ' as new project.</info>', true);
         $projectInstaller = new ProjectInstaller($directory, $dm);
         $projectInstaller->install($package);