Skip to content

Commit

Permalink
feature #843 Let's use symfony/runtime (Ferror)
Browse files Browse the repository at this point in the history
This PR was merged into the 1.12 branch.

Discussion
----------

I would like to propose using symfony/runtime component that has multiple advantages.

1. Simplifies the console and index entry points
2. Enables the ability to use other runtimes... Like Swoole, Roadrunner etc. https://github.com/php-runtime

https://symfony.com/blog/new-in-symfony-5-3-runtime-component

Commits
-------

2b99bdb Let\'s use symfony/runtime
  • Loading branch information
lchrusciel authored Nov 1, 2022
2 parents 6b56443 + 2b99bdb commit 20454ea
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 52 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']));
};
4 changes: 3 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
"sylius/paypal-plugin": "^1.5.x-dev",
"sylius/sylius": "^1.12.x-dev",
"symfony/dotenv": "^5.4 || ^6.0",
"symfony/runtime": "^5.4 || ^6.0",
"symfony/flex": "^2.1"
},
"require-dev": {
Expand Down Expand Up @@ -68,7 +69,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 20454ea

Please sign in to comment.