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

Commit 4546869

Browse files
Pierstovaljaviereguiluz
authored andcommitted
Issue #42 A better way to manage the version on install
1 parent 363a1ed commit 4546869

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
@@ -122,9 +122,31 @@ private function checkSymfonyVersionIsInstallable()
122122
return $this;
123123
}
124124

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

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

0 commit comments

Comments
 (0)