Skip to content

Commit

Permalink
chore(deprecations): fix deprecations picking bin/console and public/…
Browse files Browse the repository at this point in the history
…index.php from SF 5.4 skeleton project (refs #39)
  • Loading branch information
mborne committed Nov 15, 2023
1 parent 38cb812 commit dace73c
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 79 deletions.
3 changes: 3 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
39 changes: 7 additions & 32 deletions bin/console
Original file line number Diff line number Diff line change
Expand Up @@ -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);
};
6 changes: 4 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -56,7 +57,8 @@
"sort-packages": false,
"secure-http": false,
"allow-plugins": {
"symfony/flex": true
"symfony/flex": true,
"symfony/runtime": true
}
},
"autoload": {
Expand Down
23 changes: 0 additions & 23 deletions config/bootstrap.php

This file was deleted.

26 changes: 4 additions & 22 deletions public/index.php
Original file line number Diff line number Diff line change
@@ -1,27 +1,9 @@
<?php

use App\Kernel;
use Symfony\Component\ErrorHandler\Debug;
use Symfony\Component\HttpFoundation\Request;

require dirname(__DIR__).'/config/bootstrap.php';
require_once dirname(__DIR__).'/vendor/autoload_runtime.php';

if ($_SERVER['APP_DEBUG']) {
umask(0000);

Debug::enable();
}

if ($trustedProxies = $_SERVER['TRUSTED_PROXIES'] ?? false) {
Request::setTrustedProxies(explode(',', $trustedProxies), Request::HEADER_X_FORWARDED_ALL ^ Request::HEADER_X_FORWARDED_HOST);
}

if ($trustedHosts = $_SERVER['TRUSTED_HOSTS'] ?? false) {
Request::setTrustedHosts([$trustedHosts]);
}

$kernel = new Kernel($_SERVER['APP_ENV'], (bool) $_SERVER['APP_DEBUG']);
$request = Request::createFromGlobals();
$response = $kernel->handle($request);
$response->send();
$kernel->terminate($request, $response);
return function (array $context) {
return new Kernel($context['APP_ENV'], (bool) $context['APP_DEBUG']);
};

0 comments on commit dace73c

Please sign in to comment.