Skip to content

Commit a44fe9d

Browse files
committed
Merge branch '5.0' into 5.1
* 5.0: Updated some config file paths Use "closure-style" PHP configuration format in code examples [Security] Mention the feature to use a custom AccessDecisionManager Update bundles.rst [Console] Update input.rst
2 parents 793bed1 + b5079ba commit a44fe9d

File tree

4 files changed

+122
-45
lines changed

4 files changed

+122
-45
lines changed

bundles.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ file::
3131
Symfony\Bundle\SwiftmailerBundle\SwiftmailerBundle::class => ['all' => true],
3232
Doctrine\Bundle\DoctrineBundle\DoctrineBundle::class => ['all' => true],
3333
Sensio\Bundle\FrameworkExtraBundle\SensioFrameworkExtraBundle::class => ['all' => true],
34-
// this bundle is enabled only in 'dev' and 'test', so you can't use it in 'prod'
34+
// this bundle is enabled only in 'dev' and 'test', so you can't use it in 'prod'
3535
Symfony\Bundle\WebProfilerBundle\WebProfilerBundle::class => ['dev' => true, 'test' => true],
3636
];
3737

configuration.rst

Lines changed: 74 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -120,12 +120,15 @@ configuration files, even if they use a different format:
120120
.. code-block:: php
121121
122122
// config/services.php
123-
$loader->import('legacy_config.xml');
124-
// the third optional argument of import() is 'ignore_errors', which
125-
// silently discards errors if the loaded file doesn't exist
126-
$loader->import('my_config_file.yaml', null, true);
127-
// glob expressions are also supported to load multiple files
128-
$loader->import('/etc/myapp/*.yaml');
123+
namespace Symfony\Component\DependencyInjection\Loader\Configurator;
124+
125+
return static function (ContainerConfigurator $container) {
126+
$container->import('legacy_config.php');
127+
// ignore_errors (3rd parameter) silently discards errors if the loaded file doesn't exist
128+
$container->import('my_config_file.xml', null, true);
129+
// glob expressions are also supported to load multiple files
130+
$container->import('/etc/myapp/*.yaml');
131+
};
129132
130133
// ...
131134
@@ -209,24 +212,29 @@ reusable configuration value. By convention, parameters are defined under the
209212
.. code-block:: php
210213
211214
// config/services.php
212-
// the parameter name is an arbitrary string (the 'app.' prefix is recommended
213-
// to better differentiate your parameters from Symfony parameters).
214-
$container->setParameter('app.admin_email', 'something@example.com');
215+
namespace Symfony\Component\DependencyInjection\Loader\Configurator;
215216
216-
// boolean parameters
217-
$container->setParameter('app.enable_v2_protocol', true);
217+
use App\Entity\BlogPost;
218218
219-
// array/collection parameters
220-
$container->setParameter('app.supported_locales', ['en', 'es', 'fr']);
219+
return static function (ContainerConfigurator $container) {
220+
$container->parameters()
221+
// the parameter name is an arbitrary string (the 'app.' prefix is recommended
222+
// to better differentiate your parameters from Symfony parameters).
223+
->set('app.admin_email', 'something@example.com')
221224
222-
// binary content parameters (use the PHP escape sequences)
223-
$container->setParameter('app.some_parameter', 'This is a Bell char: \x07');
225+
// boolean parameters
226+
->set('app.enable_v2_protocol', true)
224227
225-
// PHP constants as parameter values
226-
use App\Entity\BlogPost;
228+
// array/collection parameters
229+
->set('app.supported_locales', ['en', 'es', 'fr'])
227230
228-
$container->setParameter('app.some_constant', GLOBAL_CONSTANT);
229-
$container->setParameter('app.another_constant', BlogPost::MAX_ITEMS);
231+
// binary content parameters (use the PHP escape sequences)
232+
->set('app.some_parameter', 'This is a Bell char: \x07')
233+
234+
// PHP constants as parameter values
235+
->set('app.some_constant', GLOBAL_CONSTANT)
236+
->set('app.another_constant', BlogPost::MAX_ITEMS);
237+
};
230238
231239
// ...
232240
@@ -278,12 +286,17 @@ configuration file using a special syntax: wrap the parameter name in two ``%``
278286
.. code-block:: php
279287
280288
// config/packages/some_package.php
281-
$container->loadFromExtension('some_package', [
282-
// any string surrounded by two % is replaced by that parameter value
283-
'email_address' => '%app.admin_email%',
289+
namespace Symfony\Component\DependencyInjection\Loader\Configurator;
290+
291+
return static function (ContainerConfigurator $container) {
292+
$container->extension('some_package', [
293+
// any string surrounded by two % is replaced by that parameter value
294+
'email_address' => '%app.admin_email%',
295+
296+
// ...
297+
]);
298+
};
284299
285-
// ...
286-
]);
287300
288301
.. note::
289302

@@ -310,7 +323,12 @@ configuration file using a special syntax: wrap the parameter name in two ``%``
310323
.. code-block:: php
311324
312325
// config/services.php
313-
$container->setParameter('url_pattern', 'http://symfony.com/?foo=%%s&bar=%%d');
326+
namespace Symfony\Component\DependencyInjection\Loader\Configurator;
327+
328+
return static function (ContainerConfigurator $container) {
329+
$container->parameters()
330+
->set('url_pattern', 'http://symfony.com/?foo=%%s&bar=%%d');
331+
};
314332
315333
.. include:: /components/dependency_injection/_imports-parameters-note.rst.inc
316334

@@ -478,12 +496,16 @@ This example shows how you could configure the database connection using an env
478496
.. code-block:: php
479497
480498
// config/packages/doctrine.php
481-
$container->loadFromExtension('doctrine', [
482-
'dbal' => [
483-
// by convention the env var names are always uppercase
484-
'url' => '%env(resolve:DATABASE_URL)%',
485-
]
486-
]);
499+
namespace Symfony\Component\DependencyInjection\Loader\Configurator;
500+
501+
return static function (ContainerConfigurator $container) {
502+
$container->extension('doctrine', [
503+
'dbal' => [
504+
// by convention the env var names are always uppercase
505+
'url' => '%env(resolve:DATABASE_URL)%',
506+
]
507+
]);
508+
};
487509
488510
.. seealso::
489511

@@ -772,13 +794,18 @@ doesn't work for parameters:
772794
.. code-block:: php
773795
774796
// config/services.php
797+
namespace Symfony\Component\DependencyInjection\Loader\Configurator;
798+
775799
use App\Service\MessageGenerator;
776-
use Symfony\Component\DependencyInjection\Reference;
777800
778-
$container->setParameter('app.contents_dir', '...');
801+
return static function (ContainerConfigurator $container) {
802+
$container->parameters()
803+
->set('app.contents_dir', '...');
779804
780-
$container->getDefinition(MessageGenerator::class)
781-
->setArgument('$contentsDir', '%app.contents_dir%');
805+
$container->services()
806+
->get(MessageGenerator::class)
807+
->arg('$contentsDir', '%app.contents_dir%');
808+
};
782809
783810
If you inject the same parameters over and over again, use the
784811
``services._defaults.bind`` option instead. The arguments defined in that option are
@@ -824,18 +851,22 @@ whenever a service/controller defines a ``$projectDir`` argument, use this:
824851
.. code-block:: php
825852
826853
// config/services.php
854+
namespace Symfony\Component\DependencyInjection\Loader\Configurator;
855+
827856
use App\Controller\LuckyController;
828857
use Psr\Log\LoggerInterface;
829858
use Symfony\Component\DependencyInjection\Reference;
830859
831-
$container->register(LuckyController::class)
832-
->setPublic(true)
833-
->setBindings([
834-
// pass this value to any $projectDir argument for any service
835-
// that's created in this file (including controller arguments)
836-
'$projectDir' => '%kernel.project_dir%',
837-
])
838-
;
860+
return static function (ContainerConfigurator $container) {
861+
$container->services()
862+
->set(LuckyController::class)
863+
->public()
864+
->args([
865+
// pass this value to any $projectDir argument for any service
866+
// that's created in this file (including controller arguments)
867+
'$projectDir' => '%kernel.project_dir%',
868+
]);
869+
};
839870
840871
.. seealso::
841872

console/input.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ There are three argument variants you can use:
106106
The argument can contain any number of values. For that reason, it must be
107107
used at the end of the argument list.
108108

109-
You can combine ``IS_ARRAY`` with ``REQUIRED`` and ``OPTIONAL`` like this::
109+
You can combine ``IS_ARRAY`` with ``REQUIRED`` or ``OPTIONAL`` like this::
110110

111111
$this
112112
// ...

security/voters.rst

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -323,3 +323,49 @@ security configuration:
323323
'allow_if_all_abstain' => false,
324324
],
325325
]);
326+
327+
Custom Access Decision Strategy
328+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
329+
330+
If none of the built-in strategies fits your use case, define the ``service``
331+
option to use a custom service as the Access Decision Manager (your service
332+
must implement the :class:`Symfony\\Component\\Security\\Core\\Authorization\\AccessDecisionManagerInterface`):
333+
334+
.. configuration-block::
335+
336+
.. code-block:: yaml
337+
338+
# config/packages/security.yaml
339+
security:
340+
access_decision_manager:
341+
service: App\Security\MyCustomAccessDecisionManager
342+
# ...
343+
344+
.. code-block:: xml
345+
346+
<!-- config/packages/security.xml -->
347+
<?xml version="1.0" encoding="UTF-8" ?>
348+
<srv:container xmlns="http://symfony.com/schema/dic/security"
349+
xmlns:srv="http://symfony.com/schema/dic/services"
350+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
351+
xsi:schemaLocation="http://symfony.com/schema/dic/services
352+
https://symfony.com/schema/dic/services/services-1.0.xsd"
353+
>
354+
355+
<config>
356+
<access-decision-manager
357+
service="App\Security\MyCustomAccessDecisionManager"/>
358+
</config>
359+
</srv:container>
360+
361+
.. code-block:: php
362+
363+
// config/packages/security.php
364+
use App\Security\MyCustomAccessDecisionManager;
365+
366+
$container->loadFromExtension('security', [
367+
'access_decision_manager' => [
368+
'service' => MyCustomAccessDecisionManager::class,
369+
// ...
370+
],
371+
]);

0 commit comments

Comments
 (0)