Answer the question
In order to leave comments, you need to log in
How to properly replace ServiceLocator in ZF3?
Good day!
When upgrading from ZF2 to ZF3, a ServiceLocatorAware deprecation error appears, since I use ServiceLocator in the controller, in services. Here is one example of solving this problem - to make a factory and specify dependencies in it. Everything seems to be logical.
// Класс фабрики
class IndexControllerFactory implements FactoryInterface
{
public function __invoke(ContainerInterface $container,
$requestedName, array $options = null)
{
// Извлечь экземпляр сервиса CurrencyConverter из менеджера сервисов.
$currencyConverter = $container->get(CurrencyConverter::class);
// Создать экземпляр контроллера и передать сервис в его конструктор.
return new IndexController($currencyConverter);
}
Answer the question
In order to leave comments, you need to log in
if the controller has about 10 dependencies? All to push in the designer?Separate classes and dependencies. Otherwise, slide down to the magentoo level.
To what size can a constructor grow?1-3 external services, except for technical ones (like loggers, transfers, etc.).
how to use it in big projectsSRP.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question