diff --git a/forms.rst b/forms.rst index c5e41222104..b6c63773452 100644 --- a/forms.rst +++ b/forms.rst @@ -345,13 +345,13 @@ can set this option to generate forms compatible with the Bootstrap 4 CSS framew .. code-block:: php // config/packages/twig.php - $container->loadFromExtension('twig', [ - 'form_themes' => [ - 'bootstrap_4_layout.html.twig', - ], + use Symfony\Config\TwigConfig; + + return static function (TwigConfig $twig) { + $twig->formThemes(['bootstrap_4_layout.html.twig']); // ... - ]); + }; The :ref:`built-in Symfony form themes ` include Bootstrap 3 and 4 as well as Foundation 5 and 6. You can also @@ -627,11 +627,11 @@ these new messages set the ``legacy_error_messages`` option to ``false``: .. code-block:: php // config/packages/framework.php - $container->loadFromExtension('framework', [ - 'form' => [ - 'legacy_error_messages' => false, - ], - ]); + use Symfony\Config\FrameworkConfig; + + return static function (FrameworkConfig $framework) { + $framework->form()->legacyErrorMessages(false); + }; Other Common Form Features -------------------------- diff --git a/routing.rst b/routing.rst index 9aad1ac3c58..487d2ecc587 100644 --- a/routing.rst +++ b/routing.rst @@ -2508,12 +2508,11 @@ The solution is to configure the ``default_uri`` option to define the .. code-block:: php // config/packages/routing.php - $container->loadFromExtension('framework', [ - 'router' => [ - // ... - 'default_uri' => "https://example.org/my/path/", - ], - ]); + use Symfony\Config\FrameworkConfig; + + return static function (FrameworkConfig $framework) { + $framework->router()->defaultUri('https://example.org/my/path/'); + }; .. versionadded:: 5.1 diff --git a/serializer.rst b/serializer.rst index 980bf5708ab..8cae58c5838 100644 --- a/serializer.rst +++ b/serializer.rst @@ -259,12 +259,11 @@ value: .. code-block:: php // config/packages/framework.php - $container->loadFromExtension('framework', [ - // ... - 'serializer' => [ - 'name_converter' => 'serializer.name_converter.camel_case_to_snake_case', - ], - ]); + use Symfony\Config\FrameworkConfig; + + return static function (FrameworkConfig $framework) { + $framework->serializer()->nameConverter('serializer.name_converter.camel_case_to_snake_case'); + }; Going Further with the Serializer --------------------------------- diff --git a/session.rst b/session.rst index 5a3fb69c09b..8f3fba95b30 100644 --- a/session.rst +++ b/session.rst @@ -55,18 +55,20 @@ sessions, check their default configuration: .. code-block:: php // config/packages/framework.php - $container->loadFromExtension('framework', [ - 'session' => [ + use Symfony\Config\FrameworkConfig; + + return static function (FrameworkConfig $framework) { + $framework->session() // enables the support of sessions in the app - 'enabled' => true, + ->enabled(true) // ID of the service used for session storage // NULL means that Symfony uses PHP default session mechanism - 'handler_id' => null, + ->handlerId(null) // improves the security of the cookies used for sessions - 'cookie_secure' => 'auto', - 'cookie_samesite' => 'lax', - ], - ]); + ->cookieSecure('auto') + ->cookieSamesite('lax') + ; + }; Setting the ``handler_id`` config option to ``null`` means that Symfony will use the native PHP session mechanism. The session metadata files will be stored @@ -112,13 +114,15 @@ session metadata files: .. code-block:: php // config/packages/framework.php - $container->loadFromExtension('framework', [ - 'session' => [ + use Symfony\Config\FrameworkConfig; + + return static function (FrameworkConfig $framework) { + $framework->session() // ... - 'handler_id' => 'session.handler.native_file', - 'save_path' => '%kernel.project_dir%/var/sessions/%kernel.environment%', - ], - ]); + ->handlerId('session.handler.native_file') + ->savePath('%kernel.project_dir%/var/sessions/%kernel.environment%') + ; + }; Check out the Symfony config reference to learn more about the other available :ref:`Session configuration options `. You can also diff --git a/templates.rst b/templates.rst index 9f1f5233b34..af18a438484 100644 --- a/templates.rst +++ b/templates.rst @@ -824,10 +824,12 @@ template fragments. Configure that special URL in the ``fragments`` option: .. code-block:: php // config/packages/framework.php - $container->loadFromExtension('framework', [ + use Symfony\Config\FrameworkConfig; + + return static function (FrameworkConfig $framework) { // ... - 'fragments' => ['path' => '/_fragment'], - ]); + $framework->fragments()->path('/_fragment'); + }; .. caution:: @@ -1043,15 +1045,16 @@ the ``value`` is the Twig namespace, which is explained later: .. code-block:: php // config/packages/twig.php - $container->loadFromExtension('twig', [ + use Symfony\Config\TwigConfig; + + return static function (TwigConfig $twig) { // ... - 'paths' => [ - // directories are relative to the project root dir (but you - // can also use absolute directories) - 'email/default/templates' => null, - 'backend/templates' => null, - ], - ]); + + // directories are relative to the project root dir (but you + // can also use absolute directories) + $twig->path('email/default/templates', null); + $twig->path('backend/templates', null); + }; When rendering a template, Symfony looks for it first in the ``twig.paths`` directories that don't define a namespace and then falls back to the default @@ -1098,13 +1101,14 @@ configuration to define a namespace for each template directory: .. code-block:: php // config/packages/twig.php - $container->loadFromExtension('twig', [ + use Symfony\Config\TwigConfig; + + return static function (TwigConfig $twig) { // ... - 'paths' => [ - 'email/default/templates' => 'email', - 'backend/templates' => 'admin', - ], - ]); + + $twig->path('email/default/templates', 'email'); + $twig->path('backend/templates', 'admin'); + }; Now, if you render the ``layout.html.twig`` template, Symfony will render the ``templates/layout.html.twig`` file. Use the special syntax ``@`` + namespace to