From dace73c9c1bf5f951c0d1ccb3a2d12973d0016be Mon Sep 17 00:00:00 2001 From: MBorne Date: Wed, 15 Nov 2023 11:38:53 +0100 Subject: [PATCH] chore(deprecations): fix deprecations picking bin/console and public/index.php from SF 5.4 skeleton project (refs #39) --- Makefile | 3 +++ bin/console | 39 +++++++-------------------------------- composer.json | 6 ++++-- config/bootstrap.php | 23 ----------------------- public/index.php | 26 ++++---------------------- 5 files changed, 18 insertions(+), 79 deletions(-) delete mode 100755 config/bootstrap.php diff --git a/Makefile b/Makefile index efb9f2d..10fc511 100755 --- a/Makefile +++ b/Makefile @@ -2,7 +2,10 @@ PHP_CS_RULES=@Symfony PHP_MD_RULES=./phpmd.xml test: vendor bin/validator-cli.jar + # see SYMFONY_DEPRECATIONS_HELPER in phpunit.xml.dist + rm -rf var/log/test.deprecations.log APP_ENV=test XDEBUG_MODE=coverage vendor/bin/phpunit + bin/validator-cli.jar: bash download-validator.sh diff --git a/bin/console b/bin/console index 5de0e1c..c933dc5 100755 --- a/bin/console +++ b/bin/console @@ -3,40 +3,15 @@ use App\Kernel; use Symfony\Bundle\FrameworkBundle\Console\Application; -use Symfony\Component\Console\Input\ArgvInput; -use Symfony\Component\ErrorHandler\Debug; -if (!in_array(PHP_SAPI, ['cli', 'phpdbg', 'embed'], true)) { - echo 'Warning: The console should be invoked via the CLI version of PHP, not the '.PHP_SAPI.' SAPI'.PHP_EOL; +if (!is_file(dirname(__DIR__).'/vendor/autoload_runtime.php')) { + throw new LogicException('Symfony Runtime is missing. Try running "composer require symfony/runtime".'); } -set_time_limit(0); +require_once dirname(__DIR__).'/vendor/autoload_runtime.php'; -require dirname(__DIR__).'/vendor/autoload.php'; +return function (array $context) { + $kernel = new Kernel($context['APP_ENV'], (bool) $context['APP_DEBUG']); -if (!class_exists(Application::class)) { - throw new LogicException('You need to add "symfony/framework-bundle" as a Composer dependency.'); -} - -$input = new ArgvInput(); -if (null !== $env = $input->getParameterOption(['--env', '-e'], null, true)) { - putenv('APP_ENV='.$_SERVER['APP_ENV'] = $_ENV['APP_ENV'] = $env); -} - -if ($input->hasParameterOption('--no-debug', true)) { - putenv('APP_DEBUG='.$_SERVER['APP_DEBUG'] = $_ENV['APP_DEBUG'] = '0'); -} - -require dirname(__DIR__).'/config/bootstrap.php'; - -if ($_SERVER['APP_DEBUG']) { - umask(0000); - - if (class_exists(Debug::class)) { - Debug::enable(); - } -} - -$kernel = new Kernel($_SERVER['APP_ENV'], (bool) $_SERVER['APP_DEBUG']); -$application = new Application($kernel); -$application->run($input); + return new Application($kernel); +}; diff --git a/composer.json b/composer.json index 1c25d94..a089b9a 100755 --- a/composer.json +++ b/composer.json @@ -30,7 +30,8 @@ "symfony/twig-bundle": "5.4.*", "symfony/validator": "5.4.*", "symfony/yaml": "5.4.*", - "symfony/mime": "5.4.*" + "symfony/mime": "5.4.*", + "symfony/runtime": "5.4.*" }, "require-dev": { "doctrine/doctrine-fixtures-bundle": "^3.4", @@ -56,7 +57,8 @@ "sort-packages": false, "secure-http": false, "allow-plugins": { - "symfony/flex": true + "symfony/flex": true, + "symfony/runtime": true } }, "autoload": { diff --git a/config/bootstrap.php b/config/bootstrap.php deleted file mode 100755 index 55560fb..0000000 --- a/config/bootstrap.php +++ /dev/null @@ -1,23 +0,0 @@ -=1.2) -if (is_array($env = @include dirname(__DIR__).'/.env.local.php') && (!isset($env['APP_ENV']) || ($_SERVER['APP_ENV'] ?? $_ENV['APP_ENV'] ?? $env['APP_ENV']) === $env['APP_ENV'])) { - (new Dotenv(false))->populate($env); -} else { - // load all the .env files - (new Dotenv(false))->loadEnv(dirname(__DIR__).'/.env'); -} - -$_SERVER += $_ENV; -$_SERVER['APP_ENV'] = $_ENV['APP_ENV'] = ($_SERVER['APP_ENV'] ?? $_ENV['APP_ENV'] ?? null) ?: 'dev'; -$_SERVER['APP_DEBUG'] = $_SERVER['APP_DEBUG'] ?? $_ENV['APP_DEBUG'] ?? 'prod' !== $_SERVER['APP_ENV']; -$_SERVER['APP_DEBUG'] = $_ENV['APP_DEBUG'] = (int) $_SERVER['APP_DEBUG'] || filter_var($_SERVER['APP_DEBUG'], FILTER_VALIDATE_BOOLEAN) ? '1' : '0'; diff --git a/public/index.php b/public/index.php index 0e30370..9982c21 100755 --- a/public/index.php +++ b/public/index.php @@ -1,27 +1,9 @@ handle($request); -$response->send(); -$kernel->terminate($request, $response); +return function (array $context) { + return new Kernel($context['APP_ENV'], (bool) $context['APP_DEBUG']); +};