From 68aa9e165a06c8fb9af9e49d7c3657f43788768a Mon Sep 17 00:00:00 2001 From: Jules Pietri Date: Sun, 17 Jul 2022 17:42:51 +0200 Subject: [PATCH] Ensure config blocks are consistent --- bundles/best_practices.rst | 12 +- bundles/configuration.rst | 52 +-- bundles/override.rst | 4 +- bundles/prepend_extension.rst | 30 +- cache.rst | 308 ++++++++++-------- components/dependency_injection.rst | 24 +- .../_imports-parameters-note.rst.inc | 10 +- .../dependency_injection/compilation.rst | 13 +- .../http_foundation/session_configuration.rst | 21 +- components/serializer.rst | 18 +- components/var_dumper.rst | 17 +- 11 files changed, 302 insertions(+), 207 deletions(-) diff --git a/bundles/best_practices.rst b/bundles/best_practices.rst index c6e0521db82..64992cae3a9 100644 --- a/bundles/best_practices.rst +++ b/bundles/best_practices.rst @@ -421,8 +421,8 @@ The end user can provide values in any configuration file: - + https://symfony.com/schema/dic/services/services-1.0.xsd" + > fabien@example.com @@ -432,7 +432,13 @@ The end user can provide values in any configuration file: .. code-block:: php // config/services.php - $container->setParameter('acme_blog.author.email', 'fabien@example.com'); + namespace Symfony\Component\DependencyInjection\Loader\Configurator; + + return static function (ContainerConfigurator $container) { + $container->parameters() + ->set('acme_blog.author.email', 'fabien@example.com') + ; + }; Retrieve the configuration parameters in your code from the container:: diff --git a/bundles/configuration.rst b/bundles/configuration.rst index 25254b7efcb..41c34ee7bbc 100644 --- a/bundles/configuration.rst +++ b/bundles/configuration.rst @@ -20,19 +20,22 @@ as integration of other related components: .. code-block:: yaml + # config/packages/framework.yaml framework: form: true .. code-block:: xml + - + https://symfony.com/schema/dic/symfony/symfony-1.0.xsd" + > @@ -40,9 +43,14 @@ as integration of other related components: .. code-block:: php - $container->loadFromExtension('framework', [ - 'form' => true, - ]); + // config/packages/framework.php + namespace Symfony\Component\DependencyInjection\Loader\Configurator; + + return static function (ContainerConfigurator $container) { + $container->extension('framework', [ + 'form' => true, + ]); + }; Using the Bundle Extension -------------------------- @@ -69,24 +77,28 @@ can add some configuration that looks like this: xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:acme-social="http://example.org/schema/dic/acme_social" xsi:schemaLocation="http://symfony.com/schema/dic/services - https://symfony.com/schema/dic/services/services-1.0.xsd"> - + https://symfony.com/schema/dic/services/services-1.0.xsd" + > - + - - .. code-block:: php // config/packages/acme_social.php - $container->loadFromExtension('acme_social', [ - 'twitter' => [ - 'client_id' => 123, - 'client_secret' => 'your_secret', - ], - ]); + namespace Symfony\Component\DependencyInjection\Loader\Configurator; + + return static function (ContainerConfigurator $container) { + $container->extension('acme_social', [ + 'twitter' => [ + 'client_id' => 123, + 'client_secret' => 'your_secret', + ], + ]); + }; The basic idea is that instead of having the user override individual parameters, you let the user configure just a few, specifically created, @@ -242,8 +254,8 @@ For example, imagine your bundle has the following example config: - + https://symfony.com/schema/dic/services/services-1.0.xsd" + > @@ -423,8 +435,8 @@ Assuming the XSD file is called ``hello-1.0.xsd``, the schema location will be xsi:schemaLocation="http://symfony.com/schema/dic/services https://symfony.com/schema/dic/services/services-1.0.xsd http://acme_company.com/schema/dic/hello - https://acme_company.com/schema/dic/hello/hello-1.0.xsd"> - + https://acme_company.com/schema/dic/hello/hello-1.0.xsd" + > diff --git a/bundles/override.rst b/bundles/override.rst index bf53eb5ce3c..6cf3d37c386 100644 --- a/bundles/override.rst +++ b/bundles/override.rst @@ -139,8 +139,8 @@ to a new validation group: - + https://symfony.com/schema/dic/constraint-mapping/constraint-mapping-1.0.xsd" + > diff --git a/bundles/prepend_extension.rst b/bundles/prepend_extension.rst index c23f9133ff4..fe551f31083 100644 --- a/bundles/prepend_extension.rst +++ b/bundles/prepend_extension.rst @@ -127,29 +127,35 @@ registered and the ``entity_manager_name`` setting for ``acme_hello`` is set to http://example.org/schema/dic/acme_something https://example.org/schema/dic/acme_something/acme_something-1.0.xsd http://example.org/schema/dic/acme_other - https://example.org/schema/dic/acme_something/acme_other-1.0.xsd"> - + https://example.org/schema/dic/acme_something/acme_other-1.0.xsd" + > non_default - + + + .. code-block:: php // config/packages/acme_something.php - $container->loadFromExtension('acme_something', [ - // ... - 'use_acme_goodbye' => false, - 'entity_manager_name' => 'non_default', - ]); - $container->loadFromExtension('acme_other', [ - // ... - 'use_acme_goodbye' => false, - ]); + namespace Symfony\Component\DependencyInjection\Loader\Configurator; + + return static function (ContainerConfigurator $container) { + $container->extension('acme_something', [ + // ... + 'use_acme_goodbye' => false, + 'entity_manager_name' => 'non_default', + ]); + $container->extension('acme_other', [ + // ... + 'use_acme_goodbye' => false, + ]); + }; More than one Bundle using PrependExtensionInterface ---------------------------------------------------- diff --git a/cache.rst b/cache.rst index 9982c33a7cf..73766284f21 100644 --- a/cache.rst +++ b/cache.rst @@ -77,10 +77,11 @@ adapter (template) they use by using the ``app`` and ``system`` key like: xsi:schemaLocation="http://symfony.com/schema/dic/services https://symfony.com/schema/dic/services/services-1.0.xsd http://symfony.com/schema/dic/symfony - https://symfony.com/schema/dic/symfony/symfony-1.0.xsd"> - + https://symfony.com/schema/dic/symfony/symfony-1.0.xsd" + > - @@ -89,12 +90,16 @@ adapter (template) they use by using the ``app`` and ``system`` key like: .. code-block:: php // config/packages/cache.php - $container->loadFromExtension('framework', [ - 'cache' => [ - 'app' => 'cache.adapter.filesystem', - 'system' => 'cache.adapter.system', - ], - ]); + namespace Symfony\Component\DependencyInjection\Loader\Configurator; + + return static function (ContainerConfigurator $container) { + $container->extension('framework', [ + 'cache' => [ + 'app' => 'cache.adapter.filesystem', + 'system' => 'cache.adapter.system', + ], + ]); + }; The Cache component comes with a series of adapters pre-configured: @@ -140,8 +145,8 @@ will create pools with service IDs that follow the pattern ``cache.[type]``. xsi:schemaLocation="http://symfony.com/schema/dic/services https://symfony.com/schema/dic/services/services-1.0.xsd http://symfony.com/schema/dic/symfony - https://symfony.com/schema/dic/symfony/symfony-1.0.xsd"> - + https://symfony.com/schema/dic/symfony/symfony-1.0.xsd" + > + @@ -368,12 +385,14 @@ with either :class:`Symfony\\Contracts\\Cache\\CacheInterface` or // config/services.php namespace Symfony\Component\DependencyInjection\Loader\Configurator; - return function(ContainerConfigurator $configurator) { - $services = $configurator->services(); + return function(ContainerConfigurator $container) { + $container->services() + // ... - $services->set('app.cache.adapter.redis') - ->parent('cache.adapter.redis') - ->tag('cache.pool', ['namespace' => 'my_custom_namespace']); + ->set('app.cache.adapter.redis') + ->parent('cache.adapter.redis') + ->tag('cache.pool', ['namespace' => 'my_custom_namespace']) + ; }; Custom Provider Options @@ -415,11 +434,14 @@ and use that when configuring the pool. xsi:schemaLocation="http://symfony.com/schema/dic/services https://symfony.com/schema/dic/services/services-1.0.xsd http://symfony.com/schema/dic/symfony - https://symfony.com/schema/dic/symfony/symfony-1.0.xsd"> - + https://symfony.com/schema/dic/symfony/symfony-1.0.xsd" + > - + @@ -438,27 +460,34 @@ and use that when configuring the pool. .. code-block:: php // config/packages/cache.php + namespace Symfony\Component\DependencyInjection\Loader\Configurator; + use Symfony\Component\Cache\Adapter\RedisAdapter; - $container->loadFromExtension('framework', [ - 'cache' => [ - 'pools' => [ - 'cache.my_redis' => [ - 'adapter' => 'cache.adapter.redis', - 'provider' => 'app.my_custom_redis_provider', + return static function (ContainerConfigurator $container) { + $container->extension('framework', [ + 'cache' => [ + 'pools' => [ + 'cache.my_redis' => [ + 'adapter' => 'cache.adapter.redis', + 'provider' => 'app.my_custom_redis_provider', + ], ], ], - ], - ]); - - $container->register('app.my_custom_redis_provider', \Redis::class) - ->setFactory([RedisAdapter::class, 'createConnection']) - ->addArgument('redis://localhost') - ->addArgument([ - 'retry_interval' => 2, - 'timeout' => 10 - ]) - ; + ]); + + $container->services() + ->set('app.my_custom_redis_provider', \Redis::class) + ->factory([RedisAdapter::class, 'createConnection']) + ->args([ + 'redis://localhost', + [ + 'retry_interval' => 2, + 'timeout' => 10, + ] + ]) + ; + }; Creating a Cache Chain ---------------------- @@ -506,11 +535,14 @@ Symfony stores the item automatically in all the missing pools. xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:framework="http://symfony.com/schema/dic/symfony" xsi:schemaLocation="http://symfony.com/schema/dic/services - https://symfony.com/schema/dic/services/services-1.0.xsd"> - + https://symfony.com/schema/dic/services/services-1.0.xsd + http://symfony.com/schema/dic/symfony + https://symfony.com/schema/dic/symfony/symfony-1.0.xsd" + > - + @@ -522,20 +554,24 @@ Symfony stores the item automatically in all the missing pools. .. code-block:: php // config/packages/cache.php - $container->loadFromExtension('framework', [ - 'cache' => [ - 'pools' => [ - 'my_cache_pool' => [ - 'default_lifetime' => 31536000, // One year - 'adapters' => [ - 'cache.adapter.array', - 'cache.adapter.apcu', - ['name' => 'cache.adapter.redis', 'provider' => 'redis://user:password@example.com'], + namespace Symfony\Component\DependencyInjection\Loader\Configurator; + + return static function (ContainerConfigurator $container) { + $container->extension('framework', [ + 'cache' => [ + 'pools' => [ + 'my_cache_pool' => [ + 'default_lifetime' => 31536000, // One year + 'adapters' => [ + 'cache.adapter.array', + 'cache.adapter.apcu', + ['name' => 'cache.adapter.redis', 'provider' => 'redis://user:password@example.com'], + ], ], ], ], - ], - ]); + ]); + }; Using Cache Tags ---------------- @@ -602,11 +638,14 @@ to enable this feature. This could be added by using the following configuration xsi:schemaLocation="http://symfony.com/schema/dic/services https://symfony.com/schema/dic/services/services-1.0.xsd http://symfony.com/schema/dic/symfony - https://symfony.com/schema/dic/symfony/symfony-1.0.xsd"> - + https://symfony.com/schema/dic/symfony/symfony-1.0.xsd" + > - + @@ -614,16 +653,20 @@ to enable this feature. This could be added by using the following configuration .. code-block:: php // config/packages/cache.php - $container->loadFromExtension('framework', [ - 'cache' => [ - 'pools' => [ - 'my_cache_pool' => [ - 'adapter' => 'cache.adapter.redis', - 'tags' => true, + namespace Symfony\Component\DependencyInjection\Loader\Configurator; + + return static function (ContainerConfigurator $container) { + $container->extension('framework', [ + 'cache' => [ + 'pools' => [ + 'my_cache_pool' => [ + 'adapter' => 'cache.adapter.redis', + 'tags' => true, + ], ], ], - ], - ]); + ]); + }; Tags are stored in the same pool by default. This is good in most scenarios. But sometimes it might be better to store the tags in a different pool. That could be @@ -651,12 +694,17 @@ achieved by specifying the adapter. xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:framework="http://symfony.com/schema/dic/symfony" xsi:schemaLocation="http://symfony.com/schema/dic/services - https://symfony.com/schema/dic/services/services-1.0.xsd"> - + https://symfony.com/schema/dic/services/services-1.0.xsd + http://symfony.com/schema/dic/symfony + https://symfony.com/schema/dic/symfony/symfony-1.0.xsd" + > - - + + @@ -664,19 +712,23 @@ achieved by specifying the adapter. .. code-block:: php // config/packages/cache.php - $container->loadFromExtension('framework', [ - 'cache' => [ - 'pools' => [ - 'my_cache_pool' => [ - 'adapter' => 'cache.adapter.redis', - 'tags' => 'tag_pool', - ], - 'tag_pool' => [ - 'adapter' => 'cache.adapter.apcu', + namespace Symfony\Component\DependencyInjection\Loader\Configurator; + + return static function (ContainerConfigurator $container) { + $container->extension('framework', [ + 'cache' => [ + 'pools' => [ + 'my_cache_pool' => [ + 'adapter' => 'cache.adapter.redis', + 'tags' => 'tag_pool', + ], + 'tag_pool' => [ + 'adapter' => 'cache.adapter.apcu', + ], ], ], - ], - ]); + ]); + }; .. note:: diff --git a/components/dependency_injection.rst b/components/dependency_injection.rst index 486f89e599d..fab46ff3d26 100644 --- a/components/dependency_injection.rst +++ b/components/dependency_injection.rst @@ -259,15 +259,16 @@ config files: newsletter_manager: class: NewsletterManager calls: - - setMailer: ['@mailer'] + - [setMailer, ['@mailer']] .. code-block:: xml - + xsi:schemaLocation="http://symfony.com/schema/dic/services + https://symfony.com/schema/dic/services/services-1.0.xsd" + > sendmail @@ -290,24 +291,21 @@ config files: namespace Symfony\Component\DependencyInjection\Loader\Configurator; - return function(ContainerConfigurator $configurator) { - $configurator->parameters() + return static function (ContainerConfigurator $container) { + $container->parameters() // ... ->set('mailer.transport', 'sendmail') ; - $services = $configurator->services(); - - $services->set('mailer', 'Mailer') - ->args(['%mailer.transport%']) - ; + $container->services() + ->set('mailer', 'Mailer') + ->args(['%mailer.transport%']) - $services->set('newsletter_manager', 'NewsletterManager') - ->call('setMailer', [ref('mailer')]) + ->set('newsletter_manager', 'NewsletterManager') + ->call('setMailer', [ref('mailer')]) ; }; - Learn More ---------- diff --git a/components/dependency_injection/_imports-parameters-note.rst.inc b/components/dependency_injection/_imports-parameters-note.rst.inc index 92868df1985..50c6b736353 100644 --- a/components/dependency_injection/_imports-parameters-note.rst.inc +++ b/components/dependency_injection/_imports-parameters-note.rst.inc @@ -19,8 +19,8 @@ - + https://symfony.com/schema/dic/services/services-1.0.xsd" + > @@ -29,4 +29,8 @@ .. code-block:: php // config/services.php - $loader->import('%kernel.project_dir%/somefile.yaml'); + namespace Symfony\Component\DependencyInjection\Loader\Configurator; + + return static function (ContainerConfigurator $container) { + $container->import('%kernel.project_dir%/somefile.yaml'); + }; diff --git a/components/dependency_injection/compilation.rst b/components/dependency_injection/compilation.rst index acf754c0f5d..3f5812529b2 100644 --- a/components/dependency_injection/compilation.rst +++ b/components/dependency_injection/compilation.rst @@ -200,13 +200,16 @@ The XML version of the config would then look like this: - - + xmlns:acme-demo="http://www.example.com/schema/dic/acme_demo" + xsi:schemaLocation="http://symfony.com/schema/dic/services + https://symfony.com/schema/dic/services/services-1.0.xsd + http://www.example.com/schema/dic/acme_demo + https://www.example.com/schema/dic/acme_demo/acme_demo-1.0.xsd" + > + fooValue barValue - + .. note:: diff --git a/components/http_foundation/session_configuration.rst b/components/http_foundation/session_configuration.rst index 41aacae0e46..36ca212b006 100644 --- a/components/http_foundation/session_configuration.rst +++ b/components/http_foundation/session_configuration.rst @@ -187,21 +187,26 @@ configuration: xmlns:framework="http://symfony.com/schema/dic/symfony" xsi:schemaLocation="http://symfony.com/schema/dic/services https://symfony.com/schema/dic/services/services-1.0.xsd - http://symfony.com/schema/dic/symfony https://symfony.com/schema/dic/symfony/symfony-1.0.xsd"> - + http://symfony.com/schema/dic/symfony + https://symfony.com/schema/dic/symfony/symfony-1.0.xsd" + > - + .. code-block:: php // config/packages/framework.php - $container->loadFromExtension('framework', [ - 'session' => [ - 'gc_probability' => null, - ], - ]); + namespace Symfony\Component\DependencyInjection\Loader\Configurator; + + return static function (ContainerConfigurator $container) { + $container->extension('framework', [ + 'session' => [ + 'gc_probability' => null, + ], + ]); + }; You can configure these settings by passing ``gc_probability``, ``gc_divisor`` and ``gc_maxlifetime`` in an array to the constructor of diff --git a/components/serializer.rst b/components/serializer.rst index c26cd480134..81707bc5a05 100644 --- a/components/serializer.rst +++ b/components/serializer.rst @@ -816,6 +816,8 @@ faster alternative to the # config/services.yaml services: + # ... + get_set_method_normalizer: class: Symfony\Component\Serializer\Normalizer\GetSetMethodNormalizer tags: [serializer.normalizer] @@ -827,9 +829,11 @@ faster alternative to the - + https://symfony.com/schema/dic/services/services-1.0.xsd" + > + + @@ -843,11 +847,11 @@ faster alternative to the use Symfony\Component\Serializer\Normalizer\GetSetMethodNormalizer; - return function(ContainerConfigurator $configurator) { - $services = $configurator->services(); - - $services->set('get_set_method_normalizer', GetSetMethodNormalizer::class) - ->tag('serializer.normalizer') + return static function (ContainerConfigurator $container) { + $container->services() + // ... + ->set('get_set_method_normalizer', GetSetMethodNormalizer::class) + ->tag('serializer.normalizer') ; }; diff --git a/components/var_dumper.rst b/components/var_dumper.rst index a607ddeb59b..1202791b97c 100644 --- a/components/var_dumper.rst +++ b/components/var_dumper.rst @@ -131,22 +131,27 @@ the :ref:`dump_destination option ` of the - - + http://symfony.com/schema/dic/debug + https://symfony.com/schema/dic/debug/debug-1.0.xsd" + > .. code-block:: php // config/packages/debug.php - $container->loadFromExtension('debug', [ - 'dump_destination' => 'tcp://%env(VAR_DUMPER_SERVER)%', - ]); + namespace Symfony\Component\DependencyInjection\Loader\Configurator; + + return static function (ContainerConfigurator $container) { + $container->extension('debug', [ + 'dump_destination' => 'tcp://%env(VAR_DUMPER_SERVER)%', + ]); + }; Outside a Symfony application, use the :class:`Symfony\\Component\\VarDumper\\Dumper\\ServerDumper` class:: pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy