8000 minor #13676 [DI] Renamed some PHP-DSL functions (javiereguiluz) · symfony/symfony-docs@e077b5f · GitHub
[go: up one dir, main page]

Skip to content

Commit e077b5f

Browse files
committed
minor #13676 [DI] Renamed some PHP-DSL functions (javiereguiluz)
This PR was squashed before being merged into the 5.1 branch. Discussion ---------- [DI] Renamed some PHP-DSL functions Fixes #13673. I propose to repeat the `deprecated in 5.1` message everywhere because the `ref() -> service()` is an important change and we don't want anybody to miss it. Thanks. Commits ------- 4af7b86 [DI] Renamed some PHP-DSL functions
2 parents 6cd9dbb + 4af7b86 commit e077b5f

13 files changed

+57
-54
lines changed

components/dependency_injection.rst

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -303,11 +303,11 @@ config files:
303303
;
304304
305305
$services->set('newsletter_manager', 'NewsletterManager')
306-
->call('setMailer', [ref('mailer')])
306+
// In versions earlier to Symfony 5.1 the service() function was called ref()
307+
->call('setMailer', [service('mailer')])
307308
;
308309
};
309310
310-
311311
Learn More
312312
----------
313313

security/custom_authentication_provider.rst

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -433,13 +433,14 @@ to service ids that may not exist yet: ``App\Security\Authentication\Provider\Ws
433433
$services = $configurator->services();
434434
435435
$services->set(WsseProvider::class)
436-
->arg('$cachePool', ref('cache.app'))
436+
->arg('$cachePool', service('cache.app'))
437437
;
438438
439439
$services->set(WsseListener::class)
440440
->args([
441-
ref('security.token_storage'),
442-
ref('security.authentication.manager'),
441+
// In versions earlier to Symfony 5.1 the service() function was called ref()
442+
service('security.token_storage'),
443+
service('security.authentication.manager'),
443444
])
444445
;
445446
};

service_container.rst

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -526,7 +526,8 @@ parameter and in PHP config use the ``Reference`` class:
526526
$services = $configurator->services();
527527
528528
$services->set(MessageGenerator::class)
529-
->args([ref('logger')])
529+
// In versions earlier to Symfony 5.1 the service() function was called ref()
530+
->args([service('logger')])
530531
;
531532
};
532533
@@ -633,7 +634,7 @@ But, you can control this and pass in a different logger:
633634
634635
// explicitly configure the service
635636
$services->set(SiteUpdateManager::class)
636-
->arg('$logger', ref('monolog.logger.request'))
637+
->arg('$logger', service('monolog.logger.request'))
637638
;
638639
};
639640
@@ -738,15 +739,15 @@ You can also use the ``bind`` keyword to bind specific arguments by name or type
738739
739740
// pass this service to any $requestLogger argument for any
740741
// service that's defined in this file
741-
->bind('$requestLogger', ref('monolog.logger.request'))
742+
->bind('$requestLogger', service('monolog.logger.request'))
742743
743744
// pass this service for any LoggerInterface type-hint for any
744745
// service that's defined in this file
745-
->bind(LoggerInterface::class, ref('monolog.logger.request'))
746+
->bind(LoggerInterface::class, service('monolog.logger.request'))
746747
747748
// optionally you can define both the name and type of the argument to match
748749
->bind('string $adminEmail', 'manager@example.com')
749-
->bind(LoggerInterface::class.' $requestLogger', ref('monolog.logger.request'))
750+
->bind(LoggerInterface::class.' $requestLogger', service('monolog.logger.request'))
750751
->bind('iterable $rules', tagged_iterator('app.foo.rule'))
751752
;
752753
@@ -1113,16 +1114,16 @@ admin email. In this case, each needs to have a unique service id:
11131114
->autowire(false)
11141115
// manually wire all arguments
11151116
->args([
1116-
ref(MessageGenerator::class),
1117-
ref('mailer'),
1117+
service(MessageGenerator::class),
1118+
service('mailer'),
11181119
'superadmin@example.com',
11191120
]);
11201121
11211122
$services->set('site_update_manager.normal_users', SiteUpdateManager::class)
11221123
->autowire(false)
11231124
->args([
1124-
ref(MessageGenerator::class),
1125-
ref('mailer'),
1125+
service(MessageGenerator::class),
1126+
service('mailer'),
11261127
'contact@example.com',
11271128
]);
11281129

service_container/alias_private.rst

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -284,20 +284,16 @@ The following example shows how to inject an anonymous service into another serv
284284
$services = $configurator->services();
285285
286286
$services->set(Foo::class)
287-
->args([service(AnonymousBar::class)])
287+
// In versions earlier to Symfony 5.1 the inline_service() function was called service()
288+
->args([inline_service(AnonymousBar::class)])
288289
};
289290
290-
.. versionadded:: 5.1
291-
292-
The ``service()`` function was introduced in Symfony 5.1. In previous
293-
versions it was called ``inline()``.
294-
295291
.. note::
296292

297293
Anonymous services do *NOT* inherit the definitions provided from the
298294
defaults defined in the configuration. So you'll need to explicitly mark
299295
service as autowired or autoconfigured when doing an anonymous service
300-
e.g.: ``service(Foo::class)->autowire()->autoconfigure()``.
296+
e.g.: ``inline_service(Foo::class)->autowire()->autoconfigure()``.
301297

302298
Using an anonymous service as a factory looks like this:
303299

@@ -340,7 +336,7 @@ Using an anonymous service as a factory looks like this:
340336
$services = $configurator->services();
341337
342338
$services->set(Foo::class)
343-
->factory([service(AnonymousBar::class), 'constructFoo'])
339+
->factory([inline_service(AnonymousBar::class), 'constructFoo'])
344340
};
345341
346342
Deprecating Services

service_container/autowiring.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -507,7 +507,7 @@ the injection::
507507
508508
// If you wanted to choose the non-default service and do not
509509
// want to use a named autowiring alias, wire it manually:
510-
// ->arg('$transformer', ref(UppercaseTransformer::class))
510+
// ->arg('$transformer', service(UppercaseTransformer::class))
511511
// ...
512512
};
513513

service_container/calls.rst

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -72,10 +72,10 @@ To configure the container to call the ``setLogger`` method, use the ``calls`` k
7272
// ...
7373
7474
$services->set(MessageGenerator::class)
75-
->call('setLogger', [ref('logger')]);
75+
// In versions earlier to Symfony 5.1 the service() function was called ref()
76+
->call('setLogger', [service('logger')]);
7677
};
7778
78-
7979
To provide immutable services, some classes implement immutable setters.
8080
Such setters return a new instance of the configured class
8181
instead of mutating the object they were called on::

service_container/configurators.rst

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -179,11 +179,12 @@ all the classes are already loaded as services. All you need to do is specify th
179179
$services->load('App\\', '../src/*');
180180
181181
// override the services to set the configurator
182+
// In versions earlier to Symfony 5.1 the service() function was called ref()
182183
$services->set(NewsletterManager::class)
183-
->configurator(ref(EmailConfigurator::class), 'configure');
184+
->configurator(service(EmailConfigurator::class), 'configure');
184185
185186
$services->set(GreetingCardManager::class)
186-
->configurator(ref(EmailConfigurator::class), 'configure');
187+
->configurator(service(EmailConfigurator::class), 'configure');
187188
};
188189
189190
.. _configurators-invokable:
@@ -250,10 +251,10 @@ routes can reference :ref:`invokable controllers <controller-service-invoke>`.
250251
251252
// override the services to set the configurator
252253
$services->set(NewsletterManager::class)
253-
->configurator(ref(EmailConfigurator::class));
254+
->configurator(service(EmailConfigurator::class));
254255
255256
$services->set(GreetingCardManager::class)
256-
->configurator(ref(EmailConfigurator::class));
257+
->configurator(service(EmailConfigurator::class));
257258
};
258259
259260
That's it! When requesting the ``App\Mail\NewsletterManager`` or

service_container/factories.rst

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -158,7 +158,8 @@ Configuration of the service container then looks like this:
158158
// second, use the factory service as the first argument of the 'factory'
159159
// method and the factory method as the second argument
160160
$services->set(NewsletterManager::class)
161-
->factory([ref(NewsletterManagerFa 10000 ctory::class), 'createNewsletterManager']);
161+
// In versions earlier to Symfony 5.1 the service() function was called ref()
162+
->factory([service(NewsletterManagerFactory::class), 'createNewsletterManager']);
162163
};
163164
164165
.. _factories-invokable:
@@ -228,8 +229,8 @@ method name, just as routes can reference
228229
$services = $configurator->services();
229230
230231
$services->set(NewsletterManager::class)
231-
->args([ref('templating')])
232-
->factory(ref(NewsletterManagerFactory::class));
232+
->args([service('templating')])
233+
->factory(service(NewsletterManagerFactory::class));
233234
};
234235
235236
.. _factories-passing-arguments-factory-method:
@@ -289,8 +290,8 @@ previous examples takes the ``templating`` service as an argument:
289290
$services = $configurator->services();
290291
291292
$services->set(NewsletterManager::class)
292-
->factory([ref(NewsletterManagerFactory::class), 'createNewsletterManager'])
293-
->args([ref('templating')])
293+
->factory([service(NewsletterManagerFactory::class), 'createNewsletterManager'])
294+
->args([service('templating')])
294295
;
295296
};
296297

service_container/injection_types.rst

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -77,10 +77,10 @@ service container configuration:
7777
$services = $configurator->services();
7878
7979
$services->set(NewsletterManager::class)
80-
->args(ref('mailer'));
80+
// In versions earlier to Symfony 5.1 the service() function was called ref()
81+
->args(service('mailer'));
8182
};
8283
83-
8484
.. tip::
8585

8686
Type hinting the injected object means that you can be sure that a suitable
@@ -270,7 +270,7 @@ that accepts the dependency::
270270
$services = $configurator->services();
271271
272272
$services->set(NewsletterManager::class)
273-
->call('setMailer', [ref('mailer')]);
273+
->call('setMailer', [service('mailer')]);
274274
};
275275
276276
This time the advantages are:
@@ -350,7 +350,7 @@ Another possibility is setting public fields of the class directly::
350350
$services = $configurator->services();
351351
352352
$services->set('app.newsletter_manager', NewsletterManager::class)
353-
->property('mailer', ref('mailer'));
353+
->property('mailer', service('mailer'));
354354
};
355355
356356
There are mainly only disadvantages to using property injection, it is similar

service_container/optional_dependencies.rst

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -42,10 +42,10 @@ if the service does not exist:
4242
$services = $configurator->services();
4343
4444
$services->set(NewsletterManager::class)
45-
->args([ref('logger')->nullOnInvalid()]);
45+
// In versions earlier to Symfony 5.1 the service() function was called ref()
46+
->args([service('logger')->nullOnInvalid()]);
4647
};
4748
48-
4949
.. note::
5050

5151
The "null" strategy is not currently supported by the YAML driver.
@@ -99,7 +99,7 @@ call if the service exists and remove the method call if it does not:
9999
$services = $configurator->services();
100100
101101
$services->set(NewsletterManager::class)
102-
->call('setLogger', [ref('logger')->ignoreOnInvalid()])
102+
->call('setLogger', [service('logger')->ignoreOnInvalid()])
103103
;
104104
};
105105

service_container/parent_services.rst

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -128,8 +128,9 @@ duplicated service definitions:
128128
129129
$services->set(BaseDoctrineRepository::class)
130130
->abstract()
131-
->args([ref('doctrine.orm.entity_manager')])
132-
->call('setLogger', [ref('logger')])
131+
->args([service('doctrine.orm.entity_manager')])
132+
// In versions earlier to Symfony 5.1 the service() function was called ref()
133+
->call('setLogger', [service('logger')])
133134
;
134135
135136
$services->set(DoctrineUserRepository::class)
@@ -247,13 +248,13 @@ the child class:
247248
248249
// appends the '@app.username_checker' argument to the parent
249250
// argument list
250-
->args([ref('app.username_checker')])
251+
->args([service('app.username_checker')])
251252
;
252253
253254
$services->set(DoctrinePostRepository::class)
254255
->parent(BaseDoctrineRepository::class)
255256
256257
# overrides the first argument
257-
->arg(0, ref('doctrine.custom_entity_manager'))
258+
->arg(0, service('doctrine.custom_entity_manager'))
258259
;
259260
};

service_container/service_decoration.rst

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -172,7 +172,8 @@ automatically changed to ``'.inner'``):
172172
$services->set(DecoratingMailer::class)
173173
->decorate(Mailer::class)
174174
// pass the old service as an argument
175-
->args([ref('.inner')]);
175+
// In versions earlier to Symfony 5.1 the service() function was called ref()
176+
->args([service('.inner')]);
176177
};
177178
178179
.. versionadded:: 5.1
@@ -242,7 +243,7 @@ automatically changed to ``'.inner'``):
242243
243244
$services->set(DecoratingMailer::class)
244245
->decorate(Mailer::class, DecoratingMailer::class.'.wooz')
245-
->args([ref(DecoratingMailer::class.'.wooz')]);
246+
->args([service(DecoratingMailer::class.'.wooz')]);
246247
};
247248
248249
Decoration Priority
@@ -303,11 +304,11 @@ the ``decoration_priority`` option. Its value is an integer that defaults to
303304
304305
$services->set(Bar::class)
305306
->decorate(Foo::class, null, 5)
306-
->args([ref('.inner')]);
307+
->args([service('.inner')]);
307308
308309
$services->set(Baz::class)
309310
->decorate(Foo::class, null, 1)
310-
->args([ref('.inner')]);
311+
->args([service('.inner')]);
311312
};
312313
313314
@@ -371,7 +372,7 @@ Three different behaviors are available:
371372
372373
$services->set(Bar::class)
373374
->decorate(Foo::class, null, 0, ContainerInterface::IGNORE_ON_INVALID_REFERENCE)
374-
->args([ref('.inner')])
375+
->args([service('.inner')])
375376
;
376377
};
377378

service_container/service_subscribers_locators.rst

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -311,9 +311,10 @@ service definition to pass a collection of services to the service locator:
311311
$services = $configurator->services();
312312
313313
$services->set('app.command_handler_locator', ServiceLocator::class)
314+
// In versions earlier to Symfony 5.1 the service() function was called ref()
314315
->args([[
315-
'App\FooCommand' => ref('app.command_handler.foo'),
316-
'App\BarCommand' => ref('app.command_handler.bar'),
316+
'App\FooCommand' => service('app.command_handler.foo'),
317+
'App\BarCommand' => service('app.command_handler.bar'),
317318
]])
318319
// if you are not using the default service autoconfiguration,
319320
// add the following tag to the service definition:
@@ -323,7 +324,7 @@ service definition to pass a collection of services to the service locator:
323324
// if the element has no key, the ID of the original service is used
324325
$services->set('app.another_command_handler_locator', ServiceLocator::class)
325326
->args([[
326-
ref('app.command_handler.baz'),
327+
service('app.command_handler.baz'),
327328
]])
328329
;
329330
};
@@ -372,7 +373,7 @@ Now you can use the service locator by injecting it in any other service:
372373
$services = $configurator->services();
373374
374375
$services->set(CommandBus::class)
375-
->args([ref('app.command_handler_locator')]);
376+
->args([service('app.command_handler_locator')]);
376377
};
377378
378379
In :doc:`compiler passes </service_container/compiler_passes>` it's recommended

0 commit comments

Comments
 (0)
0