From 3bed9d6666381456cc896c9e206fad5a058ed6f1 Mon Sep 17 00:00:00 2001 From: Antoine Makdessi Date: Mon, 11 May 2015 11:33:16 +0200 Subject: [PATCH] Installation dev/beta versions (143) --- src/Symfony/Installer/NewCommand.php | 42 ++++++++++++++++++++++------ 1 file changed, 33 insertions(+), 9 deletions(-) diff --git a/src/Symfony/Installer/NewCommand.php b/src/Symfony/Installer/NewCommand.php index da28fbb..c62aae8 100644 --- a/src/Symfony/Installer/NewCommand.php +++ b/src/Symfony/Installer/NewCommand.php @@ -15,6 +15,7 @@ use Symfony\Component\Console\Input\InputInterface; use Symfony\Component\Console\Output\OutputInterface; use Symfony\Installer\Exception\AbortException; +use Symfony\Component\Console\Question\ConfirmationQuestion; /** * This command creates new Symfony projects for the given Symfony version. @@ -54,6 +55,7 @@ protected function execute(InputInterface $input, OutputInterface $output) $this ->checkProjectName() ->checkSymfonyVersionIsInstallable() + ->askUserConfirmation($input, $output) ->download() ->extract() ->cleanUp() @@ -68,7 +70,7 @@ protected function execute(InputInterface $input, OutputInterface $output) aborted: $output->writeln(''); - $output->writeln('Aborting download and cleaning up temporary directories.'); + $output->writeln('Aborting download and cleaning up temporary directories.'); $this->cleanUp(); @@ -103,20 +105,17 @@ protected function execute(InputInterface $input, OutputInterface $output) */ protected function checkSymfonyVersionIsInstallable() { + // Available at the moment of installing Symfony with this installer. // 'latest' is a special version name that refers to the latest stable version - // available at the moment of installing Symfony - if ('latest' === $this->version) { - return $this; - } - // 'lts' is a special version name that refers to the current long term support version - if ('lts' === $this->version) { + // 'dev' is a special version name that refers to the current development version + if (in_array($this->version, array('latest', 'lts', 'dev'))) { 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 or 2.N.M, where N = 0..9 and M = 0..99'); + if (!preg_match('/^2\.\d(?:\.\d{1,2})?(-(dev|BETA)\d*)?$/', $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)) { @@ -177,6 +176,31 @@ protected function checkSymfonyVersionIsInstallable() return $this; } + /** + * @param InputInterface $input + * @param OutputInterface $output + * + * @return NewCommand + * + * @throws AbortException If the user wants to stop the download process in case of dev/BETA versions + */ + protected function askUserConfirmation(InputInterface $input, OutputInterface $output) + { + if (preg_match('/^(\d\.\d)(\.\d{1,2})?-(dev|BETA)\d*$/', $this->version)) { + $helper = $this->getHelper('question'); + $question = new ConfirmationQuestion( + sprintf('You are trying to install an unstable version (%s). Do you confirm this action? [y/n]', $this->version), + false + ); + + if (!$helper->ask($input, $output, $question)) { + throw new AbortException(); + } + } + + return $this; + } + /** * Removes all the temporary files and directories created to * download the project and removes Symfony-related files that don't make