Hello Cristian, It looks like your validator is being instantiated as an invokable. Bear in mind that usually plugin managers automatically instantiate invokables via a new statement with no constructor arguments. This means that your factory is not being correctly registered, so the plugin manager can't find your validator service and tries to automatically add it as an invokable.
You have to register the factory in the ValidatorPluginManager. You can do that by implementing the Zend\ModuleManager\ValidatorProvider interface in your module. This also entails that the service locator parameter of the factory will not be the root ServiceManager, but the ValidatorPluginManager instead, so you will have to invoke 'getServiceLocator()' on it to grab the root one. Cheers Il giorno mar 15 set 2015 alle ore 20:39 Cristian Bichis <[email protected]> ha scritto: > Hi, > > I am trying to use > > DoctrineModule\Validator\UniqueObject > > as validator within a zf2 form with annotations: > > /** > * @var string > * > * @Annotation\Type("email") > * @Annotation\Required(true) > * @Annotation\Filter({"name":"Zend\Filter\StringTrim"}) > * @Annotation\Filter({"name":"Zend\Filter\StripTags"}) > * @Annotation\Validator({"name":"Zend\Validator\StringLength", > "options":{"min":6, "max":128, "encoding":"UTF-8"}}) > * > @Annotation\Validator({"name":"DoctrineModule\Validator\UniqueObject"}) > * @Annotation\Options({"label":"Email", "column-size":"sm-10", > "label_attributes":{"class":"col-sm-2"}}) > * @Annotation\Flags({"priority": 93}) > * > * @ORM\Column(name="email", type="string", length=128, > nullable=false) > */ > protected $email; > > > Because I need to inject object_repository and object_manager I tried to > register a factory: > > 'factories' => array( > 'DoctrineModule\Validator\UniqueObject' => function ($sm){ > $uniqueObject = new > DoctrineModule\Validator\UniqueObject(array( > 'fields' => 'email', > 'object_repository' => > $sm->get('Doctrine\ORM\EntityManager')->getRepository('Crm\Entity\User'), > 'object_manager' => > $sm->get('Doctrine\ORM\EntityManager'), > )); > return $uniqueObject; > } > ) > > I tried under different configs: > Module getValidatorConfig > Module getFormElementConfig > or under > 'form_elements' > 'validators' > etc > > No luck... > > I am getting the: > PHP Catchable fatal error: Argument 1 passed to > DoctrineModule\\Validator\\UniqueObject::__construct() must be of the > type array, none given, called in > > /home/www/app/vendor/zendframework/zend-servicemanager/src/AbstractPluginManager.php > on line 207 and defined in > > /home/www/app/vendor/doctrine/doctrine-module/src/DoctrineModule/Validator/UniqueObject.php > on line 66 > > > Any clue where to register this ? > > Cristian > > -- > List: [email protected] > Info: http://framework.zend.com/archives > Unsubscribe: [email protected] > > >
