bug #23535 Make server:* commands work out of the box with the public/ root dir (fabpot)

This PR was squashed before being merged into the 3.3 branch (closes #23535).

Discussion
----------

Make server:* commands work out of the box with the public/ root dir

| Q             | A
| ------------- | ---
| Branch?       | 3.3
| Bug fix?      | yes
| New feature?  | no
| BC breaks?    | no
| Deprecations? | no
| Tests pass?   | yes
| Fixed tickets | n/a
| License       | MIT
| Doc PR        | n/a

The first commit removes code that is not needed as the WebserverConfig class already throws the exact same error and the display is exactly the same in that case.

The second commit adds support for `public/` along side `web/`.

Commits
-------

34c8566be1 [WebServerBundle] allowed public/ root directory to be auto-discovered along side web/
bc6b57c208 [WebServerBundle] remove duplicate code
This commit is contained in:
Fabien Potencier 2017-07-17 12:18:22 +02:00
commit c75d0c56ab
3 changed files with 14 additions and 14 deletions

View File

@ -88,6 +88,12 @@ EOF
{
$io = new SymfonyStyle($input, $output instanceof ConsoleOutputInterface ? $output->getErrorOutput() : $output);
// deprecated, logic to be removed in 4.0
// this allows the commands to work out of the box with web/ and public/
if ($this->documentRoot && !is_dir($this->documentRoot) && is_dir(dirname($this->documentRoot).'/web')) {
$this->documentRoot = dirname($this->documentRoot).'/web';
}
if (null === $documentRoot = $input->getOption('docroot')) {
if (!$this->documentRoot) {
$io->error('The document root directory must be either passed as first argument of the constructor or through the "--docroot" input option.');
@ -97,12 +103,6 @@ EOF
$documentRoot = $this->documentRoot;
}
if (!is_dir($documentRoot)) {
$io->error(sprintf('The document root directory "%s" does not exist.', $documentRoot));
return 1;
}
if (!$env = $this->environment) {
if ($input->hasOption('env') && !$env = $input->getOption('env')) {
$io->error('The environment must be either passed as second argument of the constructor or through the "--env" input option.');

View File

@ -100,6 +100,12 @@ EOF
return 1;
}
// deprecated, logic to be removed in 4.0
// this allows the commands to work out of the box with web/ and public/
if ($this->documentRoot && !is_dir($this->documentRoot) && is_dir(dirname($this->documentRoot).'/web')) {
$this->documentRoot = dirname($this->documentRoot).'/web';
}
if (null === $documentRoot = $input->getOption('docroot')) {
if (!$this->documentRoot) {
$io->error('The document root directory must be either passed as first argument of the constructor or through the "docroot" input option.');
@ -109,12 +115,6 @@ EOF
$documentRoot = $this->documentRoot;
}
if (!is_dir($documentRoot)) {
$io->error(sprintf('The document root directory "%s" does not exist.', $documentRoot));
return 1;
}
if (!$env = $this->environment) {
if ($input->hasOption('env') && !$env = $input->getOption('env')) {
$io->error('The environment must be either passed as second argument of the constructor or through the "--env" input option.');

View File

@ -8,13 +8,13 @@
<defaults public="false" />
<service id="web_server.command.server_run" class="Symfony\Bundle\WebServerBundle\Command\ServerRunCommand">
<argument>%kernel.project_dir%/web</argument>
<argument>%kernel.project_dir%/public</argument>
<argument>%kernel.environment%</argument>
<tag name="console.command" />
</service>
<service id="web_server.command.server_start" class="Symfony\Bundle\WebServerBundle\Command\ServerStartCommand">
<argument>%kernel.project_dir%/web</argument>
<argument>%kernel.project_dir%/public</argument>
<argument>%kernel.environment%</argument>
<tag name="console.command" />
</service>