[FrameworkBundle] Enable possibility to run PHP bultin server in production env #7507

Closed
wants to merge 2 commits into
from
Jump to file or symbol
Failed to load files and symbols.
+40 −3
Diff settings

Always

Just for now

@@ -4,6 +4,7 @@ CHANGELOG
2.3.0
-----
+ * added possibility to run PHP built-in server in production environment
* added possibility to load the serializer component in the service container
* added route debug information when using the `router:match` command
* added `TimedPhpEngine`
@@ -78,10 +78,16 @@ protected function configure()
*/
protected function execute(InputInterface $input, OutputInterface $output)
{
+ $env = $this->getContainer()->getParameter('kernel.environment');
+
+ if ('prod' === $env) {
+ $output->writeln('<error>Running PHP built-in server in production environment is NOT recommended!</error>');
+ }
+
$router = $input->getOption('router') ?: $this
->getContainer()
->get('kernel')
- ->locateResource('@FrameworkBundle/Resources/config/router.php')
+ ->locateResource(sprintf('@FrameworkBundle/Resources/config/router_%s.php', $env))

This comment has been minimized.

Show comment Hide comment
@fabpot

fabpot Apr 1, 2013

Member

Same as above, the whole method call should be on the same line.

@fabpot

fabpot Apr 1, 2013

Member

Same as above, the whole method call should be on the same line.

This comment has been minimized.

Show comment Hide comment
@merk

merk Apr 1, 2013

Contributor

Should there be error handling if someone tries to run this command in another environment and the router doesnt exist?

@merk

merk Apr 1, 2013

Contributor

Should there be error handling if someone tries to run this command in another environment and the router doesnt exist?

This comment has been minimized.

Show comment Hide comment
@canni

canni Apr 1, 2013

Contributor

Someone will see nice error about failed resource lock-up, not some "require" fatal :)

@canni

canni Apr 1, 2013

Contributor

Someone will see nice error about failed resource lock-up, not some "require" fatal :)

This comment has been minimized.

Show comment Hide comment
@stof

stof Apr 4, 2013

Member

Thus, you can probably create it in app/Resources/FrameworkBundle/config/router_my_env.php for other environments. So letting the resource locator handle missing files is easier.

@stof

stof Apr 4, 2013

Member

Thus, you can probably create it in app/Resources/FrameworkBundle/config/router_my_env.php for other environments. So letting the resource locator handle missing files is easier.

;
$output->writeln(sprintf("Server running on <info>%s</info>\n", $input->getArgument('address')));
@@ -21,10 +21,10 @@
* @author: Albert Jessurum <ajessu@gmail.com>
*/
-if (is_file($_SERVER['DOCUMENT_ROOT'] . DIRECTORY_SEPARATOR . $_SERVER['SCRIPT_NAME'])) {
+if (is_file($_SERVER['DOCUMENT_ROOT'].DIRECTORY_SEPARATOR.$_SERVER['SCRIPT_NAME'])) {
return false;
}
-$_SERVER['SCRIPT_FILENAME'] = $_SERVER['DOCUMENT_ROOT'] . DIRECTORY_SEPARATOR . 'app_dev.php';
+$_SERVER['SCRIPT_FILENAME'] = $_SERVER['DOCUMENT_ROOT'].DIRECTORY_SEPARATOR.'app_dev.php';
require 'app_dev.php';
@@ -0,0 +1,30 @@
+<?php
+
+/*
+ * This file is part of the Symfony package.
+ *
+ * (c) Fabien Potencier <fabien@symfony.com>
+ *
+ * For the full copyright and license information, please view the LICENSE
+ * file that was distributed with this source code.
+ */
+
+/*
+ * This file implements rewrite rules for PHP built-in web server.
+ *
+ * See: http://www.php.net/manual/en/features.commandline.webserver.php
+ *
+ * If you have custom directory layout, then you have to write your own router
+ * and pass it as a value to 'router' option of server:run command.
+ *
+ * @author: Michał Pipa <michal.pipa.xsolve@gmail.com>
+ * @author: Albert Jessurum <ajessu@gmail.com>
+ */
+
+if (is_file($_SERVER['DOCUMENT_ROOT'].DIRECTORY_SEPARATOR.$_SERVER['SCRIPT_NAME'])) {
+ return false;
+}
+
+$_SERVER['SCRIPT_FILENAME'] = $_SERVER['DOCUMENT_ROOT'].DIRECTORY_SEPARATOR.'app.php';
+
+require 'app.php';