Skip to content

Commit eab953a

Browse files
Remove mentions of the deprecated XML format
1 parent d93afd0 commit eab953a

File tree

127 files changed

+79
-11595
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

127 files changed

+79
-11595
lines changed

best_practices.rst

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -201,7 +201,7 @@ most services will be configured automatically. However, in some edge cases
201201
you'll need to configure services (or parts of them) manually.
202202

203203
YAML is the format recommended configuring services because it's friendly to
204-
newcomers and concise, but Symfony also supports XML and PHP configuration.
204+
newcomers and concise, but Symfony also supports PHP configuration.
205205

206206
Use Attributes to Define the Doctrine Entity Mapping
207207
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
@@ -238,7 +238,7 @@ Use Attributes to Configure Routing, Caching, and Security
238238

239239
Using attributes for routing, caching, and security simplifies
240240
configuration. You don't need to browse several files created with different
241-
formats (YAML, XML, PHP): all the configuration is just where you require it,
241+
formats (YAML, PHP): all the configuration is just where you require it,
242242
and it only uses one format.
243243

244244
Use Dependency Injection to Get Services

bundles/best_practices.rst

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -427,21 +427,6 @@ The end user can provide values in any configuration file:
427427
parameters:
428428
acme_blog.author.email: '[email protected]'
429429
430-
.. code-block:: xml
431-
432-
<!-- config/services.xml -->
433-
<?xml version="1.0" encoding="UTF-8" ?>
434-
<container xmlns="http://symfony.com/schema/dic/services"
435-
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
436-
xsi:schemaLocation="http://symfony.com/schema/dic/services
437-
https://symfony.com/schema/dic/services/services-1.0.xsd"
438-
>
439-
<parameters>
440-
<parameter key="acme_blog.author.email">[email protected]</parameter>
441-
</parameters>
442-
443-
</container>
444-
445430
.. code-block:: php
446431
447432
// config/services.php

bundles/configuration.rst

Lines changed: 18 additions & 155 deletions
Original file line numberDiff line numberDiff line change
@@ -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
228194
Whenever a user includes the ``acme_social`` key (which is the DI alias) in a
229195
configuration file, the configuration under it is added to an array of
230196
configurations 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

233199
For 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.
333299
Now, you can use the ``$config`` variable to modify a service provided by your bundle.
334300
For 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>`
436398
method 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

bundles/extension.rst

Lines changed: 8 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,8 @@ method to load service definitions from configuration files::
3333
{
3434
public function loadExtension(array $config, ContainerConfigurator $container, ContainerBuilder $builder): void
3535
{
36-
// load an XML, PHP or YAML file
37-
$container->import('../config/services.xml');
36+
// load a PHP or YAML file
37+
$container->import('../config/services.php');
3838

3939
// you can also add or replace parameters and services
4040
$container->parameters()
@@ -143,25 +143,25 @@ container.
143143

144144
In the ``load()`` method, you can use PHP code to register service definitions,
145145
but it is more common if you put these definitions in a configuration file
146-
(using the YAML, XML or PHP format).
146+
(using the YAML or PHP format).
147147

148-
For instance, assume you have a file called ``services.xml`` in the
148+
For instance, assume you have a file called ``services.php`` in the
149149
``config/`` directory of your bundle, your ``load()`` method looks like::
150150

151151
use Symfony\Component\Config\FileLocator;
152-
use Symfony\Component\DependencyInjection\Loader\XmlFileLoader;
152+
use Symfony\Component\DependencyInjection\Loader\PhpFileLoader;
153153

154154
// ...
155155
public function load(array $configs, ContainerBuilder $container): void
156156
{
157-
$loader = new XmlFileLoader(
157+
$loader = new PhpFileLoader(
158158
$container,
159159
new FileLocator(__DIR__.'/../../config')
160160
);
161-
$loader->load('services.xml');
161+
$loader->load('services.php');
162162
}
163163

164-
The other available loaders are ``YamlFileLoader`` and ``PhpFileLoader``.
164+
The other available loader is ``YamlFileLoader``.
165165

166166
Using Configuration to Change the Services
167167
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
@@ -200,9 +200,3 @@ performance. Define the list of annotated classes to compile in the
200200
Patterns are transformed into the actual class namespaces using the classmap
201201
generated by Composer. Therefore, before using these patterns, you must generate
202202
the full classmap executing the ``dump-autoload`` command of Composer.
203-
204-
.. warning::
205-
206-
This technique can't be used when the classes to compile use the ``__DIR__``
207-
or ``__FILE__`` constants, because their values will change when loading
208-
these classes from the ``classes.php`` file.

bundles/prepend_extension.rst

Lines changed: 0 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -108,32 +108,6 @@ registered and the ``entity_manager_name`` setting for ``acme_hello`` is set to
108108
# ...
109109
use_acme_goodbye: false
110110
111-
.. code-block:: xml
112-
113-
<!-- config/packages/acme_something.xml -->
114-
<?xml version="1.0" encoding="UTF-8" ?>
115-
<container xmlns="http://symfony.com/schema/dic/services"
116-
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
117-
xmlns:acme-something="http://example.org/schema/dic/acme_something"
118-
xmlns:acme-other="http://example.org/schema/dic/acme_other"
119-
xsi:schemaLocation="http://symfony.com/schema/dic/services
120-
https://symfony.com/schema/dic/services/services-1.0.xsd
121-
http://example.org/schema/dic/acme_something
122-
https://example.org/schema/dic/acme_something/acme_something-1.0.xsd
123-
http://example.org/schema/dic/acme_other
124-
https://example.org/schema/dic/acme_something/acme_other-1.0.xsd"
125-
>
126-
<acme-something:config use-acme-goodbye="false">
127-
<!-- ... -->
128-
<acme-something:entity-manager-name>non_default</acme-something:entity-manager-name>
129-
</acme-something:config>
130-
131-
<acme-other:config use-acme-goodbye="false">
132-
<!-- ... -->
133-
</acme-other:config>
134-
135-
</container>
136-
137111
.. code-block:: php
138112
139113
// config/packages/acme_something.php

0 commit comments

Comments
 (0)