Skip to content

Commit

Permalink
Let's use symfony/runtime
Browse files Browse the repository at this point in the history
  • Loading branch information
Ferror committed Oct 13, 2022
1 parent f235761 commit 22e1358
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 53 deletions.
35 changes: 6 additions & 29 deletions bin/console
Original file line number Diff line number Diff line change
Expand Up @@ -3,36 +3,13 @@

use App\Kernel;
use Symfony\Bundle\FrameworkBundle\Console\Application;
use Symfony\Component\Console\Input\ArgvInput;
use Symfony\Component\Debug\Debug;

set_time_limit(0);

require dirname(__DIR__).'/vendor/autoload.php';

if (!class_exists(Application::class)) {
throw new RuntimeException('You need to add "symfony/framework-bundle" as a Composer dependency.');
if (!is_file(dirname(__DIR__).'/vendor/autoload_runtime.php')) {
throw new LogicException('Symfony Runtime is missing. Try running "composer require symfony/runtime".');
}

$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();
}
}
require_once dirname(__DIR__).'/vendor/autoload_runtime.php';

$kernel = new Kernel($_SERVER['APP_ENV'], (bool) $_SERVER['APP_DEBUG']);
$application = new Application($kernel);
$application->run($input);
return function (array $context) {
return new Application(new Kernel($context['APP_ENV'], (bool) $context['APP_DEBUG']));
};
6 changes: 4 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,8 @@
"sylius/paypal-plugin": "^1.5.x-dev",
"sylius/sylius": "^1.12.x-dev",
"symfony/dotenv": "^5.4",
"symfony/flex": "^2.1"
"symfony/flex": "^2.1",
"symfony/runtime": "^5.4"
},
"require-dev": {
"behat/behat": "^3.7",
Expand Down Expand Up @@ -67,7 +68,8 @@
"symfony/flex": true,
"dealerdirect/phpcodesniffer-composer-installer": false,
"phpstan/extension-installer": false,
"symfony/thanks": false
"symfony/thanks": false,
"symfony/runtime": true
}
},
"extra": {
Expand Down
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'] ?? $_ENV['TRUSTED_PROXIES'] ?? false) {
Request::setTrustedProxies(explode(',', $trustedProxies), Request::HEADER_X_FORWARDED_ALL ^ Request::HEADER_X_FORWARDED_HOST);
}

if ($trustedHosts = $_SERVER['TRUSTED_HOSTS'] ?? $_ENV['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 22e1358

Please sign in to comment.