Thanks to visit codestin.com
Credit goes to github.com

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

Installation dev/beta versions (143) #159

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 33 additions & 9 deletions src/Symfony/Installer/NewCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -54,6 +55,7 @@ protected function execute(InputInterface $input, OutputInterface $output)
$this
->checkProjectName()
->checkSymfonyVersionIsInstallable()
->askUserConfirmation($input, $output)
->download()
->extract()
->cleanUp()
Expand All @@ -68,7 +70,7 @@ protected function execute(InputInterface $input, OutputInterface $output)
aborted:

$output->writeln('');
$output->writeln('<error>Aborting download and cleaning up temporary directories.</>');
$output->writeln('<error>Aborting download and cleaning up temporary directories.</error>');

$this->cleanUp();

Expand Down Expand Up @@ -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)) {
Expand Down Expand Up @@ -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('<question>You are trying to install an unstable version (%s). Do you confirm this action? [y/n]</question>', $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
Expand Down