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

Commit 30b941f

Browse files
committed
feature #118 Added a new "symfony demo" command (javiereguiluz)
This PR was squashed before being merged into the 1.0-dev branch (closes #118). Discussion ---------- Added a new "symfony demo" command This is a WIP and early release of the new `symfony demo` command. The general idea around this command is the following: * Soon the `AcmeDemoBundle` will be gone forever. * The Symfony Standard Edition (and therefore, the `symfony new` command) will always give you a clean and empty Symfony application. * We'll publish a complete Symfony demo application that combines what we did for the Best Practices book (and which wasn't released) and the current AcmeDemoBundle. This will be a real application using `AppBundle` and all the best practices. No more Acme or Demo. * If you are new to Symfony and want to test it ... install the Symfony Installer in 1 minute and execute the `symfony demo` command. In 10 seconds you'll have a full-featured Symfony application ready to test. And here are some comments regarding this command: * For now it doesn't download anything because the `Symfony_Demo` package doesn't exist yet. * This command **must** be as simple as possible (remember that it will be used by newcomers that just want to test-drive Symfony quickly and easily). That's why we don't allow to select the Symfony version (it will always be the most recent one). And we also don't allow to select the directory where the demo project is installed (it will be installed in `getcwd().'symfony_demo/'`) And here it is the `demo` command in action: ![symfony_demo_command](https://cloud.githubusercontent.com/assets/73419/6738237/089d80d6-ce71-11e4-9723-efb9592f5bec.png) Commits ------- f940df3 Added a new "symfony demo" command
2 parents 8ec265d + f940df3 commit 30b941f

File tree

5 files changed

+506
-333
lines changed

5 files changed

+506
-333
lines changed

src/Symfony/Installer/AboutCommand.php

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -54,21 +54,22 @@ protected function execute(InputInterface $input, OutputInterface $output)
5454
5555
<comment>%s new blog</comment>
5656
57-
To create a new project called <info>blog</info> in the current directory using
58-
the <info>long term support version</info> of Symfony, execute the following command:
57+
Create a project based on the <info>Symfony Long Term Support version</info> (LTS):
5958
6059
<comment>%3\$s new blog lts</comment>
6160
62-
To base your project on a <info>specific Symfony branch</info>, append the branch
63-
number at the end of the command:
61+
Create a project based on a <info>specific Symfony branch</info>:
6462
6563
<comment>%3\$s new blog 2.3</comment>
6664
67-
To base your project on a <info>specific Symfony version</info>, append the version
68-
number at the end of the command:
65+
Create a project based on a <info>specific Symfony version</info>:
6966
7067
<comment>%3\$s new blog 2.5.6</comment>
7168
69+
Create a <info>Symfony demo application</info> to learn how it works:
70+
71+
<comment>%3\$s demo</comment>
72+
7273
COMMAND_HELP;
7374

7475
// show the self-update information only when using the PHAR file

src/Symfony/Installer/DemoCommand.php

Lines changed: 131 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,131 @@
1+
<?php
2+
3+
/*
4+
* This file is part of the Symfony Installer package.
5+
*
6+
* (c) Fabien Potencier <fabien@symfony.com>
7+
*
8+
* For the full copyright and license information, please view the LICENSE
9+
* file that was distributed with this source code.
10+
*/
11+
12+
namespace Symfony\Installer;
13+
14+
use Symfony\Component\Console\Input\InputInterface;
15+
use Symfony\Component\Console\Output\OutputInterface;
16+
use Symfony\Component\Filesystem\Filesystem;
17+
18+
/**
19+
* This command creates a full-featured Symfony demo application.
20+
*
21+
* @author Javier Eguiluz <javier.eguiluz@gmail.com>
22+
*/
23+
class DemoCommand extends DownloadCommand
24+
{
25+
/** @var Filesystem */
26+
protected $fs;
27+
protected $projectName;
28+
protected $projectDir;
29+
protected $remoteFileUrl;
30+
protected $downloadedFilePath;
31+
protected $requirementsErrors = array();
32+
/** @var OutputInterface */
33+
protected $output;
34+
35+
protected function configure()
36+
{
37+
$this
38+
->setName('demo')
39+
->setDescription('Creates a demo Symfony project.')
40+
;
41+
}
42+
43+
protected function initialize(InputInterface $input, OutputInterface $output)
44+
{
45+
$this->remoteFileUrl = 'http://symfony.com/download?v=Symfony_Demo';
46+
$this->output = $output;
47+
$this->fs = new Filesystem();
48+
$this->projectDir = getcwd();
49+
50+
$i = 1;
51+
$projectName = 'symfony_demo';
52+
while (file_exists($this->projectDir.DIRECTORY_SEPARATOR.$projectName)) {
53+
$projectName = 'symfony_demo_'.(++$i);
54+
}
55+
56+
$this->projectName = $projectName;
57+
$this->projectDir = $this->projectDir.DIRECTORY_SEPARATOR.$projectName;
58+
}
59+
60+
protected function execute(InputInterface $input, OutputInterface $output)
61+
{
62+
try {
63+
$this
64+
->download()
65+
->extract()
66+
->cleanUp()
67+
->createGitIgnore()
68+
->checkSymfonyRequirements()
69+
->displayInstallationResult()
70+
;
71+
} catch (\Exception $e) {
72+
$this->cleanUp();
73+
throw $e;
74+
}
75+
}
76+
77+
/**
78+
* Removes all the temporary files and directories created to
79+
* download the demo application.
80+
*
81+
* @return NewCommand
82+
*/
83+
private function cleanUp()
84+
{
85+
$this->fs->remove(dirname($this->downloadedFilePath));
86+
87+
return $this;
88+
}
89+
90+
/**
91+
* It displays the message with the result of installing the Symfony Demo
92+
* application and provides some pointers to the user.
93+
*
94+
* @return DemoCommand
95+
*/
96+
private function displayInstallationResult()
97+
{
98+
if (empty($this->requirementsErrors)) {
99+
$this->output->writeln(sprintf(
100+
" <info>%s</info> Symfony Demo Application was <info>successfully installed</info>. Now you can:\n",
101+
defined('PHP_WINDOWS_VERSION_BUILD') ? 'OK' : ''
102+
));
103+
} else {
104+
$this->output->writeln(sprintf(
105+
" <comment>%s</comment> Symfony Demo Application was <info>successfully installed</info> but your system doesn't meet the\n".
106+
" technical requirements to run Symfony applications! Fix the following issues before executing it:\n",
107+
defined('PHP_WINDOWS_VERSION_BUILD') ? 'FAILED' : ''
108+
));
109+
110+
foreach ($this->requirementsErrors as $helpText) {
111+
$this->output->writeln(' * '.$helpText);
112+
}
113+
114+
$this->output->writeln(sprintf(
115+
" After fixing these issues, re-check Symfony requirements executing this command:\n\n".
116+
" <comment>php %s/app/check.php</comment>\n\n".
117+
" Then, you can:\n",
118+
$this->projectName
119+
));
120+
}
121+
122+
$this->output->writeln(sprintf(
123+
" 1. Change your current directory to <comment>%s</comment>\n\n".
124+
" 2. Execute the <comment>php app/console server:run</comment> command to run the demo application.\n\n".
125+
" 3. Browse to the <comment>http://localhost:8000</comment> URL to see the demo application in action.\n\n",
126+
$this->projectDir
127+
));
128+
129+
return $this;
130+
}
131+
}

0 commit comments

Comments
 (0)