@@ -228,7 +228,7 @@ First things first, you have to create an extension class as explained in
228228Whenever a user includes the ``acme_social `` key (which is the DI alias) in a
229229configuration file, the configuration under it is added to an array of
230230configurations and passed to the ``load() `` method of your extension (Symfony
231- automatically converts XML and YAML to an array).
231+ automatically converts YAML to an array).
232232
233233For the configuration example in the previous section, the array passed to your
234234``load() `` method will look like this::
@@ -304,7 +304,7 @@ The ``Configuration`` class to handle the sample configuration looks like::
304304.. seealso ::
305305
306306 The ``Configuration `` class can be much more complicated than shown here,
307- supporting "prototype" nodes, advanced validation, XML-specific normalization
307+ supporting "prototype" nodes, advanced validation, normalization
308308 and advanced merging. You can read more about this in
309309 :doc: `the Config component documentation </components/config/definition >`. You
310310 can also see it in action by checking out some core Configuration
@@ -331,37 +331,37 @@ in the ``Configuration`` class to validate, normalize and merge all the
331331configuration arrays together.
332332
333333Now, you can use the ``$config `` variable to modify a service provided by your bundle.
334- For example, imagine your bundle has the following example config:
335-
336- .. code-block :: xml
337-
338- <!-- src/config/services.xml -->
339- <? xml version = " 1.0 " encoding = " UTF-8 " ?>
340- < container xmlns = " http://symfony.com/schema/dic/services "
341- xmlns : xsi = " http://www.w3.org/2001/XMLSchema-instance "
342- xsi : schemaLocation = " http://symfony.com/schema/dic/ services
343- https://symfony.com/schema/dic/services/services-1.0.xsd "
344- >
345- < services >
346- < service id = " acme_social.twitter_client " class = " Acme\SocialBundle\TwitterClient " >
347- < argument ></ argument > <!-- will be filled in with client_id dynamically -->
348- < argument ></ argument > <!-- will be filled in with client_secret dynamically -->
349- </ service >
350- </ services >
351- </ container >
334+ For example, imagine your bundle has the following example config::
335+
336+ // config/services.php
337+ namespace Symfony\Component\DependencyInjection\Loader\Configurator;
338+
339+ use Acme\SocialBundle\TwitterClient;
340+
341+ return static function (ContainerConfigurator $container): void {
342+ $services = $container-> services();
343+
344+ $services
345+ ->set('acme_social.twitter_client', TwitterClient::class)
346+ ->args([
347+ param('client_id'), // dynamically filled
348+ param(' client_secret') // dynamically filled
349+ ])
350+ ;
351+ };
352352
353353In your extension, you can load this and dynamically set its arguments::
354354
355355 // src/DependencyInjection/AcmeSocialExtension.php
356356 namespace Acme\SocialBundle\DependencyInjection;
357357
358358 use Symfony\Component\Config\FileLocator;
359- use Symfony\Component\DependencyInjection\Loader\XmlFileLoader ;
359+ use Symfony\Component\DependencyInjection\Loader\PhpFileLoader ;
360360
361361 public function load(array $configs, ContainerBuilder $container): void
362362 {
363- $loader = new XmlFileLoader ($container, new FileLocator(dirname( __DIR__) .'/Resources /config'));
364- $loader->load('services.xml ');
363+ $loader = new PhpFileLoader ($container, new FileLocator(__DIR__.'/../.. /config'));
364+ $loader->load('services.php ');
365365
366366 $configuration = new Configuration();
367367 $config = $this->processConfiguration($configuration, $configs);
@@ -438,118 +438,40 @@ method and return an instance of your ``Configuration``.
438438Supporting XML
439439--------------
440440
441- Symfony allows people to provide the configuration in three different formats:
442- Yaml, XML and PHP. Both Yaml and PHP use the same syntax and are supported by
443- default when using the Config component. Supporting XML requires you to do some
444- more things. But when sharing your bundle with others, it is recommended that
445- you follow these steps.
446-
447- Make your Config Tree ready for XML
448- ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
449-
450- The Config component provides some methods by default to allow it to correctly
451- process XML configuration. See ":ref: `component-config-normalization `" of the
452- component documentation. However, you can do some optional things as well, this
453- will improve the experience of using XML configuration:
454-
455- Choosing an XML Namespace
456- ~~~~~~~~~~~~~~~~~~~~~~~~~
457-
458- In XML, the `XML namespace `_ is used to determine which elements belong to the
459- configuration of a specific bundle. The namespace is returned from the
460- :method: `Extension::getNamespace() <Symfony\\ Component\\ DependencyInjection\\ Extension\\ Extension::getNamespace> `
461- method. By convention, the namespace is a URL (it doesn't have to be a valid
462- URL nor does it need to exist). By default, the namespace for a bundle is
463- ``http://example.org/schema/dic/DI_ALIAS ``, where ``DI_ALIAS `` is the DI alias of
464- the extension. You might want to change this to a more professional URL::
465-
466- // src/DependencyInjection/AcmeHelloExtension.php
467- namespace Acme\HelloBundle\DependencyInjection;
468-
469- // ...
470- class AcmeHelloExtension extends Extension
471- {
472- // ...
473-
474- public function getNamespace(): string
475- {
476- return 'http://acme_company.com/schema/dic/hello';
477- }
478- }
479-
480- .. deprecated :: 7.4
481-
482- The ``getNamespace() `` method, together with XML support, is deprecated
483- since Symfony 7.4 and will be removed in Symfony 8.0.
484-
485- If your bundle needs to remain compatible with older Symfony versions that
486- still support XML, keep this method and add the ``@deprecated `` annotation to it.
441+ Before Symfony 8.0, it was recommended that reusable bundles use XML as their
442+ configuration format. XML support was deprecated in Symfony 7.4 and removed in
443+ Symfony 8.0.
487444
488- Providing an XML Schema
489- ~~~~~~~~~~~~~~~~~~~~~~~
445+ Starting with Symfony 8.0, the supported configuration formats are YAML and PHP.
446+ Symfony recommends that reusable bundles use PHP and define their configuration
447+ with the fluent interface methods::
490448
491- XML has a very useful feature called `XML schema `_. This allows you to
492- describe all possible elements and attributes and their values in an XML Schema
493- Definition (an XSD file). This XSD file is used by IDEs for auto completion and
494- it is used by the Config component to validate the elements.
495-
496- In order to use the schema, the XML configuration file must provide an
497- ``xsi:schemaLocation `` attribute pointing to the XSD file for a certain XML
498- namespace. This location always starts with the XML namespace. This XML
499- namespace is then replaced with the XSD validation base path returned from
500- :method: `Extension::getXsdValidationBasePath() <Symfony\\ Component\\ DependencyInjection\\ Extension\\ ExtensionInterface::getXsdValidationBasePath> `
501- method. This namespace is then followed by the rest of the path from the base
502- path to the file itself.
503-
504- By convention, the XSD file lives in ``config/schema/ `` directory, but you
505- can place it anywhere you like. You should return this path as the base path::
506-
507- // src/DependencyInjection/AcmeHelloExtension.php
508- namespace Acme\HelloBundle\DependencyInjection;
449+ // config/services.php
450+ namespace Symfony\Component\DependencyInjection\Loader\Configurator;
509451
510452 // ...
511- class AcmeHelloExtension extends Extension
512- {
513- // ...
514-
515- public function getXsdValidationBasePath(): string
516- {
517- return __DIR__.'/../config/schema';
518- }
519- }
520-
521- .. deprecated :: 7.4
453+ use Symfony\Component\DependencyInjection\ServiceLocator;
522454
523- The ``getXsdValidationBasePath() `` method, together with XML support, is
524- deprecated since Symfony 7.4 and will be removed in Symfony 8.0.
455+ return static function (ContainerConfigurator $container) {
456+ $container->parameters()
457+ ->set('your_bundle.some_parameter_name', '...')
458+ ;
525459
526- If your bundle needs to remain compatible with older Symfony versions that
527- still support XML, keep this method and add the ``@deprecated `` annotation to it.
460+ $container->services()
461+ ->set('your_bundle.some_service', SomeService::class)
462+ ->args([
463+ service('...'),
464+ service('...'),
465+ ])
466+ ->alias(AnotherClass::class, 'your_bundle.another_name')
528467
529- Assuming the XSD file is called `` hello-1.0.xsd ``, the schema location will be
530- `` https://acme_company.com/schema/dic/hello/hello-1.0.xsd ``:
468+ ->set('your_bundle.other_service', OtherService::class)
469+ ->tag('kernel.reset', ['method' => '...'])
531470
532- .. code-block :: xml
471+ ->set('your_bundle.another_service', AnotherService::class)
533472
534- <!-- config/packages/acme_hello.xml -->
535- <?xml version =" 1.0" encoding =" UTF-8" ?>
536- <container xmlns =" http://symfony.com/schema/dic/services"
537- xmlns : xsi =" http://www.w3.org/2001/XMLSchema-instance"
538- xmlns : acme-hello =" http://acme_company.com/schema/dic/hello"
539- xsi : schemaLocation =" http://symfony.com/schema/dic/services
540- https://symfony.com/schema/dic/services/services-1.0.xsd
541- http://acme_company.com/schema/dic/hello
542- https://acme_company.com/schema/dic/hello/hello-1.0.xsd"
543- >
544- <acme-hello : config >
545- <!-- ... -->
546- </acme-hello : config >
547-
548- <!-- ... -->
549- </container >
473+ // ...
550474
551475.. _`FrameworkBundle Configuration` : https://github.com/symfony/symfony/blob/master/src/Symfony/Bundle/FrameworkBundle/DependencyInjection/Configuration.php
552476.. _`TwigBundle Configuration` : https://github.com/symfony/symfony/blob/master/src/Symfony/Bundle/TwigBundle/DependencyInjection/Configuration.php
553- .. _`XML namespace` : https://en.wikipedia.org/wiki/XML_namespace
554- .. _`XML schema` : https://en.wikipedia.org/wiki/XML_schema
555477.. _`snake case` : https://en.wikipedia.org/wiki/Snake_case
0 commit comments