Deny public use of the service

In a larger application, I have many services. Using Symfony 2.x, we have most of the public services and use them in controllers:

$container->get('service.id');

Transition to Symfony 3.4 / 4 I would like to refuse public use of services. Since many customers use the service directly, I have to keep them open.

But I would like to mention the public use of the service is "out of date."

I already know how to discount service definitions in Symfony ( http://symfony.com/blog/new-in-symfony-2-8-deprecated-service-definitions ).

Is it possible to somehow refuse public use ?

+4
source share
1 answer

"wanna-be-private", private true .

yaml: public: true, private: true
php: $definition->setPublic(true)->setPrivate(true);

, , public: false .

+1

Source: https://habr.com/ru/post/1690787/


All Articles