New in Symfony 5.3: Runtime Component

Contributed by Nicolas Grekas in #38465 and #40513.

Symfony 5.3 was released on May 31, 2021. Although we’ve published many articles about new Symfony 5.3 features, there are some interesting new features that we haven’t discussed yet. The first one is the new Runtime Component. The purpose of the Runtime component is to abstract most of the application bootstrapping logic into so-called runtimes, allowing you to write generic front-controllers. This will make Symfony applications easier to maintain, because the front-controller code can be moved to a Symfony Flex recipe managed automatically by Symfony. In addition, this component decouples the bootstrapping from any global state to make sure the application can run with runtimes like PHP-FPM, ReactPHP, Swoole, etc. without any changes. If you open your public/index.php file, you’ll see some code like this: 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22// public/index.php <?php

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

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

(new Dotenv())->bootEnv(dirname(DIR).'/.env');

if ($_SERVER['APP_DEBUG']) { umask(0000); Debug::enable(); }

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

In addition to some autoloading and configuration, this file contains the code needed to process the well-known Symfony Request-Response flow. In a new Symfony 5.3 application, the same front-controller uses Symfony Runtime and its code looks as follows: 1 2 3 4 5 6 7 8 9 10// public/index.php <?php

use App\Kernel;

require_once dirname(DIR).'/vendor/autoload_runtime.php';

return function (array $context) { return new Kernel($context['APP_ENV'], (bool) $context['APP_DEBUG']); };

Why is the new front-controller code so concise? Where is the request turned into a response? What’s this autoload_runtime.php file? Read the new Runtime component docs to learn about all this and more. You will also learn how to tweak this runtime and how to create your own runtimes. If you are upgrading an existing application to Symfony 5.3, you can start using this new component as follows:

Install the component by running composer require symfony/runtime Update your front controller using the public/index.php code found in Symfony’s FrameworkBundle recipe Update your console script using the bin/console code found in Symfony’s Console recipe

If you want to learn more about this component, join the SymfonyWorld Online 2021 Summer Edition conference (June 17-18, 2021), where Tobias Nyholm will deliver a talk titled “Runtime component: The game changer”.

                Sponsor the Symfony project.

http://feedproxy.google.com/~r/symfony/blog/~3/rAuSFR_e6s4/new-in-symfony-5-3-runtime-component

Utworzony 4y | 2 cze 2021, 08:20:05


Zaloguj się, aby dodać komentarz

Inne posty w tej grupie

New in Symfony 7.3: DX Improvements (part 2)

This is the second part of the blog post showcasing the main DX (developer experience) features introduced in Symfony 7.3. Read the first part of this blog post.

Verify URI Signatures… https://symfon

29 maj 2025, 09:10:19 | Symfony
Symfony 6.4.22 released

Symfony 6.4.22 has just been released. Read the Symfony upgrade guide to learn more about upgrading Symfony and use the SymfonyInsight upgrade reports to detect the code you will need to change in you

29 maj 2025, 09:10:19 | Symfony
Symfony 7.2.7 released

Symfony 7.2.7 has just been released. Read the Symfony upgrade guide to learn more about upgrading Symfony and use the SymfonyInsight upgrade reports to detect the code you will need to change in your

29 maj 2025, 09:10:18 | Symfony
Symfony 7.3.0 released

Symfony 7.3.0 has just been released. Check the New in Symfony 7.3 posts on this blog to learn about the main features of this new stable release; or check the first beta release announcement to get t

29 maj 2025, 09:10:17 | Symfony
Symfony 7.3 curated new features

Symfony 7.3.0 has been released. As for any other Symfony release, our backward compatibility promise applies and this means that you should be able to upgrade easily to 7.3 without changing anything

29 maj 2025, 09:10:16 | Symfony
New in Symfony 7.3: DX Improvements (part 1)

Symfony 7.3 includes many small improvements aimed at making developers' lives easier and more productive. This blog post highlights some of the most useful DX (Developer Experience) features added in

28 maj 2025, 09:50:15 | Symfony
New in Symfony 7.3: Validator Improvements

Symfony 7.3 introduces several enhancements to the Validator component, focusing on developer experience, better configurability, and more expressive constraint definitions.

Allow to Disable Translat

27 maj 2025, 08:30:20 | Symfony