Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
56 changes: 56 additions & 0 deletions configuration.rst
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,62 @@ readable. These are the main advantages and disadvantages of each format:

Array shapes were introduced in Symfony 7.4.

When using the PHP format, you can wrap your configuration arrays with
:class:`Symfony\\Config\\ServicesConfig` or :class:`Symfony\\Config\\RoutesConfig`.
These wrappers are entirely optional but provide
`psalm array-shape <https://psalm.dev/docs/annotating_code/type_syntax/array_types/#array-shapes>`_
type definitions that enable autocompletion and static analysis in IDEs.

For service configuration (``config/services.php``)::

// config/services.php
use App\Service\MyService;
use Symfony\Config\ServicesConfig;

return new ServicesConfig(
defaults: [
'autowire' => true,
'autoconfigure' => true,
],
services: [
'App\\' => ['resource' => '../src/'],
MyService::class => null,
],
);

For routing configuration (``config/routes.php``)::

// config/routes.php
use Symfony\Config\RoutesConfig;

return new RoutesConfig([
'controllers' => [
'resource' => '../src/Controller/',
'type' => 'attribute',
],
]);

.. tip::

The ``ServicesConfig`` constructor also accepts ``imports``, ``parameters``
and ``instanceof`` arguments. The ``_defaults`` and ``_instanceof`` keys
should not be included in the ``services`` array; use the dedicated
``defaults`` and ``instanceof`` parameters instead.

These wrappers also work with environment-specific configuration using
``when@env``::

// config/services.php
use Symfony\Config\ServicesConfig;

return [
'when@dev' => new ServicesConfig(
services: [
'App\\' => ['resource' => '../src/', 'exclude' => '../src/{Entity,Kernel.php}'],
],
),
];

Importing Configuration Files
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Expand Down
4 changes: 2 additions & 2 deletions reference/configuration/security.rst
Original file line number Diff line number Diff line change
Expand Up @@ -194,8 +194,8 @@ allow_if_equal_granted_denied

This option is only used by the ``consensus`` strategy. If the number of
:doc:`voters </security/voters>` granting access is equal to the number of
voters denying access, this option determines the final decision. If ``true``
(the default), access is granted in case of a tie.
voters denying access, this option determines the final decision. If ``true``
(the default), access is granted in case of a tie.

service
.......
Expand Down
7 changes: 3 additions & 4 deletions routing.rst
Original file line number Diff line number Diff line change
Expand Up @@ -82,10 +82,9 @@ the ``list()`` method of the ``BlogController`` class.
.. warning::

If you define multiple PHP classes in the same file, Symfony only loads the
routes of the first class, ignoring all the other routes.The route attribute
is always wins over route with yaml, xml or PHP file and Symfony will always
load the route attribute.

routes of the first class, ignoring all the other routes. The route attribute
always wins over routes defined in YAML, XML or PHP files and Symfony will
always load the route attribute.

The route name (``blog_list``) is not important for now, but it will be
essential later when :ref:`generating URLs <routing-generating-urls>`. You only
Expand Down