From a56b781e909a2cf2cc5adc90a8bbcc991c4f3f5a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dariusz=20G=C3=B3recki?= Date: Thu, 28 Mar 2013 11:40:30 +0000 Subject: [PATCH 1/2] [FrameworkBundle] Enable possibility to run PHP bultin server in production env --- .../Command/ServerRunCommand.php | 13 +++++++- .../config/{router.php => router_dev.php} | 0 .../Resources/config/router_prod.php | 30 +++++++++++++++++++ 3 files changed, 42 insertions(+), 1 deletion(-) rename src/Symfony/Bundle/FrameworkBundle/Resources/config/{router.php => router_dev.php} (100%) create mode 100644 src/Symfony/Bundle/FrameworkBundle/Resources/config/router_prod.php diff --git a/src/Symfony/Bundle/FrameworkBundle/Command/ServerRunCommand.php b/src/Symfony/Bundle/FrameworkBundle/Command/ServerRunCommand.php index f62a15de28665..064ee18079b4b 100644 --- a/src/Symfony/Bundle/FrameworkBundle/Command/ServerRunCommand.php +++ b/src/Symfony/Bundle/FrameworkBundle/Command/ServerRunCommand.php @@ -78,10 +78,21 @@ protected function configure() */ protected function execute(InputInterface $input, OutputInterface $output) { + $env = $this->getContainer()->getParameter('kernel.environment'); + + if ('prod' === $env) { + $output->writeln( + 'Running PHP built-in server in production environment is NOT secure!' + ); + } + $router = $input->getOption('router') ?: $this ->getContainer() ->get('kernel') - ->locateResource('@FrameworkBundle/Resources/config/router.php') + ->locateResource(sprintf( + '@FrameworkBundle/Resources/config/router_%s.php', + $env + )) ; $output->writeln(sprintf("Server running on %s\n", $input->getArgument('address'))); diff --git a/src/Symfony/Bundle/FrameworkBundle/Resources/config/router.php b/src/Symfony/Bundle/FrameworkBundle/Resources/config/router_dev.php similarity index 100% rename from src/Symfony/Bundle/FrameworkBundle/Resources/config/router.php rename to src/Symfony/Bundle/FrameworkBundle/Resources/config/router_dev.php diff --git a/src/Symfony/Bundle/FrameworkBundle/Resources/config/router_prod.php b/src/Symfony/Bundle/FrameworkBundle/Resources/config/router_prod.php new file mode 100644 index 0000000000000..5be1617ecb845 --- /dev/null +++ b/src/Symfony/Bundle/FrameworkBundle/Resources/config/router_prod.php @@ -0,0 +1,30 @@ + + * + * 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 + * @author: Albert Jessurum + */ + +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'; From b065f3894e0f2881746bc73631e0a0397198c35c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dariusz=20G=C3=B3recki?= Date: Mon, 1 Apr 2013 12:36:39 +0100 Subject: [PATCH 2/2] Fix CS --- src/Symfony/Bundle/FrameworkBundle/CHANGELOG.md | 1 + .../Bundle/FrameworkBundle/Command/ServerRunCommand.php | 9 ++------- .../FrameworkBundle/Resources/config/router_dev.php | 4 ++-- .../FrameworkBundle/Resources/config/router_prod.php | 4 ++-- 4 files changed, 7 insertions(+), 11 deletions(-) diff --git a/src/Symfony/Bundle/FrameworkBundle/CHANGELOG.md b/src/Symfony/Bundle/FrameworkBundle/CHANGELOG.md index 00d900d1c80cd..b24e4ba04ae23 100644 --- a/src/Symfony/Bundle/FrameworkBundle/CHANGELOG.md +++ b/src/Symfony/Bundle/FrameworkBundle/CHANGELOG.md @@ -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` diff --git a/src/Symfony/Bundle/FrameworkBundle/Command/ServerRunCommand.php b/src/Symfony/Bundle/FrameworkBundle/Command/ServerRunCommand.php index 064ee18079b4b..09ca54556bbb5 100644 --- a/src/Symfony/Bundle/FrameworkBundle/Command/ServerRunCommand.php +++ b/src/Symfony/Bundle/FrameworkBundle/Command/ServerRunCommand.php @@ -81,18 +81,13 @@ protected function execute(InputInterface $input, OutputInterface $output) $env = $this->getContainer()->getParameter('kernel.environment'); if ('prod' === $env) { - $output->writeln( - 'Running PHP built-in server in production environment is NOT secure!' - ); + $output->writeln('Running PHP built-in server in production environment is NOT recommended!'); } $router = $input->getOption('router') ?: $this ->getContainer() ->get('kernel') - ->locateResource(sprintf( - '@FrameworkBundle/Resources/config/router_%s.php', - $env - )) + ->locateResource(sprintf('@FrameworkBundle/Resources/config/router_%s.php', $env)) ; $output->writeln(sprintf("Server running on %s\n", $input->getArgument('address'))); diff --git a/src/Symfony/Bundle/FrameworkBundle/Resources/config/router_dev.php b/src/Symfony/Bundle/FrameworkBundle/Resources/config/router_dev.php index e55c81c844280..64c90b4bd20c4 100644 --- a/src/Symfony/Bundle/FrameworkBundle/Resources/config/router_dev.php +++ b/src/Symfony/Bundle/FrameworkBundle/Resources/config/router_dev.php @@ -21,10 +21,10 @@ * @author: Albert Jessurum */ -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'; diff --git a/src/Symfony/Bundle/FrameworkBundle/Resources/config/router_prod.php b/src/Symfony/Bundle/FrameworkBundle/Resources/config/router_prod.php index 5be1617ecb845..4278b4bba15be 100644 --- a/src/Symfony/Bundle/FrameworkBundle/Resources/config/router_prod.php +++ b/src/Symfony/Bundle/FrameworkBundle/Resources/config/router_prod.php @@ -21,10 +21,10 @@ * @author: Albert Jessurum */ -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.php'; +$_SERVER['SCRIPT_FILENAME'] = $_SERVER['DOCUMENT_ROOT'].DIRECTORY_SEPARATOR.'app.php'; require 'app.php'; pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy