Skip to content

Commit 9196b61

Browse files
committed
Start using ConfigBuilder
1 parent 982a9b7 commit 9196b61

File tree

5 files changed

+59
-53
lines changed

5 files changed

+59
-53
lines changed

forms.rst

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -345,13 +345,13 @@ can set this option to generate forms compatible with the Bootstrap 4 CSS framew
345345
.. code-block:: php
346346
347347
// config/packages/twig.php
348-
$container->loadFromExtension('twig', [
349-
'form_themes' => [
350-
'bootstrap_4_layout.html.twig',
351-
],
348+
use Symfony\Config\TwigConfig;
349+
350+
return static function (TwigConfig $twig) {
351+
$twig->formTheme(['bootstrap_4_layout.html.twig']);
352352
353353
// ...
354-
]);
354+
};
355355
356356
The :ref:`built-in Symfony form themes <symfony-builtin-forms>` include
357357
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``:
627627
.. code-block:: php
628628
629629
// config/packages/framework.php
630-
$container->loadFromExtension('framework', [
631-
'form' => [
632-
'legacy_error_messages' => false,
633-
],
634-
]);
630+
use Symfony\Config\FrameworkConfig;
631+
632+
return static function (FrameworkConfig $framework) {
633+
$framework->form()->legacyErrorMessages(false);
634+
};
635635
636636
Other Common Form Features
637637
--------------------------

routing.rst

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2508,12 +2508,11 @@ The solution is to configure the ``default_uri`` option to define the
25082508
.. code-block:: php
25092509
25102510
// config/packages/routing.php
2511-
$container->loadFromExtension('framework', [
2512-
'router' => [
2513-
// ...
2514-
'default_uri' => "https://example.org/my/path/",
2515-
],
2516-
]);
2511+
use Symfony\Config\FrameworkConfig;
2512+
2513+
return static function (FrameworkConfig $framework) {
2514+
$framework->router()->defaultUri('https://example.org/my/path/');
2515+
};
25172516
25182517
.. versionadded:: 5.1
25192518

serializer.rst

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -259,12 +259,11 @@ value:
259259
.. code-block:: php
260260
261261
// config/packages/framework.php
262-
$container->loadFromExtension('framework', [
263-
// ...
264-
'serializer' => [
265-
'name_converter' => 'serializer.name_converter.camel_case_to_snake_case',
266-
],
267-
]);
262+
use Symfony\Config\FrameworkConfig;
263+
264+
return static function (FrameworkConfig $framework) {
265+
$framework->serializer()->nameConverter('serializer.name_converter.camel_case_to_snake_case');
266+
};
268267
269268
Going Further with the Serializer
270269
---------------------------------

session.rst

Lines changed: 18 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -55,18 +55,20 @@ sessions, check their default configuration:
5555
.. code-block:: php
5656
5757
// config/packages/framework.php
58-
$container->loadFromExtension('framework', [
59-
'session' => [
58+
use Symfony\Config\FrameworkConfig;
59+
60+
return static function (FrameworkConfig $framework) {
61+
$framework->session()
6062
// enables the support of sessions in the app
61-
'enabled' => true,
63+
->enabled(true)
6264
// ID of the service used for session storage
6365
// NULL means that Symfony uses PHP default session mechanism
64-
'handler_id' => null,
66+
->handlerId(null)
6567
// improves the security of the cookies used for sessions
66-
'cookie_secure' => 'auto',
67-
'cookie_samesite' => 'lax',
68-
],
69-
]);
68+
->cookieSecure('auto')
69+
->cookieSamesite('lax')
70+
;
71+
};
7072
7173
Setting the ``handler_id`` config option to ``null`` means that Symfony will
7274
use the native PHP session mechanism. The session metadata files will be stored
@@ -112,13 +114,15 @@ session metadata files:
112114
.. code-block:: php
113115
114116
// config/packages/framework.php
115-
$container->loadFromExtension('framework', [
116-
'session' => [
117+
use Symfony\Config\FrameworkConfig;
118+
119+
return static function (FrameworkConfig $framework) {
120+
$framework->session()
117121
// ...
118-
'handler_id' => 'session.handler.native_file',
119-
'save_path' => '%kernel.project_dir%/var/sessions/%kernel.environment%',
120-
],
121-
]);
122+
->handlerId('session.handler.native_file')
123+
->savePath('%kernel.project_dir%/var/sessions/%kernel.environment%')
124+
;
125+
};
122126
123127
Check out the Symfony config reference to learn more about the other available
124128
:ref:`Session configuration options <config-framework-session>`. You can also

templates.rst

Lines changed: 21 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -824,10 +824,12 @@ template fragments. Configure that special URL in the ``fragments`` option:
824824
.. code-block:: php
825825
826826
// config/packages/framework.php
827-
$container->loadFromExtension('framework', [
827+
use Symfony\Config\FrameworkConfig;
828+
829+
return static function (FrameworkConfig $framework) {
828830
// ...
829-
'fragments' => ['path' => '/_fragment'],
830-
]);
831+
$framework->fragments()->path('/_fragment');
832+
};
831833
832834
.. caution::
833835

@@ -1043,15 +1045,16 @@ the ``value`` is the Twig namespace, which is explained later:
10431045
.. code-block:: php
10441046
10451047
// config/packages/twig.php
1046-
$container->loadFromExtension('twig', [
1048+
use Symfony\Config\TwigConfig;
1049+
1050+
return static function (TwigConfig $twig) {
10471051
// ...
1048-
'paths' => [
1049-
// directories are relative to the project root dir (but you
1050-
// can also use absolute directories)
1051-
'email/default/templates' => null,
1052-
'backend/templates' => null,
1053-
],
1054-
]);
1052+
1053+
// directories are relative to the project root dir (but you
1054+
// can also use absolute directories)
1055+
$twig->path('email/default/templates', null);
1056+
$twig->path('backend/templates', null);
1057+
};
10551058
10561059
When rendering a template, Symfony looks for it first in the ``twig.paths``
10571060
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:
10981101
.. code-block:: php
10991102
11001103
// config/packages/twig.php
1101-
$container->loadFromExtension('twig', [
1104+
use Symfony\Config\TwigConfig;
1105+
1106+
return static function (TwigConfig $twig) {
11021107
// ...
1103-
'paths' => [
1104-
'email/default/templates' => 'email',
1105-
'backend/templates' => 'admin',
1106-
],
1107-
]);
1108+
1109+
$twig->path('email/default/templates', 'email');
1110+
$twig->path('backend/templates', 'admin');
1111+
};
11081112
11091113
Now, if you render the ``layout.html.twig`` template, Symfony will render the
11101114
``templates/layout.html.twig`` file. Use the special syntax ``@`` + namespace to

0 commit comments

Comments
 (0)