|
7 | 7 | use Distill\Exception\IO\Input\FileEmptyException;
|
8 | 8 | use Distill\Exception\IO\Output\TargetDirectoryNotWritableException;
|
9 | 9 | use Distill\Strategy\MinimumSize;
|
| 10 | +use GuzzleHttp; |
10 | 11 | use GuzzleHttp\Client;
|
11 | 12 | use GuzzleHttp\Exception\ClientException;
|
12 | 13 | use GuzzleHttp\Message\Response;
|
@@ -122,9 +123,32 @@ private function checkSymfonyVersionIsInstallable()
|
122 | 123 | return $this;
|
123 | 124 | }
|
124 | 125 |
|
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 | + } |
128 | 152 | }
|
129 | 153 |
|
130 | 154 | // 2.0, 2.1, 2.2 and 2.4 cannot be installed because they are unmaintained
|
@@ -553,12 +577,12 @@ private function generateComposerProjectName()
|
553 | 577 | /**
|
554 | 578 | * Returns the executed command.
|
555 | 579 | *
|
| 580 | + * @param string $version A version to add to the command as example, if needed. |
556 | 581 | * @return string
|
557 | 582 | */
|
558 |
| - private function getExecutedCommand() |
| 583 | + private function getExecutedCommand($version = '') |
559 | 584 | {
|
560 |
| - $version = ''; |
561 |
| - if ('latest' !== $this->version) { |
| 585 | + if ('' === $version && 'latest' !== $this->version) { |
562 | 586 | $version = $this->version;
|
563 | 587 | }
|
564 | 588 |
|
|
0 commit comments