Skip to content

Commit 25231c5

Browse files
committed
"public: false" in service configuration file doesn't exist anymore
And is the default configuration
1 parent 667c179 commit 25231c5

12 files changed

+38
-68
lines changed

frontend/custom_version_strategy.rst

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,6 @@ After creating the strategy PHP class, register it as a Symfony service.
118118
arguments:
119119
- "%kernel.project_dir%/busters.json"
120120
- "%%s?version=%%s"
121-
public: false
122121
123122
.. code-block:: xml
124123
@@ -130,7 +129,7 @@ After creating the strategy PHP class, register it as a Symfony service.
130129
https://symfony.com/schema/dic/services/services-1.0.xsd"
131130
>
132131
<services>
133-
<service id="App\Asset\VersionStrategy\GulpBusterVersionStrategy" public="false">
132+
<service id="App\Asset\VersionStrategy\GulpBusterVersionStrategy">
134133
<argument>%kernel.project_dir%/busters.json</argument>
135134
<argument>%%s?version=%%s</argument>
136135
</service>
@@ -149,7 +148,7 @@ After creating the strategy PHP class, register it as a Symfony service.
149148
'%kernel.project_dir%/busters.json',
150149
'%%s?version=%%s',
151150
]
152-
)->setPublic(false);
151+
);
153152
154153
Finally, enable the new asset versioning for all the application assets or just
155154
for some :ref:`asset package <reference-framework-assets-packages>` thanks to

profiler/data_collector.rst

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -239,7 +239,6 @@ to specify a tag that contains the template:
239239
id: 'app.request_collector'
240240
# optional priority
241241
# priority: 300
242-
public: false
243242
244243
.. code-block:: xml
245244
@@ -251,7 +250,7 @@ to specify a tag that contains the template:
251250
https://symfony.com/schema/dic/services/services-1.0.xsd">
252251
253252
<services>
254-
<service id="App\DataCollector\RequestCollector" public="false">
253+
<service id="App\DataCollector\RequestCollector">
255254
<!-- priority="300" -->
256255
<tag name="data_collector"
257256
template="data_collector/template.html.twig"
@@ -268,7 +267,6 @@ to specify a tag that contains the template:
268267
269268
$container
270269
->autowire(RequestCollector::class)
271-
->setPublic(false)
272270
->addTag('data_collector', [
273271
'template' => 'data_collector/template.html.twig',
274272
'id' => 'app.request_collector',

reference/dic_tags.rst

Lines changed: 12 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -64,13 +64,10 @@ services:
6464
services:
6565
app.mysql_lock:
6666
class: App\Lock\MysqlLock
67-
public: false
6867
app.postgresql_lock:
6968
class: App\Lock\PostgresqlLock
70-
public: false
7169
app.sqlite_lock:
7270
class: App\Lock\SqliteLock
73-
public: false
7471
7572
.. code-block:: xml
7673
@@ -81,11 +78,11 @@ services:
8178
https://symfony.com/schema/dic/services/services-1.0.xsd">
8279
8380
<services>
84-
<service id="app.mysql_lock" public="false"
81+
<service id="app.mysql_lock"
8582
class="App\Lock\MysqlLock"/>
86-
<service id="app.postgresql_lock" public="false"
83+
<service id="app.postgresql_lock"
8784
class="App\Lock\PostgresqlLock"/>
88-
<service id="app.sqlite_lock" public="false"
85+
<service id="app.sqlite_lock"
8986
class="App\Lock\SqliteLock"/>
9087
</services>
9188
</container>
@@ -96,9 +93,9 @@ services:
9693
use App\Lock\PostgresqlLock;
9794
use App\Lock\SqliteLock;
9895
99-
$container->register('app.mysql_lock', MysqlLock::class)->setPublic(false);
100-
$container->register('app.postgresql_lock', PostgresqlLock::class)->setPublic(false);
101-
$container->register('app.sqlite_lock', SqliteLock::class)->setPublic(false);
96+
$container->register('app.mysql_lock', MysqlLock::class);
97+
$container->register('app.postgresql_lock', PostgresqlLock::class);
98+
$container->register('app.sqlite_lock', SqliteLock::class);
10299
103100
Instead of dealing with these three services, your application needs a generic
104101
``app.lock`` service that will be an alias to one of these services, depending on
@@ -132,11 +129,11 @@ the generic ``app.lock`` service can be defined as follows:
132129
https://symfony.com/schema/dic/services/services-1.0.xsd">
133130
134131
<services>
135-
<service id="app.mysql_lock" public="false"
132+
<service id="app.mysql_lock"
136133
class="App\Lock\MysqlLock"/>
137-
<service id="app.postgresql_lock" public="false"
134+
<service id="app.postgresql_lock"
138135
class="App\Lock\PostgresqlLock"/>
139-
<service id="app.sqlite_lock" public="false"
136+
<service id="app.sqlite_lock"
140137
class="App\Lock\SqliteLock"/>
141138
142139
<service id="app.lock">
@@ -151,9 +148,9 @@ the generic ``app.lock`` service can be defined as follows:
151148
use App\Lock\PostgresqlLock;
152149
use App\Lock\SqliteLock;
153150
154-
$container->register('app.mysql_lock', MysqlLock::class)->setPublic(false);
155-
$container->register('app.postgresql_lock', PostgresqlLock::class)->setPublic(false);
156-
$container->register('app.sqlite_lock', SqliteLock::class)->setPublic(false);
151+
$container->register('app.mysql_lock', MysqlLock::class);
152+
$container->register('app.postgresql_lock', PostgresqlLock::class);
153+
$container->register('app.sqlite_lock', SqliteLock::class);
157154
158155
$container->register('app.lock')
159156
->addTag('auto_alias', ['format' => 'app.%database_type%_lock']);

security/custom_authentication_provider.rst

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -396,11 +396,9 @@ to service ids that may not exist yet: ``App\Security\Authentication\Provider\Ws
396396
App\Security\Authentication\Provider\WsseProvider:
397397
arguments:
398398
$cachePool: '@cache.app'
399-
public: false
400399
401400
App\Security\Firewall\WsseListener:
402401
arguments: ['@security.token_storage', '@security.authentication.manager']
403-
public: false
404402
405403
.. code-block:: xml
406404
@@ -411,15 +409,11 @@ to service ids that may not exist yet: ``App\Security\Authentication\Provider\Ws
411409
xsi:schemaLocation="http://symfony.com/schema/dic/services https://symfony.com/schema/dic/services/services-1.0.xsd">
412410
413411
<services>
414-
<service id="App\Security\Authentication\Provider\WsseProvider"
415-
public="false"
416-
>
412+
<service id="App\Security\Authentication\Provider\WsseProvider">
417413
<argument key="$cachePool" type="service" id="cache.app"></argument>
418414
</service>
419415
420-
<service id="App\Security\Firewall\WsseListener"
421-
public="false"
422-
>
416+
<service id="App\Security\Firewall\WsseListener">
423417
<argument type="service" id="security.token_storage"/>
424418
<argument type="service" id="security.authentication.manager"/>
425419
</service>
@@ -435,14 +429,14 @@ to service ids that may not exist yet: ``App\Security\Authentication\Provider\Ws
435429
436430
$container->register(WsseProvider::class)
437431
->setArgument('$cachePool', new Reference('cache.app'))
438-
->setPublic(false);
432+
;
439433
440434
$container->register(WsseListener::class)
441435
->setArguments([
442436
new Reference('security.token_storage'),
443437
new Reference('security.authentication.manager'),
444438
])
445-
->setPublic(false);
439+
;
446440
447441
Now that your services are defined, tell your security context about your
448442
factory in the kernel::

serializer.rst

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,6 @@ properties and setters (``setXxx()``) to change properties:
9393
services:
9494
get_set_method_normalizer:
9595
class: Symfony\Component\Serializer\Normalizer\GetSetMethodNormalizer
96-
public: false
9796
tags: [serializer.normalizer]
9897
9998
.. code-block:: xml
@@ -106,7 +105,7 @@ properties and setters (``setXxx()``) to change properties:
106105
https://symfony.com/schema/dic/services/services-1.0.xsd">
107106
108107
<services>
109-
<service id="get_set_method_normalizer" class="Symfony\Component\Serializer\Normalizer\GetSetMethodNormalizer" public="false">
108+
<service id="get_set_method_normalizer" class="Symfony\Component\Serializer\Normalizer\GetSetMethodNormalizer">
110109
<tag name="serializer.normalizer"/>
111110
</service>
112111
</services>
@@ -118,7 +117,6 @@ properties and setters (``setXxx()``) to change properties:
118117
use Symfony\Component\Serializer\Normalizer\GetSetMethodNormalizer;
119118
120119
$container->register('get_set_method_normalizer', GetSetMethodNormalizer::class)
121-
->setPublic(false)
122120
->addTag('serializer.normalizer')
123121
;
124122

service_container.rst

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -154,9 +154,6 @@ each time you ask for it.
154154
_defaults:
155155
autowire: true # Automatically injects dependencies in your services.
156156
autoconfigure: true # Automatically registers your services as commands, event subscribers, etc.
157-
public: false # Allows optimizing the container by removing unused services; this also means
158-
# fetching services directly from the container via $container->get() won't work.
159-
# The best practice is to be explicit about your dependencies anyway.
160157
161158
# makes classes in src/ available to be used as services
162159
# this creates a service per class whose id is the fully-qualified class name
@@ -177,7 +174,7 @@ each time you ask for it.
177174
178175
<services>
179176
<!-- Default configuration for services in *this* file -->
180-
<defaults autowire="true" autoconfigure="true" public="false"/>
177+
<defaults autowire="true" autoconfigure="true"/>
181178
182179
<prototype namespace="App\" resource="../src/*" exclude="../src/{DependencyInjection,Entity,Migrations,Tests,Kernel.php}"/>
183180
</services>
@@ -815,8 +812,7 @@ loss, enable the compiler pass in your application.
815812
Public Versus Private Services
816813
------------------------------
817814

818-
Thanks to the ``_defaults`` section in ``services.yaml``, every service defined in
819-
this file is ``public: false`` by default.
815+
From Symfony 4.0, every service defined is private by default.
820816

821817
What does this mean? When a service **is** public, you can access it directly
822818
from the container object, which is accessible from any controller that extends
@@ -956,9 +952,7 @@ them will not cause the container to be rebuilt.
956952
.. note::
957953

958954
Wait, does this mean that *every* class in ``src/`` is registered as
959-
a service? Even model classes? Actually, no. As long as you have
960-
``public: false`` under your ``_defaults`` key (or you can add it under the
961-
specific import), all the imported services are *private*. Thanks to this, all
955+
a service? Even model classes? Actually, no. As long as you keep your imported services as :ref:`private <container-public>`, all
962956
classes in ``src/`` that are *not* explicitly used as services are
963957
automatically removed from the final container. In reality, the import
964958
means that all classes are "available to be *used* as services" without needing

service_container/alias_private.rst

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,7 @@ And in this case, those services do *not* need to be public.
2323

2424
So unless you *specifically* need to access a service directly from the container
2525
via ``$container->get()``, the best-practice is to make your services *private*.
26-
In fact, the :ref:`default services.yaml configuration <container-public>` configures
27-
all services to be private by default.
26+
In fact, All services are :ref:`private <container-public>` by default.
2827

2928
You can also control the ``public`` option on a service-by-service basis:
3029

@@ -37,7 +36,7 @@ You can also control the ``public`` option on a service-by-service basis:
3736
# ...
3837
3938
App\Service\Foo:
40-
public: false
39+
public: true
4140
4241
.. code-block:: xml
4342
@@ -48,7 +47,7 @@ You can also control the ``public`` option on a service-by-service basis:
4847
xsi:schemaLocation="http://symfony.com/schema/dic/services https://symfony.com/schema/dic/services/services-1.0.xsd">
4948
5049
<services>
51-
<service id="App\Service\Foo" public="false"/>
50+
<service id="App\Service\Foo" public="true"/>
5251
</services>
5352
</container>
5453
@@ -63,7 +62,7 @@ You can also control the ``public`` option on a service-by-service basis:
6362
$services = $configurator->services();
6463
6564
$services->set(Foo::class)
66-
->private();
65+
->public();
6766
};
6867
6968
.. _services-why-private:

service_container/autowiring.rst

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,6 @@ both services:
7373
_defaults:
7474
autowire: true
7575
autoconfigure: true
76-
public: false
7776
# ...
7877
7978
App\Service\TwitterClient:
@@ -92,7 +91,7 @@ both services:
9291
xsi:schemaLocation="http://symfony.com/schema/dic/services https://symfony.com/schema/dic/services/services-1.0.xsd">
9392
9493
<services>
95-
<defaults autowire="true" autoconfigure="true" public="false"/>
94+
<defaults autowire="true" autoconfigure="true"/>
9695
<!-- ... -->
9796
9897
<!-- autowire is redundant thanks to defaults, but value is overridable on each service -->

service_container/import.rst

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,6 @@ a relative or absolute path to the imported file:
8585
_defaults:
8686
autowire: true
8787
autoconfigure: true
88-
public: false
8988
9089
App\:
9190
resource: '../src/*'
@@ -105,7 +104,7 @@ a relative or absolute path to the imported file:
105104
<imports>
106105
<import resource="services/mailer.xml"/>
107106
108-
<defaults autowire="true" autoconfigure="true" public="false"/>
107+
<defaults autowire="true" autoconfigure="true"/>
109108
110109
<prototype namespace="App\" resource="../src/*"
111110
exclude="../src/{DependencyInjection,Entity,Migrations,Tests,Kernel.php}"/>
@@ -126,7 +125,6 @@ a relative or absolute path to the imported file:
126125
->defaults()
127126
->autowire()
128127
->autoconfigure()
129-
->private()
130128
;
131129
132130
$services->load('App\\', '../src/*')

service_container/parent_services.rst

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -181,8 +181,8 @@ the child class:
181181
App\Repository\DoctrineUserRepository:
182182
parent: App\Repository\BaseDoctrineRepository
183183
184-
# overrides the public setting of the parent service
185-
public: false
184+
# overrides the private setting of the parent service
185+
public: true
186186
187187
# appends the '@app.username_checker' argument to the parent
188188
# argument list
@@ -207,10 +207,10 @@ the child class:
207207
<services>
208208
<!-- ... -->
209209
210-
<!-- overrides the public setting of the parent service -->
210+
<!-- overrides the private setting of the parent service -->
211211
<service id="App\Repository\DoctrineUserRepository"
212212
parent="App\Repository\BaseDoctrineRepository"
213-
public="false"
213+
public="true"
214214
>
215215
<!-- appends the '@app.username_checker' argument to the parent
216216
argument list -->
@@ -248,8 +248,8 @@ the child class:
248248
$services->set(DoctrineUserRepository::class)
249249
->parent(BaseDoctrineRepository::class)
250250
251-
// overrides the public setting of the parent service
252-
->private()
251+
// overrides the private setting of the parent service
252+
->public()
253253
254254
// appends the '@app.username_checker' argument to the parent
255255
// argument list

service_container/service_decoration.rst

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -254,13 +254,11 @@ the ``decoration_priority`` option. Its value is an integer that defaults to
254254
Foo: ~
255255
256256
Bar:
257-
public: false
258257
decorates: Foo
259258
decoration_priority: 5
260259
arguments: ['@Bar.inner']
261260
262261
Baz:
263-
public: false
264262
decorates: Foo
265263
decoration_priority: 1
266264
arguments: ['@Baz.inner']
@@ -277,11 +275,11 @@ the ``decoration_priority`` option. Its value is an integer that defaults to
277275
<services>
278276
<service id="Foo"/>
279277
280-
<service id="Bar" decorates="Foo" decoration-priority="5" public="false">
278+
<service id="Bar" decorates="Foo" decoration-priority="5">
281279
<argument type="service" id="Bar.inner"/>
282280
</service>
283281
284-
<service id="Baz" decorates="Foo" decoration-priority="1" public="false">
282+
<service id="Baz" decorates="Foo" decoration-priority="1">
285283
<argument type="service" id="Baz.inner"/>
286284
</service>
287285
</services>
@@ -298,12 +296,10 @@ the ``decoration_priority`` option. Its value is an integer that defaults to
298296
$services->set(Foo::class);
299297
300298
$services->set(Bar::class)
301-
->private()
302299
->decorate(Foo::class, null, 5)
303300
->args([ref(Bar::class.'.inner')]);
304301
305302
$services->set(Baz::class)
306-
->private()
307303
->decorate(Foo::class, null, 1)
308304
->args([ref(Baz::class.'.inner')]);
309305
};

0 commit comments

Comments
 (0)