Skip to content

Commit 2576835

Browse files
committed
Merge branch '3.4' into 4.4
* 3.4: Minor fixes in configuration blocks
2 parents 5b7a873 + 853d05f commit 2576835

13 files changed

+307
-87
lines changed

bundles/configuration.rst

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -420,7 +420,9 @@ Assuming the XSD file is called ``hello-1.0.xsd``, the schema location will be
420420
<container xmlns="http://symfony.com/schema/dic/services"
421421
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
422422
xmlns:acme-hello="http://acme_company.com/schema/dic/hello"
423-
xsi:schemaLocation="http://acme_company.com/schema/dic/hello
423+
xsi:schemaLocation="http://symfony.com/schema/dic/services
424+
https://symfony.com/schema/dic/services/services-1.0.xsd
425+
http://acme_company.com/schema/dic/hello
424426
https://acme_company.com/schema/dic/hello/hello-1.0.xsd">
425427
426428
<acme-hello:config>

bundles/prepend_extension.rst

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -122,9 +122,14 @@ registered and the ``entity_manager_name`` setting for ``acme_hello`` is set to
122122
xmlns:acme-something="http://example.org/schema/dic/acme_something"
123123
xmlns:acme-other="http://example.org/schema/dic/acme_other"
124124
xsi:schemaLocation="http://symfony.com/schema/dic/services
125-
https://symfony.com/schema/dic/services/services-1.0.xsd">
125+
https://symfony.com/schema/dic/services/services-1.0.xsd
126+
http://example.org/schema/dic/acme_something
127+
https://example.org/schema/dic/acme_something/acme_something-1.0.xsd
128+
http://example.org/schema/dic/acme_other
129+
https://example.org/schema/dic/acme_something/acme_other-1.0.xsd">
126130
127131
<acme-something:config use-acme-goodbye="false">
132+
<!-- ... -->
128133
<acme-something:entity-manager-name>non_default</acme-something:entity-manager-name>
129134
</acme-something:config>
130135

cache.rst

Lines changed: 56 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,9 @@ adapter (template) they use by using the ``app`` and ``system`` key like:
7575
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
7676
xmlns:framework="http://symfony.com/schema/dic/symfony"
7777
xsi:schemaLocation="http://symfony.com/schema/dic/services
78-
https://symfony.com/schema/dic/services/services-1.0.xsd">
78+
https://symfony.com/schema/dic/services/services-1.0.xsd
79+
http://symfony.com/schema/dic/symfony
80+
https://symfony.com/schema/dic/symfony/symfony-1.0.xsd">
7981
8082
<framework:config>
8183
<framework:cache app="cache.adapter.filesystem"
@@ -136,7 +138,9 @@ will create pool with service id of ``cache.[type]``
136138
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
137139
xmlns:framework="http://symfony.com/schema/dic/symfony"
138140
xsi:schemaLocation="http://symfony.com/schema/dic/services
139-
https://symfony.com/schema/dic/services/services-1.0.xsd">
141+
https://symfony.com/schema/dic/services/services-1.0.xsd
142+
http://symfony.com/schema/dic/symfony
143+
https://symfony.com/schema/dic/symfony/symfony-1.0.xsd">
140144
141145
<framework:config>
142146
<!--
@@ -146,6 +150,7 @@ will create pool with service id of ``cache.[type]``
146150
default_memcached_provider: Service: cache.memcached
147151
default_pdo_provider: Service: cache.pdo
148152
-->
153+
<!-- "directory" attribute is only used with cache.adapter.filesystem -->
149154
<framework:cache directory="%kernel.cache_dir%/pools"
150155
default_doctrine_provider="app.doctrine_cache"
151156
default_psr6_provider="app.my_psr6_service"
@@ -226,14 +231,31 @@ You can also create more customized pools:
226231
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
227232
xmlns:framework="http://symfony.com/schema/dic/symfony"
228233
xsi:schemaLocation="http://symfony.com/schema/dic/services
229-
https://symfony.com/schema/dic/services/services-1.0.xsd">
234+
https://symfony.com/schema/dic/services/services-1.0.xsd
235+
http://symfony.com/schema/dic/symfony
236+
https://symfony.com/schema/dic/symfony/symfony-1.0.xsd">
230237
231238
<framework:config>
232-
<framework:cache default_memcached_provider="memcached://localhost">
239+
<framework:cache default-memcached-provider="memcached://localhost">
240+
<!-- creates a "custom_thing.cache" service
241+
autowireable via "CacheInterface $customThingCache"
242+
uses the "app" cache configuration -->
233243
<framework:pool name="custom_thing.cache" adapter="cache.app"/>
244+
245+
<!-- creates a "my_cache_pool" service
246+
autowireable via "CacheInterface $myCachePool" -->
234247
<framework:pool name="my_cache_pool" adapter="cache.adapter.array"/>
248+
249+
<!-- uses the default_memcached_provider from above -->
235250
<framework:pool name="acme.cache" adapter="cache.adapter.memcached"/>
236-
<framework:pool name="foobar.cache" adapter="cache.adapter.memcached" provider="memcached://user:password@example.com"/>
251+
252+
<!-- control adapter's configuration -->
253+
<framework:pool name="foobar.cache" adapter="cache.adapter.memcached"
254+
provider="memcached://user:password@example.com"
255+
/>
256+
257+
<!-- uses the "foobar.cache" pool as its backend but controls
258+
the lifetime and (like all pools) has a separate cache namespace -->
237259
<framework:pool name="short_cache" adapter="foobar.cache" default-lifetime="60"/>
238260
</framework:cache>
239261
</framework:config>
@@ -246,19 +268,32 @@ You can also create more customized pools:
246268
'cache' => [
247269
'default_memcached_provider' => 'memcached://localhost',
248270
'pools' => [
271+
// creates a "custom_thing.cache" service
272+
// autowireable via "CacheInterface $customThingCache"
273+
// uses the "app" cache configuration
249274
'custom_thing.cache' => [
250275
'adapter' => 'cache.app',
251276
],
277+
278+
// creates a "my_cache_pool" service
279+
// autowireable via "CacheInterface $myCachePool"
252280
'my_cache_pool' => [
253281
'adapter' => 'cache.adapter.array',
254282
],
283+
284+
// uses the default_memcached_provider from above
255285
'acme.cache' => [
256286
'adapter' => 'cache.adapter.memcached',
257287
],
288+
289+
// control adapter's configuration
258290
'foobar.cache' => [
259291
'adapter' => 'cache.adapter.memcached',
260292
'provider' => 'memcached://user:password@example.com',
261293
],
294+
295+
// uses the "foobar.cache" pool as its backend but controls
296+
// the lifetime and (like all pools) has a separate cache namespace
262297
'short_cache' => [
263298
'adapter' => 'foobar.cache',
264299
'default_lifetime' => 60,
@@ -331,7 +366,9 @@ and use that when configuring the pool.
331366
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
332367
xmlns:framework="http://symfony.com/schema/dic/symfony"
333368
xsi:schemaLocation="http://symfony.com/schema/dic/services
334-
https://symfony.com/schema/dic/services/services-1.0.xsd">
369+
https://symfony.com/schema/dic/services/services-1.0.xsd
370+
http://symfony.com/schema/dic/symfony
371+
https://symfony.com/schema/dic/symfony/symfony-1.0.xsd">
335372
336373
<framework:config>
337374
<framework:cache>
@@ -341,6 +378,7 @@ and use that when configuring the pool.
341378
342379
<services>
343380
<service id="app.my_custom_redis_provider" class="\Redis">
381+
<factory class="Symfony\Component\Cache\Adapter\RedisAdapter" method="createConnection"/>
344382
<argument>redis://localhost</argument>
345383
<argument type="collection">
346384
<argument key="retry_interval">2</argument>
@@ -353,6 +391,8 @@ and use that when configuring the pool.
353391
.. code-block:: php
354392
355393
// config/packages/cache.php
394+
use Symfony\Component\Cache\Adapter\RedisAdapter;
395+
356396
$container->loadFromExtension('framework', [
357397
'cache' => [
358398
'pools' => [
@@ -364,12 +404,14 @@ and use that when configuring the pool.
364404
],
365405
]);
366406
367-
$container->getDefinition('app.my_custom_redis_provider', \Redis::class)
407+
$container->register('app.my_custom_redis_provider', \Redis::class)
408+
->setFactory([RedisAdapter::class, 'createConnection'])
368409
->addArgument('redis://localhost')
369410
->addArgument([
370411
'retry_interval' => 2,
371412
'timeout' => 10
372-
]);
413+
])
414+
;
373415
374416
Creating a Cache Chain
375417
----------------------
@@ -511,7 +553,9 @@ to enable this feature. This could be added by using the following configuration
511553
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
512554
xmlns:framework="http://symfony.com/schema/dic/symfony"
513555
xsi:schemaLocation="http://symfony.com/schema/dic/services
514-
https://symfony.com/schema/dic/services/services-1.0.xsd">
556+
https://symfony.com/schema/dic/services/services-1.0.xsd
557+
http://symfony.com/schema/dic/symfony
558+
https://symfony.com/schema/dic/symfony/symfony-1.0.xsd">
515559
516560
<framework:config>
517561
<framework:cache>
@@ -523,6 +567,9 @@ to enable this feature. This could be added by using the following configuration
523567
.. code-block:: php
524568
525569
// config/packages/cache.php
570+
use Symfony\Component\Cache\Adapter\ChainAdapter;
571+
use Symfony\Component\DependencyInjection\Reference;
572+
526573
$container->loadFromExtension('framework', [
527574
'cache' => [
528575
'pools' => [

configuration/using_parameters_in_dic.rst

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,11 @@ Now, examine the results to see this closely:
5151
5252
<?xml version="1.0" encoding="UTF-8" ?>
5353
<container xmlns="http://symfony.com/schema/dic/services"
54-
xmlns:my-bundle="http://example.org/schema/dic/my_bundle">
54+
xmlns:my-bundle="http://example.org/schema/dic/my_bundle"
55+
xsi:schemaLocation="http://symfony.com/schema/dic/services
56+
https://symfony.com/schema/dic/services/services-1.0.xsd
57+
http://example.org/schema/dic/my_bundle
58+
https://example.org/schema/dic/my_bundle/my_bundle-1.0.xsd">
5559
5660
<my-bundle:config logging="true"/>
5761
<!-- true, as expected -->

console/commands_as_services.rst

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -89,20 +89,24 @@ Or set the ``command`` attribute on the ``console.command`` tag in your service
8989
9090
# config/services.yaml
9191
services:
92+
# ...
93+
9294
App\Command\SunshineCommand:
9395
tags:
9496
- { name: 'console.command', command: 'app:sunshine' }
95-
# ...
9697
9798
.. code-block:: xml
9899
99100
<!-- config/services.xml -->
100101
<?xml version="1.0" encoding="UTF-8" ?>
101102
<container xmlns="http://symfony.com/schema/dic/services"
102103
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
103-
xsi:schemaLocation="http://symfony.com/schema/dic/services https://symfony.com/schema/dic/services/services-1.0.xsd">
104+
xsi:schemaLocation="http://symfony.com/schema/dic/services
105+
https://symfony.com/schema/dic/services/services-1.0.xsd">
104106
105107
<services>
108+
<!-- ... -->
109+
106110
<service id="App\Command\SunshineCommand">
107111
<tag name="console.command" command="app:sunshine"/>
108112
</service>
@@ -113,10 +117,9 @@ Or set the ``command`` attribute on the ``console.command`` tag in your service
113117
114118
// config/services.php
115119
use App\Command\SunshineCommand;
116-
// ...
117120
118-
$container
119-
->register(SunshineCommand::class)
121+
// ...
122+
$container->register(SunshineCommand::class)
120123
->addTag('console.command', ['command' => 'app:sunshine'])
121124
;
122125

console/input.rst

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,8 @@ to greet all your friends). Only the last argument can be a list::
7474
'names',
7575
InputArgument::IS_ARRAY,
7676
'Who do you want to greet (separate multiple names with a space)?'
77-
);
77+
)
78+
;
7879

7980
To use this, specify as many names as you want:
8081

@@ -111,7 +112,8 @@ You can combine ``IS_ARRAY`` with ``REQUIRED`` and ``OPTIONAL`` like this::
111112
'names',
112113
InputArgument::IS_ARRAY | InputArgument::REQUIRED,
113114
'Who do you want to greet (separate multiple names with a space)?'
114-
);
115+
)
116+
;
115117

116118
Using Command Options
117119
---------------------
@@ -135,7 +137,8 @@ how many times in a row the message should be printed::
135137
InputOption::VALUE_REQUIRED,
136138
'How many times should the message be printed?',
137139
1
138-
);
140+
)
141+
;
139142

140143
Next, use this in the command to print the message multiple times::
141144

@@ -177,7 +180,8 @@ flag:
177180
InputOption::VALUE_REQUIRED,
178181
'How many times should the message be printed?',
179182
1
180-
);
183+
)
184+
;
181185

182186
Note that to comply with the `docopt standard`_, long options can specify their
183187
values after a white space or an ``=`` sign (e.g. ``--iterations 5`` or
@@ -221,7 +225,8 @@ You can combine ``VALUE_IS_ARRAY`` with ``VALUE_REQUIRED`` or
221225
InputOption::VALUE_REQUIRED | InputOption::VALUE_IS_ARRAY,
222226
'Which colors do you like?',
223227
['blue', 'red']
224-
);
228+
)
229+
;
225230

226231
Options with optional arguments
227232
-------------------------------
@@ -239,7 +244,8 @@ optionally accepts a value, but it's a bit tricky. Consider this example::
239244
null,
240245
InputOption::VALUE_OPTIONAL,
241246
'Should I yell while greeting?'
242-
);
247+
)
248+
;
243249

244250
This option can be used in 3 ways: ``--yell``, ``yell=louder``, and not passing
245251
the option at all. However, it's hard to distinguish between passing the option
@@ -258,7 +264,8 @@ To solve this issue, you have to set the option's default value to ``false``::
258264
InputOption::VALUE_OPTIONAL,
259265
'Should I yell while greeting?',
260266
false // this is the new default value, instead of null
261-
);
267+
)
268+
;
262269

263270
Now check the value of the option and keep in mind that ``false !== null``::
264271

controller.rst

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -231,7 +231,7 @@ the argument by its name:
231231
232232
# explicitly configure the service
233233
App\Controller\LuckyController:
234-
public: true
234+
tags: [controller.service_arguments]
235235
bind:
236236
# for any $logger argument, pass this specific service
237237
$logger: '@monolog.logger.doctrine'
@@ -251,7 +251,8 @@ the argument by its name:
251251
<!-- ... -->
252252
253253
<!-- Explicitly configure the service -->
254-
<service id="App\Controller\LuckyController" public="true">
254+
<service id="App\Controller\LuckyController">
255+
<tag name"controller.service_arguments"/>
255256
<bind key="$logger"
256257
type="service"
257258
id="monolog.logger.doctrine"
@@ -268,7 +269,7 @@ the argument by its name:
268269
use Symfony\Component\DependencyInjection\Reference;
269270
270271
$container->register(LuckyController::class)
271-
->setPublic(true)
272+
->addTag('controller.service_arguments')
272273
->setBindings([
273274
'$logger' => new Reference('monolog.logger.doctrine'),
274275
'$projectDir' => '%kernel.project_dir%'
@@ -278,6 +279,14 @@ the argument by its name:
278279
Like with all services, you can also use regular :ref:`constructor injection <services-constructor-injection>`
279280
in your controllers.
280281

282+
.. caution::
283+
284+
You can *only* pass *services* to your controller arguments in this way. It's not
285+
possible, for example, to pass a config parameter as a controller argument,
286+
even by using ``bind``. If you need a parameter, use the ``$this->getParameter('kernel.debug')``
287+
shortcut or pass the value through your controller's ``__construct()`` method
288+
and specify its value with ``bind``.
289+
281290
For more information about services, see the :doc:`/service_container` article.
282291

283292
Generating Controllers

controller/argument_value_resolver.rst

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,9 @@ type-hinted method arguments:
112112
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
113113
xmlns:sensio-framework-extra="http://symfony.com/schema/dic/symfony_extra"
114114
xsi:schemaLocation="http://symfony.com/schema/dic/services
115-
https://symfony.com/schema/dic/services/services-1.0.xsd">
115+
https://symfony.com/schema/dic/services/services-1.0.xsd
116+
http://symfony.com/schema/dic/symfony_extra
117+
https://symfony.com/schema/dic/symfony_extra/symfony_extra-1.0.xsd">
116118
117119
<sensio-framework-extra:config>
118120
<request converters="true" auto-convert="false"/>
@@ -217,7 +219,8 @@ and adding a priority.
217219
<?xml version="1.0" encoding="UTF-8" ?>
218220
<container xmlns="http://symfony.com/schema/dic/services"
219221
xmlns:xsi="http://www.w3.org/2001/XMLSchema-Instance"
220-
xsi:schemaLocation="http://symfony.com/schema/dic/services https://symfony.com/schema/dic/services/services-1.0.xsd">
222+
xsi:schemaLocation="http://symfony.com/schema/dic/services
223+
https://symfony.com/schema/dic/services/services-1.0.xsd">
221224
222225
<services>
223226
<!-- ... be sure autowiring is enabled -->
@@ -237,7 +240,8 @@ and adding a priority.
237240
use App\ArgumentResolver\UserValueResolver;
238241
239242
$container->autowire(UserValueResolver::class)
240-
->addTag('controller.argument_value_resolver', ['priority' => 50]);
243+
->addTag('controller.argument_value_resolver', ['priority' => 50])
244+
;
241245
242246
While adding a priority is optional, it's recommended to add one to make sure
243247
the expected value is injected. The ``RequestAttributeValueResolver`` has a

event_dispatcher.rst

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -108,8 +108,7 @@ using a special "tag":
108108
// config/services.php
109109
use App\EventListener\ExceptionListener;
110110
111-
$container
112-
->autowire(ExceptionListener::class)
111+
$container->register(ExceptionListener::class)
113112
->addTag('kernel.event_listener', ['event' => 'kernel.exception'])
114113
;
115114

0 commit comments

Comments
 (0)