Skip to content
This repository was archived by the owner on Nov 14, 2019. It is now read-only.

Issue #42 A better way to manage the version on install #90

Closed
wants to merge 8 commits into from
30 changes: 26 additions & 4 deletions src/Symfony/Installer/NewCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -122,9 +122,31 @@ private function checkSymfonyVersionIsInstallable()
return $this;
}

// validate semver syntax
if (!preg_match('/^2\.\d\.\d{1,2}$/', $this->version)) {
throw new \RuntimeException('The Symfony version should be 2.N.M, where N = 0..9 and M = 0..99');
// validate server syntax
if (!preg_match('/^2\.\d(?:\.\d{1,2})?$/', $this->version)) {
throw new \RuntimeException('The Symfony version should be 2.N or 2.N.M, where N = 0..9 and M = 0..99');
}

if (preg_match('/^2\.\d$/', $this->version)) {
// Check if we have a minor version in order to retrieve the last patch from symfony.com

$client = new Client();
$versionsList = $client->get('http://symfony.com/versions.json')->json();

if ($versionsList && isset($versionsList[$this->version])) {
// Get the latest patch of the minor version the user asked
$this->version = $versionsList[$this->version];
} elseif ($versionsList && !isset($versionsList[$this->version])) {
throw new \RuntimeException(sprintf(
"The selected branch (%s) does not exist, or is not maintained.\n".
"To solve this issue, install Symfony with the latest stable release:\n\n".
'%s %s %s',
$this->version,
$_SERVER['PHP_SELF'],
$this->getName(),
$this->projectDir
));
}
}

// 2.0, 2.1, 2.2 and 2.4 cannot be installed because they are unmaintained
Expand Down Expand Up @@ -241,7 +263,7 @@ private function download()
));
} else {
throw new \RuntimeException(sprintf(
"The selected version (%s) couldn\'t be downloaded because of the following error:\n%s",
"The selected version (%s) couldn't be downloaded because of the following error:\n%s",
$this->version,
$e->getMessage()
));
Expand Down