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

Skip to content

Commit 17e065f

Browse files
committed
merged branch canni/prod_server (PR #7507)
This PR was squashed before being merged into the master branch (closes #7507). Discussion ---------- [FrameworkBundle] Enable possibility to run PHP bultin server in production env See the referenced ticket for discussion; | Q | A | ------------- | --- | Bug fix? | no | New feature? | yes | BC breaks? | no | Deprecations? | no | Tests pass? | yes | Fixed tickets | #7430 | License | MIT Commits ------- 12fce13 [FrameworkBundle] Enable possibility to run PHP bultin server in production env
2 parents d9d9635 + 12fce13 commit 17e065f

File tree

4 files changed

+38
-1
lines changed

4 files changed

+38
-1
lines changed

src/Symfony/Bundle/FrameworkBundle/CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ CHANGELOG
44
2.3.0
55
-----
66

7+
* added possibility to run PHP built-in server in production environment
78
* added possibility to load the serializer component in the service container
89
* added route debug information when using the `router:match` command
910
* added `TimedPhpEngine`

src/Symfony/Bundle/FrameworkBundle/Command/ServerRunCommand.php

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,10 +78,16 @@ protected function configure()
7878
*/
7979
protected function execute(InputInterface $input, OutputInterface $output)
8080
{
81+
$env = $this->getContainer()->getParameter('kernel.environment');
82+
83+
if ('prod' === $env) {
84+
$output->writeln('<error>Running PHP built-in server in production environment is NOT recommended!</error>');
85+
}
86+
8187
$router = $input->getOption('router') ?: $this
8288
->getContainer()
8389
->get('kernel')
84-
->locateResource('@FrameworkBundle/Resources/config/router.php')
90+
->locateResource(sprintf('@FrameworkBundle/Resources/config/router_%s.php', $env))
8591
;
8692

8793
$output->writeln(sprintf("Server running on <info>%s</info>\n", $input->getArgument('address')));
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
<?php
2+
3+
/*
4+
* This file is part of the Symfony package.
5+
*
6+
* (c) Fabien Potencier <[email protected]>
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+
/*
13+
* This file implements rewrite rules for PHP built-in web server.
14+
*
15+
* See: http://www.php.net/manual/en/features.commandline.webserver.php
16+
*
17+
* If you have custom directory layout, then you have to write your own router
18+
* and pass it as a value to 'router' option of server:run command.
19+
*
20+
* @author: Michał Pipa <[email protected]>
21+
* @author: Albert Jessurum <[email protected]>
22+
*/
23+
24+
if (is_file($_SERVER['DOCUMENT_ROOT'].DIRECTORY_SEPARATOR.$_SERVER['SCRIPT_NAME'])) {
25+
return false;
26+
}
27+
28+
$_SERVER['SCRIPT_FILENAME'] = $_SERVER['DOCUMENT_ROOT'].DIRECTORY_SEPARATOR.'app.php';
29+
30+
require 'app.php';

0 commit comments

Comments
 (0)