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

Commit f75f252

Browse files
committed
Issue #42 A better way to manage the version on install
1 parent 363a1ed commit f75f252

File tree

1 file changed

+30
-6
lines changed

1 file changed

+30
-6
lines changed

src/Symfony/Installer/NewCommand.php

Lines changed: 30 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
use Distill\Exception\IO\Input\FileEmptyException;
88
use Distill\Exception\IO\Output\TargetDirectoryNotWritableException;
99
use Distill\Strategy\MinimumSize;
10+
use GuzzleHttp;
1011
use GuzzleHttp\Client;
1112
use GuzzleHttp\Exception\ClientException;
1213
use GuzzleHttp\Message\Response;
@@ -122,9 +123,32 @@ private function checkSymfonyVersionIsInstallable()
122123
return $this;
123124
}
124125

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');
126+
// validate server syntax
127+
if (!preg_match('/^(2\.\d\.\d{1,2}|2\.\d)$/', $this->version)) {
128+
throw new \RuntimeException('The Symfony version should be 2.N or 2.N.M, where N = 0..9 and M = 0..99');
129+
}
130+
131+
if (preg_match('/^2\.\d$/', $this->version)) {
132+
// Check if we have a minor version
133+
134+
$json = @file_get_contents('http://symfony.com/versions.json');
135+
136+
if (false !== $json) {
137+
$versionsList = GuzzleHttp\json_decode($json, true);
138+
if (isset($versionsList[$this->version]) && in_array($versionsList[$this->version], $versionsList['installable'])) {
139+
// Get the latest installable of the minor version the user asked
140+
$this->version = $versionsList[$this->version];
141+
} else {
142+
throw new \RuntimeException(sprintf(
143+
"The selected version (%s) cannot be installed because it is not\n".
144+
"supported, or is considered as not installable for security reasons.\n".
145+
"To solve this issue, install Symfony with the latest available version by\n".
146+
"specifying no version, or simply using \"latest\" keyword as version name:\n%s",
147+
$this->version,
148+
$this->getExecutedCommand('latest')
149+
));
150+
}
151+
}
128152
}
129153

130154
// 2.0, 2.1, 2.2 and 2.4 cannot be installed because they are unmaintained
@@ -553,12 +577,12 @@ private function generateComposerProjectName()
553577
/**
554578
* Returns the executed command.
555579
*
580+
* @param string $version A version to add to the command as example, if needed.
556581
* @return string
557582
*/
558-
private function getExecutedCommand()
583+
private function getExecutedCommand($version = '')
559584
{
560-
$version = '';
561-
if ('latest' !== $this->version) {
585+
if ('' === $version && 'latest' !== $this->version) {
562586
$version = $this->version;
563587
}
564588

0 commit comments

Comments
 (0)