Contributed by
Hugo Hamon
in #19146.
Private services have been supported in the Symfony Service Container since
day one. By default all services are public, but setting the public
option
to false
will turn them into private services:
1 2 3 4 | services:
app.manager.user:
class: AppBundle\Manager\User
public: false
|
Intuitively, you may think that private services are no longer accessible from the container. However, their behavior is a bit tricky:
$container->get('...')
.This last behaviour is counterintuitive, so we decided to improve private services in Symfony 3.2. From now on, a private service always behaves like you expect:
Container::set()
method
is no longer supported;Container::has()
will always return false
;Container::get()
method no longer
returns the service.The next step, which may be completed before Symfony 3.2 release, will be to
randomize the id
of the private services, making it impossible for
applications to get those services circumventing the restrictions imposed by
Symfony.
What a Symfony developer should know about the framework: News, Jobs, Tweets, Events, Videos,...