Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
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
-------

34c8566 [WebServerBundle] allowed public/ root directory to be auto-discovered along side web/
bc6b57c [WebServerBundle] remove duplicate code
  • Loading branch information
fabpot committed Jul 17, 2017
2 parents 0d72e82 + 34c8566 commit c75d0c5
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 14 deletions.
12 changes: 6 additions & 6 deletions src/Symfony/Bundle/WebServerBundle/Command/ServerRunCommand.php
Expand Up @@ -88,6 +88,12 @@ protected function execute(InputInterface $input, OutputInterface $output)
{
$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.');
Expand All @@ -97,12 +103,6 @@ protected function execute(InputInterface $input, OutputInterface $output)
$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.');
Expand Down
Expand Up @@ -100,6 +100,12 @@ protected function execute(InputInterface $input, OutputInterface $output)
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.');
Expand All @@ -109,12 +115,6 @@ protected function execute(InputInterface $input, OutputInterface $output)
$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.');
Expand Down
Expand Up @@ -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>
Expand Down

0 comments on commit c75d0c5

Please sign in to comment.