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

Commit 9645168

Browse files
committed
feature #155 Added support for a specific directory in demo command (lyrixx)
This PR was merged into the 1.0-dev branch. Discussion ---------- Added support for a specific directory in demo command fixes #154 Commits ------- 8a9c43b Added support for a specific directory in demo command
2 parents a218a51 + 8a9c43b commit 9645168

File tree

3 files changed

+36
-16
lines changed

3 files changed

+36
-16
lines changed

src/Symfony/Installer/DemoCommand.php

Lines changed: 17 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111

1212
namespace Symfony\Installer;
1313

14+
use Symfony\Component\Console\Input\InputArgument;
1415
use Symfony\Component\Console\Input\InputInterface;
1516
use Symfony\Component\Console\Output\OutputInterface;
1617

@@ -21,15 +22,14 @@
2122
*/
2223
class DemoCommand extends DownloadCommand
2324
{
24-
protected $projectName;
25-
protected $projectDir;
2625
protected $downloadedFilePath;
2726
protected $requirementsErrors = array();
2827

2928
protected function configure()
3029
{
3130
$this
3231
->setName('demo')
32+
->addArgument('directory', InputArgument::OPTIONAL, 'Directory where the new project will be created.', 'symfony_demo')
3333
->setDescription('Creates a demo Symfony project.')
3434
;
3535
}
@@ -38,22 +38,29 @@ protected function initialize(InputInterface $input, OutputInterface $output)
3838
{
3939
parent::initialize($input, $output);
4040

41-
$this->projectDir = getcwd();
41+
if (!$input->getArgument('directory')) {
42+
$this->projectDir = getcwd();
4243

43-
$i = 1;
44-
$projectName = 'symfony_demo';
45-
while (file_exists($this->projectDir.DIRECTORY_SEPARATOR.$projectName)) {
46-
$projectName = 'symfony_demo_'.(++$i);
47-
}
44+
$i = 1;
45+
$projectName = 'symfony_demo';
46+
while (file_exists($this->projectDir.DIRECTORY_SEPARATOR.$projectName)) {
47+
$projectName = 'symfony_demo_'.(++$i);
48+
}
4849

49-
$this->projectName = $projectName;
50-
$this->projectDir = $this->projectDir.DIRECTORY_SEPARATOR.$projectName;
50+
$this->projectName = $projectName;
51+
$this->projectDir = $this->projectDir.DIRECTORY_SEPARATOR.$projectName;
52+
} else {
53+
$directory = rtrim(trim($input->getArgument('directory')), DIRECTORY_SEPARATOR);
54+
$this->projectDir = $this->fs->isAbsolutePath($directory) ? $directory : getcwd().DIRECTORY_SEPARATOR.$directory;
55+
$this->projectName = basename($directory);
56+
}
5157
}
5258

5359
protected function execute(InputInterface $input, OutputInterface $output)
5460
{
5561
try {
5662
$this
63+
->checkProjectName()
5764
->download()
5865
->extract()
5966
->cleanUp()

src/Symfony/Installer/DownloadCommand.php

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,8 @@ abstract class DownloadCommand extends Command
3838
protected $fs;
3939
/** @var OutputInterface */
4040
protected $output;
41+
protected $projectName;
42+
protected $projectDir;
4143

4244
/**
4345
* Returns the type of the downloaded application in a human readable format.
@@ -150,6 +152,19 @@ protected function download()
150152
return $this;
151153
}
152154

155+
protected function checkProjectName()
156+
{
157+
if (is_dir($this->projectDir) && !$this->isEmptyDirectory($this->projectDir)) {
158+
throw new \RuntimeException(sprintf(
159+
"There is already a '%s' project in this directory (%s).\n".
160+
'Change your project name or create it in another directory.',
161+
$this->projectName, $this->projectDir
162+
));
163+
}
164+
165+
return $this;
166+
}
167+
153168
/**
154169
* Returns the Guzzle client configured according to the system environment
155170
* (e.g. it takes into account whether it should use a proxy server or not).

src/Symfony/Installer/NewCommand.php

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,6 @@
2323
*/
2424
class NewCommand extends DownloadCommand
2525
{
26-
protected $projectName;
27-
protected $projectDir;
2826
protected $version;
2927
protected $downloadedFilePath;
3028
protected $requirementsErrors = array();
@@ -84,7 +82,7 @@ protected function checkProjectName()
8482
if (is_dir($this->projectDir) && !$this->isEmptyDirectory($this->projectDir)) {
8583
throw new \RuntimeException(sprintf(
8684
"There is already a '%s' project in this directory (%s).\n".
87-
"Change your project name or create it in another directory.",
85+
'Change your project name or create it in another directory.',
8886
$this->projectName, $this->projectDir
8987
));
9088
}
@@ -155,7 +153,7 @@ protected function checkSymfonyVersionIsInstallable()
155153
"The selected version (%s) cannot be installed because it belongs\n".
156154
"to an unmaintained Symfony branch which is not compatible with this installer.\n".
157155
"To solve this issue install Symfony manually executing the following command:\n\n".
158-
"composer create-project symfony/framework-standard-edition %s %s",
156+
'composer create-project symfony/framework-standard-edition %s %s',
159157
$this->version, $this->projectDir, $this->version
160158
));
161159
}
@@ -166,7 +164,7 @@ protected function checkSymfonyVersionIsInstallable()
166164
"The selected version (%s) cannot be installed because this installer\n".
167165
"is compatible with Symfony 2.3 versions starting from 2.3.21.\n".
168166
"To solve this issue install Symfony manually executing the following command:\n\n".
169-
"composer create-project symfony/framework-standard-edition %s %s",
167+
'composer create-project symfony/framework-standard-edition %s %s',
170168
$this->version, $this->projectDir, $this->version
171169
));
172170
}
@@ -177,7 +175,7 @@ protected function checkSymfonyVersionIsInstallable()
177175
"The selected version (%s) cannot be installed because this installer\n".
178176
"is compatible with Symfony 2.5 versions starting from 2.5.6.\n".
179177
"To solve this issue install Symfony manually executing the following command:\n\n".
180-
"composer create-project symfony/framework-standard-edition %s %s",
178+
'composer create-project symfony/framework-standard-edition %s %s',
181179
$this->version, $this->projectDir, $this->version
182180
));
183181
}

0 commit comments

Comments
 (0)