@@ -20,23 +20,6 @@ as integration of other related components:
2020 framework :
2121 form : true
2222
23- .. code-block :: xml
24-
25- <!-- config/packages/framework.xml -->
26- <?xml version =" 1.0" encoding =" UTF-8" ?>
27- <container xmlns =" http://symfony.com/schema/dic/services"
28- xmlns : xsi =" http://www.w3.org/2001/XMLSchema-instance"
29- xmlns : framework =" http://symfony.com/schema/dic/symfony"
30- xsi : schemaLocation =" http://symfony.com/schema/dic/services
31- https://symfony.com/schema/dic/services/services-1.0.xsd
32- http://symfony.com/schema/dic/symfony
33- https://symfony.com/schema/dic/symfony/symfony-1.0.xsd"
34- >
35- <framework : config >
36- <framework : form />
37- </framework : config >
38- </container >
39-
4023 .. code-block :: php
4124
4225 // config/packages/framework.php
@@ -162,23 +145,6 @@ can add some configuration that looks like this:
162145 client_id : 123
163146 client_secret : your_secret
164147
165- .. code-block :: xml
166-
167- <!-- config/packages/acme_social.xml -->
168- <?xml version =" 1.0" encoding =" UTF-8" ?>
169- <container xmlns =" http://symfony.com/schema/dic/services"
170- xmlns : xsi =" http://www.w3.org/2001/XMLSchema-instance"
171- xmlns : acme-social =" http://example.org/schema/dic/acme_social"
172- xsi : schemaLocation =" http://symfony.com/schema/dic/services
173- https://symfony.com/schema/dic/services/services-1.0.xsd"
174- >
175- <acme-social : config >
176- <acme-social : twitter client-id =" 123"
177- client-secret =" your_secret"
178- />
179- </acme-social : config >
180- </container >
181-
182148 .. code-block :: php
183149
184150 // config/packages/acme_social.php
@@ -228,7 +194,7 @@ First things first, you have to create an extension class as explained in
228194Whenever a user includes the ``acme_social `` key (which is the DI alias) in a
229195configuration file, the configuration under it is added to an array of
230196configurations and passed to the ``load() `` method of your extension (Symfony
231- automatically converts XML and YAML to an array).
197+ automatically converts the configuration to an array).
232198
233199For the configuration example in the previous section, the array passed to your
234200``load() `` method will look like this::
@@ -304,7 +270,7 @@ The ``Configuration`` class to handle the sample configuration looks like::
304270.. seealso ::
305271
306272 The ``Configuration `` class can be much more complicated than shown here,
307- supporting "prototype" nodes, advanced validation, XML-specific normalization
273+ supporting "prototype" nodes, advanced validation, plural/singular normalization
308274 and advanced merging. You can read more about this in
309275 :doc: `the Config component documentation </components/config/definition >`. You
310276 can also see it in action by checking out some core Configuration
@@ -331,37 +297,31 @@ in the ``Configuration`` class to validate, normalize and merge all the
331297configuration arrays together.
332298
333299Now, 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 >
300+ For example, imagine your bundle has the following example config::
301+
302+ <!-- src/Resources/config/services.php -->
303+ namespace Symfony\Component\DependencyInjection\Loader\Configurator;
304+
305+ use Acme\SocialBundle\TwitterClient;
306+
307+ return function (ContainerConfigurator $container) {
308+ $container->services()
309+ ->set('acme_social.twitter_client', TwitterClient::class)
310+ ->args([abstract_arg('client_id'), abstract_arg('client_secret')]);
311+ };
352312
353313In your extension, you can load this and dynamically set its arguments::
354314
355315 // src/DependencyInjection/AcmeSocialExtension.php
356316 namespace Acme\SocialBundle\DependencyInjection;
357317
358318 use Symfony\Component\Config\FileLocator;
359- use Symfony\Component\DependencyInjection\Loader\XmlFileLoader ;
319+ use Symfony\Component\DependencyInjection\Loader\PhpFileLoader ;
360320
361321 public function load(array $configs, ContainerBuilder $container): void
362322 {
363- $loader = new XmlFileLoader ($container, new FileLocator(dirname(__DIR__).'/Resources/config'));
364- $loader->load('services.xml ');
323+ $loader = new PhpFileLoader ($container, new FileLocator(dirname(__DIR__).'/Resources/config'));
324+ $loader->load('services.php ');
365325
366326 $configuration = new Configuration();
367327 $config = $this->processConfiguration($configuration, $configs);
@@ -401,7 +361,7 @@ In your extension, you can load this and dynamically set its arguments::
401361 Using the Config component is fully optional. The ``load() `` method gets an
402362 array of configuration values. You can instead parse these arrays yourself
403363 (e.g. by overriding configurations and using :phpfunction: `isset ` to check
404- for the existence of a value). Be aware that it'll be very hard to support XML ::
364+ for the existence of a value)::
405365
406366 public function load(array $configs, ContainerBuilder $container): void
407367 {
@@ -435,121 +395,6 @@ have something different, your ``Extension`` class must override the
435395:method: `Extension::getConfiguration() <Symfony\\ Component\\ DependencyInjection\\ Extension\\ Extension::getConfiguration> `
436396method and return an instance of your ``Configuration ``.
437397
438- Supporting XML
439- --------------
440-
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.
487-
488- Providing an XML Schema
489- ~~~~~~~~~~~~~~~~~~~~~~~
490-
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;
509-
510- // ...
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
522-
523- The ``getXsdValidationBasePath() `` method, together with XML support, is
524- deprecated since Symfony 7.4 and will be removed in Symfony 8.0.
525-
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.
528-
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 ``:
531-
532- .. code-block :: xml
533-
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 >
550-
551398.. _`FrameworkBundle Configuration` : https://github.com/symfony/symfony/blob/master/src/Symfony/Bundle/FrameworkBundle/DependencyInjection/Configuration.php
552399.. _`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
555400.. _`snake case` : https://en.wikipedia.org/wiki/Snake_case
0 commit comments