laminas / laminas-validator

Validation classes for a wide range of domains, and the ability to chain validators to create complex validation criteria
https://docs.laminas.dev/laminas-validator/
BSD 3-Clause "New" or "Revised" License
130 stars 55 forks source link

error on documentation example code #25

Open weierophinney opened 4 years ago

weierophinney commented 4 years ago

The section "Using pre-translated validation messages" on the Zend Validator documentaion has the following example:

use Zend\I18n\Translator\Resources;
use Zend\Mvc\I18n\Translator;
use Zend\Validator\AbstractValidator;

$translator = new Zend\Mvc\I18n\Translator();
$translator->addTranslationFilePattern(
    'phpArray',
    Resources::getBasePath(),
    Resources::getPatternForValidator()
);
AbstractValidator::setDefaultTranslator($translator);

Fist Zend\Mvc\I18n\Translator(); needs an I18nTranslatorInterface and that's not documented on this example.

The another problem with this example is that it throws this Exception:

A plugin by the name "phpArray" was not found in the plugin manager Zend\I18n\Translator\LoaderPluginManager

Because the alias for Zend\I18n\Translator\Loader\PhpArray now is "phparray" not "phpArray"


Originally posted by @igormx at https://github.com/zendframework/zend-validator/issues/106

weierophinney commented 4 years ago

I was going to report the same. I can get past line 5 replacing it with: $translator = new Zend\Mvc\I18n\Translator(new Zend\I18n\Translator\Translator());

While this allows the example to run, it does not change the language. And indeed, the example never specifies German.

Yet another problem: the __call() function of Translator (surely used for addTranslationFilePattern()) is marked as deprecated.


Originally posted by @Chealer at https://github.com/zendframework/zend-validator/issues/106#issuecomment-240204583

weierophinney commented 4 years ago

I resolve my issue exactly in the same way than you.


Originally posted by @igormx at https://github.com/zendframework/zend-validator/issues/106#issuecomment-242848382

weierophinney commented 4 years ago

phpArray is re-added to zend-i18n src/Translator/LoaderPluginManager.php https://github.com/zendframework/zend-i18n/pull/56


Originally posted by @samsonasik at https://github.com/zendframework/zend-validator/issues/106#issuecomment-303998030