injectTranslator is called to early
michalbundyra opened this issue · 3 comments
In Line 141 of /src/ValidatorPluginManager.php a new Initializer is added by the line:
$this->addInitializer([$this, 'injectTranslator']);
after parent::__construct() is called. Which means, that on creation of a new validator the method `injectTranslator()' is called before the closure:
$this->addInitializer(function ($instance) use ($self) {
if ($instance instanceof ServiceLocatorAwareInterface) {
$instance->setServiceLocator($self);
}
});
of the AbstractPluginManager is called.
But since the injectTranslator
method needs the serviceLocator and the serviceLocator isn't injected at this point of time, the result of $this->getServiceLocator()
in injectTranslator
will always be null. And that's why there will be never a translator injected.
Originally posted by @jscssphtml at zendframework/zend-validator#13
But since the
injectTranslator
method needs the serviceLocator and the serviceLocator isn't injected at this point of time, the result of$this->getServiceLocator()
ininjectTranslator
will always be null. And that's why there will be never a translator injected.
The code you are referring to adds initializers, it does not execute them at that point.
This is what happens:
Zend\ServiceManager\AbstractPluginManager::__construct
is called and adds an initializer which sets theServiceLocator
(so it does not run that code at that point)- after that
Zend\Validator\ValidatorPluginManager
adds theinjectTranslator
initializer on line 141
The initializers are executed in the same order they are added and thus the ServiceLocator
is set before the translator is injected.
Originally posted by @Martin-P at zendframework/zend-validator#13 (comment)
@jscssphtml Is this (still) an issue? If so could you provide a simple reproducing test case to demonstrate it?
Originally posted by @adamlundrigan at zendframework/zend-validator#13 (comment)
Unfortunately, there is no feedback to reproduce the problem. Therefore, the issue is closed at this point.