zendframework / zend-validator

Validator component from Zend Framework
BSD 3-Clause "New" or "Revised" License
181 stars 136 forks source link

injectTranslator is called to early #13

Open jscssphtml opened 9 years ago

jscssphtml commented 9 years ago

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.

Martin-P commented 9 years ago

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.

The code you are referring to adds initializers, it does not execute them at that point. This is what happens:

The initializers are executed in the same order they are added and thus the ServiceLocator is set before the translator is injected.

adamlundrigan commented 7 years ago

@jscssphtml Is this (still) an issue? If so could you provide a simple reproducing test case to demonstrate it?

michalbundyra commented 4 years ago

This repository has been closed and moved to laminas/laminas-validator; a new issue has been opened at https://github.com/laminas/laminas-validator/issues/47.