@@ -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
@@ -333,35 +299,31 @@ configuration arrays together.
333299Now, you can use the ``$config `` variable to modify a service provided by your bundle.
334300For example, imagine your bundle has the following example config:
335301
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 >
302+ .. code-block :: php
303+
304+ <!-- src/config/services.php -->
305+ namespace Symfony\Component\DependencyInjection\Loader\Configurator;
306+
307+ use Acme\SocialBundle\TwitterClient;
308+
309+ return function (ContainerConfigurator $container) {
310+ $container->services()
311+ ->set('acme_social.twitter_client', TwitterClient::class)
312+ ->args([abstract_arg('client_id'), abstract_arg('client_secret')]);
313+ };
352314
353315 In your extension, you can load this and dynamically set its arguments::
354316
355317 // src/DependencyInjection/AcmeSocialExtension.php
356318 namespace Acme\SocialBundle\DependencyInjection;
357319
358320 use Symfony\Component\Config\FileLocator;
359- use Symfony\Component\DependencyInjection\Loader\XmlFileLoader ;
321+ use Symfony\Component\DependencyInjection\Loader\PhpFileLoader ;
360322
361323 public function load(array $configs, ContainerBuilder $container): void
362324 {
363- $loader = new XmlFileLoader ($container, new FileLocator(dirname(__DIR__).'/Resources/config'));
364- $loader->load('services.xml ');
325+ $loader = new PhpFileLoader ($container, new FileLocator(dirname(__DIR__).'/Resources/config'));
326+ $loader->load('services.php ');
365327
366328 $configuration = new Configuration();
367329 $config = $this->processConfiguration($configuration, $configs);
@@ -401,7 +363,7 @@ In your extension, you can load this and dynamically set its arguments::
401363 Using the Config component is fully optional. The ``load() `` method gets an
402364 array of configuration values. You can instead parse these arrays yourself
403365 (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 ::
366+ for the existence of a value)::
405367
406368 public function load(array $configs, ContainerBuilder $container): void
407369 {
@@ -435,105 +397,6 @@ have something different, your ``Extension`` class must override the
435397:method: `Extension::getConfiguration() <Symfony\\ Component\\ DependencyInjection\\ Extension\\ Extension::getConfiguration> `
436398method and return an instance of your ``Configuration ``.
437399
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- Providing an XML Schema
481- ~~~~~~~~~~~~~~~~~~~~~~~
482-
483- XML has a very useful feature called `XML schema `_. This allows you to
484- describe all possible elements and attributes and their values in an XML Schema
485- Definition (an XSD file). This XSD file is used by IDEs for auto completion and
486- it is used by the Config component to validate the elements.
487-
488- In order to use the schema, the XML configuration file must provide an
489- ``xsi:schemaLocation `` attribute pointing to the XSD file for a certain XML
490- namespace. This location always starts with the XML namespace. This XML
491- namespace is then replaced with the XSD validation base path returned from
492- :method: `Extension::getXsdValidationBasePath() <Symfony\\ Component\\ DependencyInjection\\ Extension\\ ExtensionInterface::getXsdValidationBasePath> `
493- method. This namespace is then followed by the rest of the path from the base
494- path to the file itself.
495-
496- By convention, the XSD file lives in ``config/schema/ `` directory, but you
497- can place it anywhere you like. You should return this path as the base path::
498-
499- // src/DependencyInjection/AcmeHelloExtension.php
500- namespace Acme\HelloBundle\DependencyInjection;
501-
502- // ...
503- class AcmeHelloExtension extends Extension
504- {
505- // ...
506-
507- public function getXsdValidationBasePath(): string
508- {
509- return __DIR__.'/../config/schema';
510- }
511- }
512-
513- Assuming the XSD file is called ``hello-1.0.xsd ``, the schema location will be
514- ``https://acme_company.com/schema/dic/hello/hello-1.0.xsd ``:
515-
516- .. code-block :: xml
517-
518- <!-- config/packages/acme_hello.xml -->
519- <?xml version =" 1.0" encoding =" UTF-8" ?>
520- <container xmlns =" http://symfony.com/schema/dic/services"
521- xmlns : xsi =" http://www.w3.org/2001/XMLSchema-instance"
522- xmlns : acme-hello =" http://acme_company.com/schema/dic/hello"
523- xsi : schemaLocation =" http://symfony.com/schema/dic/services
524- https://symfony.com/schema/dic/services/services-1.0.xsd
525- http://acme_company.com/schema/dic/hello
526- https://acme_company.com/schema/dic/hello/hello-1.0.xsd"
527- >
528- <acme-hello : config >
529- <!-- ... -->
530- </acme-hello : config >
531-
532- <!-- ... -->
533- </container >
534-
535400.. _`FrameworkBundle Configuration` : https://github.com/symfony/symfony/blob/master/src/Symfony/Bundle/FrameworkBundle/DependencyInjection/Configuration.php
536401.. _`TwigBundle Configuration` : https://github.com/symfony/symfony/blob/master/src/Symfony/Bundle/TwigBundle/DependencyInjection/Configuration.php
537- .. _`XML namespace` : https://en.wikipedia.org/wiki/XML_namespace
538- .. _`XML schema` : https://en.wikipedia.org/wiki/XML_schema
539402.. _`snake case` : https://en.wikipedia.org/wiki/Snake_case
0 commit comments