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

Commit 1b1899e

Browse files
committed
feature #90 Issue #42 A better way to manage the version on install (Pierstoval)
This PR was squashed before being merged into the 1.0-dev branch (closes #90). Discussion ---------- Issue #42 A better way to manage the version on install Commits ------- 4546869 Issue #42 A better way to manage the version on install
2 parents 3ae6556 + 4546869 commit 1b1899e

File tree

1 file changed

+26
-4
lines changed

1 file changed

+26
-4
lines changed

src/Symfony/Installer/NewCommand.php

Lines changed: 26 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -133,9 +133,31 @@ private function checkSymfonyVersionIsInstallable()
133133
return $this;
134134
}
135135

136-
// validate semver syntax
137-
if (!preg_match('/^2\.\d\.\d{1,2}$/', $this->version)) {
138-
throw new \RuntimeException('The Symfony version should be 2.N.M, where N = 0..9 and M = 0..99');
136+
// validate server syntax
137+
if (!preg_match('/^2\.\d(?:\.\d{1,2})?$/', $this->version)) {
138+
throw new \RuntimeException('The Symfony version should be 2.N or 2.N.M, where N = 0..9 and M = 0..99');
139+
}
140+
141+
if (preg_match('/^2\.\d$/', $this->version)) {
142+
// Check if we have a minor version in order to retrieve the last patch from symfony.com
143+
144+
$client = new Client();
145+
$versionsList = $client->get('http://symfony.com/versions.json')->json();
146+
147+
if ($versionsList && isset($versionsList[$this->version])) {
148+
// Get the latest patch of the minor version the user asked
149+
$this->version = $versionsList[$this->version];
150+
} elseif ($versionsList && !isset($versionsList[$this->version])) {
151+
throw new \RuntimeException(sprintf(
152+
"The selected branch (%s) does not exist, or is not maintained.\n".
153+
"To solve this issue, install Symfony with the latest stable release:\n\n".
154+
'%s %s %s',
155+
$this->version,
156+
$_SERVER['PHP_SELF'],
157+
$this->getName(),
158+
$this->projectDir
159+
));
160+
}
139161
}
140162

141163
// 2.0, 2.1, 2.2 and 2.4 cannot be installed because they are unmaintained
@@ -251,7 +273,7 @@ private function download()
251273
));
252274
} else {
253275
throw new \RuntimeException(sprintf(
254-
"The selected version (%s) couldn\'t be downloaded because of the following error:\n%s",
276+
"The selected version (%s) couldn't be downloaded because of the following error:\n%s",
255277
$this->version,
256278
$e->getMessage()
257279
));

0 commit comments

Comments
 (0)