/**
  * {@inheritDoc}
  *
  * @return ValidatorInterface
  */
 public function createService(ServiceLocatorInterface $serviceLocator)
 {
     $services = $serviceLocator->getServiceLocator();
     /* @var $options InputFilterOptionsInterface */
     $options = $services->get(ModuleOptions::class);
     $validator = new ValidatorChain();
     $validator->setPluginManager($serviceLocator);
     $validator->attachByName('StringLength', ['messages' => [StringLength::TOO_SHORT => 'Email address must be at least %min% characters long', StringLength::TOO_LONG => 'Email address must not be more than %max% characters'], 'encoding' => 'UTF-8', 'min' => 6, 'max' => 60], true);
     $validator->attachByName('EmailAddress', [], true);
     $validator->attachByName('CmsUserNoEmailExists', [], true);
     return $validator;
 }
Esempio n. 2
0
 /**
  * {@inheritDoc}
  *
  * @return ValidatorInterface
  */
 public function createService(ServiceLocatorInterface $serviceLocator)
 {
     $services = $serviceLocator->getServiceLocator();
     /* @var $options InputFilterOptionsInterface */
     $options = $services->get(ModuleOptions::class);
     $validator = new ValidatorChain();
     $validator->setPluginManager($serviceLocator);
     $validator->attachByName('StringLength', ['messages' => [StringLength::TOO_SHORT => 'The username must be at least %min% characters long', StringLength::TOO_LONG => 'The username must not be more than %max% characters'], 'encoding' => 'UTF-8', 'min' => 5, 'max' => 30], true);
     $validator->attachByName('Regex', ['messages' => [Regex::NOT_MATCH => 'Incorrect username. ' . 'Username must contain alphanumeric characters without spaces'], 'pattern' => $options->getUsernameRegexPattern()], true);
     $validator->attachByName('CmsUserNoUsernameExists', [], true);
     return $validator;
 }
Esempio n. 3
0
 public function testFactoryInjectsComposedFilterAndValidatorChainsIntoInputObjectsWhenCreatingNewInputFilterObjects()
 {
     $factory = new Factory();
     $filterPlugins = new Filter\FilterPluginManager();
     $validatorPlugins = new Validator\ValidatorPluginManager();
     $filterChain = new Filter\FilterChain();
     $validatorChain = new Validator\ValidatorChain();
     $filterChain->setPluginManager($filterPlugins);
     $validatorChain->setPluginManager($validatorPlugins);
     $factory->setDefaultFilterChain($filterChain);
     $factory->setDefaultValidatorChain($validatorChain);
     $inputFilter = $factory->createInputFilter(array('foo' => array('name' => 'foo')));
     $this->assertInstanceOf('Zend\\InputFilter\\InputFilterInterface', $inputFilter);
     $this->assertEquals(1, count($inputFilter));
     $input = $inputFilter->get('foo');
     $this->assertInstanceOf('Zend\\InputFilter\\InputInterface', $input);
     $inputFilterChain = $input->getFilterChain();
     $inputValidatorChain = $input->getValidatorChain();
     $this->assertSame($filterPlugins, $inputFilterChain->getPluginManager());
     $this->assertSame($validatorPlugins, $inputValidatorChain->getPluginManager());
 }
Esempio n. 4
0
 /**
  * @return ValidatorChain
  */
 public function getValidatorChain()
 {
     if (!$this->validatorChain) {
         $validator = new ValidatorChain();
         $inputs = $this->getServiceLocator();
         if ($inputs instanceof AbstractPluginManager) {
             $services = $inputs->getServiceLocator();
             if ($services instanceof ServiceLocatorInterface && $services->has('ValidatorManager')) {
                 $validator->setPluginManager($services->get('ValidatorManager'));
             }
         }
         $this->setValidatorChain($validator);
     }
     return $this->validatorChain;
 }