@@ -454,9 +454,11 @@ doubling them to prevent Symfony from interpreting them as container parameters)
454
454
.. code-block :: php
455
455
456
456
// config/packages/framework.php
457
- $container->loadFromExtension('framework', [
458
- 'ide' => 'myide://open?url=file://%%f&line=%%l',
459
- ]);
457
+ use Symfony\Config\FrameworkConfig;
458
+
459
+ return static function (FrameworkConfig $framework) {
460
+ $framework->ide('myide://open?url=file://%%f&line=%%l');
461
+ };
460
462
461
463
Since every developer uses a different IDE, the recommended way to enable this
462
464
feature is to configure it on a system level. This can be done by setting the
@@ -596,9 +598,11 @@ the application won't respond and the user will receive a 400 response.
596
598
.. code-block :: php
597
599
598
600
// config/packages/framework.php
599
- $container->loadFromExtension('framework', [
600
- 'trusted_hosts' => ['^example\.com$', '^example\.org$'],
601
- ]);
601
+ use Symfony\Config\FrameworkConfig;
602
+
603
+ return static function (FrameworkConfig $framework) {
604
+ $framework->trustedHosts(['^example\.com$', '^example\.org$']);
605
+ };
602
606
603
607
Hosts can also be configured to respond to any subdomain, via
604
608
``^(.+\.)?example\.com$ `` for instance.
@@ -724,9 +728,11 @@ You can also set ``esi`` to ``true`` to enable it:
724
728
.. code-block :: php
725
729
726
730
// config/packages/framework.php
727
- $container->loadFromExtension('framework', [
728
- 'esi' => true,
729
- ]);
731
+ use Symfony\Config\FrameworkConfig;
732
+
733
+ return static function (FrameworkConfig $framework) {
734
+ $framework->esi()->enabled(true);
735
+ };
730
736
731
737
fragments
732
738
~~~~~~~~~
@@ -1359,13 +1365,12 @@ To configure a ``jsonp`` format:
1359
1365
.. code-block :: php
1360
1366
1361
1367
// config/packages/framework.php
1362
- $container->loadFromExtension('framework', [
1363
- 'request' => [
1364
- 'formats' => [
1365
- 'jsonp' => 'application/javascript',
1366
- ],
1367
- ],
1368
- ]);
1368
+ use Symfony\Config\FrameworkConfig;
1369
+
1370
+ return static function (FrameworkConfig $framework) {
1371
+ $framework->request()
1372
+ ->format('jsonp', 'application/javascript');
1373
+ };
1369
1374
1370
1375
router
1371
1376
~~~~~~
@@ -1720,11 +1725,12 @@ setting the value to ``null``:
1720
1725
.. code-block :: php
1721
1726
1722
1727
// config/packages/framework.php
1723
- $container->loadFromExtension('framework', [
1724
- 'session' => [
1725
- 'save_path' => null,
1726
- ],
1727
- ]);
1728
+ use Symfony\Config\FrameworkConfig;
1729
+
1730
+ return static function (FrameworkConfig $framework) {
1731
+ $framework->session()
1732
+ ->savePath(null);
1733
+ };
1728
1734
1729
1735
.. _reference-session-metadata-update-threshold :
1730
1736
@@ -1774,11 +1780,12 @@ Whether to enable the session support in the framework.
1774
1780
.. code-block :: php
1775
1781
1776
1782
// config/packages/framework.php
1777
- $container->loadFromExtension('framework', [
1778
- 'session' => [
1779
- 'enabled' => true,
1780
- ],
1781
- ]);
1783
+ use Symfony\Config\FrameworkConfig;
1784
+
1785
+ return static function (FrameworkConfig $framework) {
1786
+ $framework->session()
1787
+ ->enabled(true);
1788
+ };
1782
1789
1783
1790
use_cookies
1784
1791
...........
@@ -1830,12 +1837,13 @@ This option allows you to define a base path to be used for assets:
1830
1837
.. code-block :: php
1831
1838
1832
1839
// config/packages/framework.php
1833
- $container->loadFromExtension('framework', [
1840
+ use Symfony\Config\FrameworkConfig;
1841
+
1842
+ return static function (FrameworkConfig $framework) {
1834
1843
// ...
1835
- 'assets' => [
1836
- 'base_path' => '/images',
1837
- ],
1838
- ]);
1844
+ $framework->assets()
1845
+ ->basePath('/images');
1846
+ };
1839
1847
1840
1848
.. _reference-templating-base-urls :
1841
1849
.. _reference-assets-base-urls :
@@ -1879,12 +1887,13 @@ collection each time it generates an asset's path:
1879
1887
.. code-block :: php
1880
1888
1881
1889
// config/packages/framework.php
1882
- $container->loadFromExtension('framework', [
1890
+ use Symfony\Config\FrameworkConfig;
1891
+
1892
+ return static function (FrameworkConfig $framework) {
1883
1893
// ...
1884
- 'assets' => [
1885
- 'base_urls' => ['http://cdn.example.com/'],
1886
- ],
1887
- ]);
1894
+ $framework->assets()
1895
+ ->baseUrls(['http://cdn.example.com/']);
1896
+ };
1888
1897
1889
1898
.. _reference-framework-assets-packages :
1890
1899
@@ -1928,16 +1937,14 @@ You can group assets into packages, to specify different base URLs for them:
1928
1937
.. code-block :: php
1929
1938
1930
1939
// config/packages/framework.php
1931
- $container->loadFromExtension('framework', [
1940
+ use Symfony\Config\FrameworkConfig;
1941
+
1942
+ return static function (FrameworkConfig $framework) {
1932
1943
// ...
1933
- 'assets' => [
1934
- 'packages' => [
1935
- 'avatars' => [
1936
- 'base_urls' => 'http://static_cdn.example.com/avatars',
1937
- ],
1938
- ],
1939
- ],
1940
- ]);
1944
+ $framework->assets()
1945
+ ->package('avatars')
1946
+ ->baseUrls(['http://static_cdn.example.com/avatars']);
1947
+ };
1941
1948
1942
1949
Now you can use the ``avatars `` package in your templates:
1943
1950
@@ -2005,12 +2012,13 @@ Now, activate the ``version`` option:
2005
2012
.. code-block :: php
2006
2013
2007
2014
// config/packages/framework.php
2008
- $container->loadFromExtension('framework', [
2015
+ use Symfony\Config\FrameworkConfig;
2016
+
2017
+ return static function (FrameworkConfig $framework) {
2009
2018
// ...
2010
- 'assets' => [
2011
- 'version' => 'v2',
2012
- ],
2013
- ]);
2019
+ $framework->assets()
2020
+ ->version('v2');
2021
+ };
2014
2022
2015
2023
Now, the same asset will be rendered as ``/images/logo.png?v2 `` If you use
2016
2024
this feature, you **must ** manually increment the ``version `` value
@@ -2132,25 +2140,25 @@ individually for each asset package:
2132
2140
.. code-block :: php
2133
2141
2134
2142
// config/packages/framework.php
2135
- $container->loadFromExtension('framework', [
2136
- 'assets' => [
2137
- 'version_strategy' => 'app.asset.my_versioning_strategy',
2138
- 'packages' => [
2139
- 'foo_package' => [
2140
- // this package removes any versioning (its assets won't be versioned)
2141
- 'version' => null,
2142
- ],
2143
- 'bar_package' => [
2144
- // this package uses its own strategy (the default strategy is ignored)
2145
- 'version_strategy' => 'app.asset.another_version_strategy',
2146
- ],
2147
- 'baz_package' => [
2148
- // this package inherits the default strategy
2149
- 'base_path' => '/images',
2150
- ],
2151
- ],
2152
- ],
2153
- ]) ;
2143
+ use Symfony\Config\FrameworkConfig;
2144
+
2145
+ return static function (FrameworkConfig $framework) {
2146
+ // ...
2147
+ $framework->assets()
2148
+ ->versionStrategy('app.asset.my_versioning_strategy');
2149
+
2150
+ $framework->assets()->package('foo_package')
2151
+ // this package removes any versioning (its assets won't be versioned)
2152
+ ->version(null);
2153
+
2154
+ $framework->assets()->package('bar_package')
2155
+ // this package uses its own strategy (the default strategy is ignored)
2156
+ ->versionStrategy('app.asset.another_version_strategy');
2157
+
2158
+ $framework->assets()->package('baz_package')
2159
+ // this package inherits the default strategy
2160
+ ->basePath('/images');
2161
+ } ;
2154
2162
2155
2163
.. note ::
2156
2164
@@ -2229,24 +2237,24 @@ package:
2229
2237
.. code-block :: php
2230
2238
2231
2239
// config/packages/framework.php
2232
- $container->loadFromExtension('framework', [
2233
- 'assets' => [
2240
+ use Symfony\Config\FrameworkConfig;
2241
+
2242
+ return static function (FrameworkConfig $framework) {
2243
+ // ...
2244
+ $framework->assets()
2234
2245
// this manifest is applied to every asset (including packages)
2235
- 'json_manifest_path' => '%kernel.project_dir%/public/build/manifest.json',
2236
- // you can use absolute URLs too and Symfony will download them automatically
2237
- // 'json_manifest_path' => 'https://cdn.example.com/manifest.json',
2238
- 'packages' => [
2239
- 'foo_package' => [
2240
- // this package uses its own manifest (the default file is ignored)
2241
- 'json_manifest_path' => '%kernel.project_dir%/public/build/a_different_manifest.json',
2242
- ],
2243
- 'bar_package' => [
2244
- // this package uses the global manifest (the default file is used)
2245
- 'base_path' => '/images',
2246
- ],
2247
- ],
2248
- ],
2249
- ]);
2246
+ ->jsonManifestPath('%kernel.project_dir%/public/build/manifest.json');
2247
+
2248
+ // you can use absolute URLs too and Symfony will download them automatically
2249
+ // 'json_manifest_path' => 'https://cdn.example.com/manifest.json',
2250
+ $framework->assets()->package('foo_package')
2251
+ // this package uses its own manifest (the default file is ignored)
2252
+ ->jsonManifestPath('%kernel.project_dir%/public/build/a_different_manifest.json');
2253
+
2254
+ $framework->assets()->package('bar_package')
2255
+ // this package uses the global manifest (the default file is used)
2256
+ ->basePath('/images');
2257
+ };
2250
2258
2251
2259
.. versionadded :: 5.1
2252
2260
@@ -2335,11 +2343,12 @@ performance a bit:
2335
2343
.. code-block :: php
2336
2344
2337
2345
// config/packages/translation.php
2338
- $container->loadFromExtension('framework', [
2339
- 'translator' => [
2340
- 'enabled_locales' => ['en', 'es'],
2341
- ],
2342
- ]);
2346
+ use Symfony\Config\FrameworkConfig;
2347
+
2348
+ return static function (FrameworkConfig $framework) {
2349
+ $framework->translator()
2350
+ ->enabledLocales(['en', 'es']);
2351
+ };
2343
2352
2344
2353
If some user makes requests with a locale not included in this option, the
2345
2354
application won't display any error because Symfony will display contents using
@@ -2621,15 +2630,13 @@ the component will look for additional validation files:
2621
2630
.. code-block :: php
2622
2631
2623
2632
// config/packages/framework.php
2624
- $container->loadFromExtension('framework', [
2625
- 'validation' => [
2626
- 'mapping' => [
2627
- 'paths' => [
2628
- '%kernel.project_dir%/config/validation/',
2629
- ],
2630
- ],
2631
- ],
2632
- ]);
2633
+ use Symfony\Config\FrameworkConfig;
2634
+
2635
+ return static function (FrameworkConfig $framework) {
2636
+ $framework->validation()
2637
+ ->mapping()
2638
+ ->paths(['%kernel.project_dir%/config/validation/']);
2639
+ };
2633
2640
2634
2641
annotations
2635
2642
~~~~~~~~~~~
@@ -2927,16 +2934,14 @@ To configure a Redis cache pool with a default lifetime of 1 hour, do the follow
2927
2934
.. code-block :: php
2928
2935
2929
2936
// config/packages/framework.php
2930
- $container->loadFromExtension('framework', [
2931
- 'cache' => [
2932
- 'pools' => [
2933
- 'cache.mycache' => [
2934
- 'adapter' => 'cache.adapter.redis',
2935
- 'default_lifetime' => 3600,
2936
- ],
2937
- ],
2938
- ],
2939
- ]);
2937
+ use Symfony\Config\FrameworkConfig;
2938
+
2939
+ return static function (FrameworkConfig $framework) {
2940
+ $framework->cache()
2941
+ ->pool('cache.mycache')
2942
+ ->adapters(['cache.adapter.redis'])
2943
+ ->defaultLifetime(3600);
2944
+ };
2940
2945
2941
2946
.. _reference-cache-pools-name :
2942
2947
@@ -3094,9 +3099,12 @@ A list of lock stores to be created by the framework extension.
3094
3099
.. code-block :: php
3095
3100
3096
3101
// config/packages/lock.php
3097
- $container->loadFromExtension('framework', [
3098
- 'lock' => '%env(LOCK_DSN)%',
3099
- ]);
3102
+ use Symfony\Config\FrameworkConfig;
3103
+
3104
+ return static function (FrameworkConfig $framework) {
3105
+ $framework->lock()
3106
+ ->resource('lock', ['%env(LOCK_DSN)%']);
3107
+ };
3100
3108
3101
3109
.. seealso ::
3102
3110
@@ -3281,11 +3289,14 @@ A list of workflows to be created by the framework extension:
3281
3289
.. code-block :: php
3282
3290
3283
3291
// config/packages/workflow.php
3284
- $container->loadFromExtension('framework', [
3285
- 'workflows' => [
3286
- 'my_workflow' => // ...
3287
- ],
3288
- ]);
3292
+ use Symfony\Config\FrameworkConfig;
3293
+
3294
+ return static function (FrameworkConfig $framework) {
3295
+ $framework->workflows()
3296
+ ->workflows('my_workflow')
3297
+ // ...
3298
+ ;
3299
+ };
3289
3300
3290
3301
.. seealso ::
3291
3302
0 commit comments