php Zend-Validator-ValidatorChain类(方法)实例源码

下面列出了php Zend-Validator-ValidatorChain 类(方法)源码代码实例,从而了解它的用法。

作者:coolm    项目:use   
/**
  * {@inheritDoc}
  *
  * @return ValidatorInterface
  */
 public function createService(ServiceLocatorInterface $serviceLocator)
 {
     $services = $serviceLocator->getServiceLocator();
     /* @var $options ModuleOptions */
     $options = $services->get(ModuleOptions::class);
     $identity = null;
     if ($services->has($options->getAuthenticationService())) {
         /* @var $authService \Zend\Authentication\AuthenticationServiceInterface */
         $authService = $services->get($options->getAuthenticationService());
         if ($authService->hasIdentity()) {
             /* @var $identity \CmsUser\Mapping\UserInterface */
             $identity = $authService->getIdentity();
         }
     }
     $validatorChain = new ValidatorChain();
     $validatorChain->attachByName('Callback', ['messages' => [Callback::INVALID_VALUE => 'Your answer is wrong. ' . 'Please provide the correct answer'], 'callback' => function ($value, $context = []) use($identity) {
         if (isset($context['answer'])) {
             return strtolower($context['answer']) === $value;
         } elseif ($identity) {
             return $identity->getAnswer() === $value;
         }
         return false;
     }], true);
     return $validatorChain;
 }

作者:riesch    项目:techtalks_dat   
/**
  * @param array $config
  * @param ServiceLocatorInterface $serviceLocator
  * @return ValidatorChain
  */
 private function create(array $config, ServiceLocatorInterface $serviceLocator)
 {
     $validator = new ValidatorChain();
     foreach ($config as $key => $val) {
         $breakChainOnFailure = false;
         if ($key === 'required') {
             continue;
         }
         if (is_string($key) && class_exists($key)) {
             if (isset($val['break']) || is_int($key)) {
                 $breakChainOnFailure = $val['break'];
             }
             $childValidator = $this->service($key, $serviceLocator);
         } elseif (is_array($val)) {
             $childValidator = $this->create($val, $serviceLocator);
             if (!isset($val['required']) || $val['required'] !== false) {
                 $childValidator->attach(new FieldExists($key), true, 2);
             }
         } else {
             $childValidator = $this->service($val, $serviceLocator);
         }
         $validator->attach($childValidator, $breakChainOnFailure);
     }
     return $validator;
 }

作者:coolm    项目:use   
/**
  * {@inheritDoc}
  *
  * @return ValidatorInterface
  */
 public function createService(ServiceLocatorInterface $serviceLocator)
 {
     $services = $serviceLocator->getServiceLocator();
     /* @var $options InputFilterOptionsInterface */
     $options = $services->get(ModuleOptions::class);
     $userMapper = null;
     $identity = null;
     if ($services->has($options->getAuthenticationService())) {
         /* @var $authService \Zend\Authentication\AuthenticationServiceInterface */
         $authService = $services->get($options->getAuthenticationService());
         if ($authService->hasIdentity()) {
             /* @var $userMapper \CmsUser\Persistence\UserMapperInterface */
             $userMapper = $services->get('MapperManager')->get($options->getUserEntityClass());
             /* @var $identity \CmsUser\Mapping\UserInterface */
             $identity = $authService->getIdentity();
         }
     }
     $validatorChain = new ValidatorChain();
     $validatorChain->attachByName('Callback', ['messages' => [Callback::INVALID_VALUE => 'Incorrect password verification'], 'callback' => function ($value, $context = []) use($userMapper, $identity) {
         if (isset($context['password'])) {
             return $value === $context['password'];
         } elseif ($userMapper && $identity && $identity instanceof PasswordableInterface) {
             return $userMapper->getPasswordService()->verify($value, $identity->getPassword());
         }
         return false;
     }], true);
     return $validatorChain;
 }

作者:coolm    项目:authenticatio   
/**
  * {@inheritDoc}
  *
  * @return ValidatorChain
  */
 public function createService(ServiceLocatorInterface $validators)
 {
     /* @var $options InputFilterOptionsInterface */
     $options = $validators->getServiceLocator()->get(ModuleOptions::class);
     $chain = new ValidatorChain();
     $chain->attachByName('StringLength', ['min' => $options->getMinCredentialLength(), 'max' => $options->getMaxCredentialLength()], true);
     return $chain;
 }

作者:samij    项目:Deeplifec4t   
/**
  * @return ValidatorChain
  */
 protected function getTitleValidatorChain()
 {
     $stringLength = new StringLength();
     $stringLength->setMin(5);
     $validatorChain = new ValidatorChain();
     //        $validatorChain->attach(new Alnum(true));
     $validatorChain->attach($stringLength);
     return $validatorChain;
 }

作者:navassouz    项目:zf   
public function testValidatorChain()
 {
     $validatorChain = new ValidatorChain();
     $validatorChain->addValidator(new DigitsFilter());
     $validatorChain->addValidator(new Int());
     $filter = new Validator($validatorChain);
     $this->assertTrue($filter->filter(array('message' => '123')));
     $this->assertFalse($filter->filter(array('message' => 'test')));
 }

作者:coolm    项目:use   
/**
  * {@inheritDoc}
  *
  * @return ValidatorInterface
  */
 public function createService(ServiceLocatorInterface $serviceLocator)
 {
     $validatorChain = new ValidatorChain();
     $intl = new IntlDateFormatter(Locale::getDefault(), IntlDateFormatter::LONG, IntlDateFormatter::NONE);
     $date = (new DateTime('now'))->modify('-100 years');
     $validatorChain->attachByName('GreaterThan', ['messages' => [GreaterThan::NOT_GREATER_INCLUSIVE => 'The date of birth ' . 'must be not earlier than %min% inclusive'], 'messageVariables' => ['min' => ['abstractOptions' => 'fmt']], 'min' => $date->format('Y-m-d'), 'fmt' => $intl->format($date), 'inclusive' => true], true);
     $date = (new DateTime('now'))->modify('-18 years');
     $validatorChain->attachByName('LessThan', ['messages' => [LessThan::NOT_LESS_INCLUSIVE => 'The date of birth ' . 'must be not later than %max% inclusive'], 'messageVariables' => ['max' => ['abstractOptions' => 'fmt']], 'max' => $date->format('Y-m-d'), 'fmt' => $intl->format($date), 'inclusive' => true], true);
     return $validatorChain;
 }

作者:totoloui    项目:ZF2-Aut   
/**
  * Constructor.
  *
  * @param  string  $host OPTIONAL Hostname of remote connection (default: 127.0.0.1)
  * @param  integer $port OPTIONAL Port number (default: null)
  * @throws Exception\RuntimeException
  */
 public function __construct($host = '127.0.0.1', $port = null)
 {
     $this->validHost = new Validator\ValidatorChain();
     $this->validHost->attach(new Validator\Hostname(Validator\Hostname::ALLOW_ALL));
     if (!$this->validHost->isValid($host)) {
         throw new Exception\RuntimeException(implode(', ', $this->validHost->getMessages()));
     }
     $this->host = $host;
     $this->port = $port;
 }

作者:papertas    项目:papertas   
public function createInputFilter()
 {
     $inputFilter = new InputFilter\InputFilter();
     $email = new InputFilter\Input('email');
     $email->setRequired(true);
     $validatorChain = new Validator\ValidatorChain();
     $validatorChain->attach(new Validator\EmailAddress());
     $email->setValidatorChain($validatorChain);
     $inputFilter->add($email);
     return $inputFilter;
 }

作者:coolm    项目:authenticatio   
/**
  * {@inheritDoc}
  *
  * @return ValidatorChain
  */
 public function createService(ServiceLocatorInterface $validators)
 {
     /* @var $options InputFilterOptionsInterface */
     $options = $validators->getServiceLocator()->get(ModuleOptions::class);
     $chain = new ValidatorChain();
     $chain->attachByName('StringLength', ['min' => $options->getMinIdentityLength(), 'max' => $options->getMaxIdentityLength()], true);
     if ($options->getIdentityRegexPattern()) {
         $chain->attachByName('Regex', ['messages' => [Regex::NOT_MATCH => 'Incorrect identity. ' . 'Identity must contain alphanumeric characters without spaces'], 'pattern' => $options->getIdentityRegexPattern()], true);
     }
     return $chain;
 }

作者:coolm    项目:user-or   
/**
  * {@inheritDoc}
  */
 public function createService(ServiceLocatorInterface $validators)
 {
     $validatorChain = new ValidatorChain();
     $validatorChain->attachByName('Callback', ['messages' => [Callback::INVALID_VALUE => 'Termination date must be greater' . ' than the date of employment'], 'callback' => function ($value, $context = []) {
         if ($value && isset($context['since'])) {
             $filter = new DateSelectFilter();
             return new \DateTime($value) > new \DateTime($filter->filter($context['since']));
         }
         return true;
     }], true);
     return $validatorChain;
 }

作者:bravadomizzo    项目:dewdro   
public function getValidatorChain()
 {
     if (!$this->validatorChain) {
         $this->validatorChain = new ValidatorChain();
         $uploadFileValidator = new UploadFileValidator();
         $this->validatorChain->attach($uploadFileValidator);
         $mimeTypeValidator = new MimeTypeValidator();
         $mimeTypeValidator->addMimeType($this->allowedMimeTypes);
         $this->validatorChain->attach($mimeTypeValidator);
     }
     return $this->validatorChain;
 }

作者:alex-patterson-webde    项目:arp-stdli   
public function isValid($value, array $context = [])
 {
     if (!isset($context['name_of_other_field'])) {
         throw new Exception\RuntimeException(sprintf('The required \'name_of_other_field\' context value was not found in validator \'%s\'.', __CLASS__));
     }
     if (1234 === $context['name_of_other_field']) {
         $validator = new Validator\ValidatorChain();
         $validator->attach(new Validator\StringLength(['min' => 8, 'max' => 12]));
         $validator->attach(new Validator\EmailAddress());
         return $validator->isValid($value);
     }
     return true;
 }

作者:leonardovn8    项目:zf2_basic201   
/**
  * Create a new simple console route.
  *
  * @param  string                                   $route
  * @param  array                                    $constraints
  * @param  array                                    $defaults
  * @param  array                                    $aliases
  * @param  null|array|Traversable|FilterChain       $filters
  * @param  null|array|Traversable|ValidatorChain    $validators
  * @throws \Zend\Mvc\Exception\InvalidArgumentException
  * @return \Zend\Mvc\Router\Console\Simple
  */
 public function __construct($route, array $constraints = array(), array $defaults = array(), array $aliases = array(), $filters = null, $validators = null)
 {
     $this->defaults = $defaults;
     $this->constraints = $constraints;
     $this->aliases = $aliases;
     if ($filters !== null) {
         if ($filters instanceof FilterChain) {
             $this->filters = $filters;
         } elseif ($filters instanceof Traversable) {
             $this->filters = new FilterChain(array('filters' => ArrayUtils::iteratorToArray($filters, false)));
         } elseif (is_array($filters)) {
             $this->filters = new FilterChain(array('filters' => $filters));
         } else {
             throw new InvalidArgumentException('Cannot use ' . gettype($filters) . ' as filters for ' . __CLASS__);
         }
     }
     if ($validators !== null) {
         if ($validators instanceof ValidatorChain) {
             $this->validators = $validators;
         } elseif ($validators instanceof Traversable || is_array($validators)) {
             $this->validators = new ValidatorChain();
             foreach ($validators as $v) {
                 $this->validators->attach($v);
             }
         } else {
             throw new InvalidArgumentException('Cannot use ' . gettype($validators) . ' as validators for ' . __CLASS__);
         }
     }
     $this->parts = $this->parseRouteDefinition($route);
 }

作者:papertas    项目:papertas   
public function createInputFilter()
 {
     $inputFilter = new InputFilter\InputFilter();
     //username
     $username = new InputFilter\Input('email');
     $username->setRequired(true);
     $validatorChain = new Validator\ValidatorChain();
     $validatorChain->attach(new Validator\EmailAddress());
     $username->setValidatorChain($validatorChain);
     $inputFilter->add($username);
     //password
     $password = new InputFilter\Input('password');
     $password->setRequired(true);
     $inputFilter->add($password);
     return $inputFilter;
 }

作者:papertas    项目:papertas   
protected function createInputFilter()
 {
     $inputFilter = new InputFilter\InputFilter();
     // password
     $password = new InputFilter\Input('password');
     $password->setRequired(true);
     // Generate password validator chain
     $validatorPasswordChain = new Validator\ValidatorChain();
     $validatorPasswordChain->attach(new Validator\StringLength(array('min' => 6)));
     $password->setValidatorChain($validatorPasswordChain);
     $inputFilter->add($password);
     // confirmation
     $confirmation = new InputFilter\Input('confirmation');
     $confirmation->setRequired(true);
     $confirmation->setValidatorChain($validatorPasswordChain);
     $inputFilter->add($confirmation);
     return $inputFilter;
 }

作者:gridguy    项目:zor   
/**
  * Get current input filter factory
  *
  * If none provided, uses an unconfigured instance.
  *
  * @return InputFilterFactory
  */
 public function getInputFilterFactory()
 {
     $inputFilterFactory = parent::getInputFilterFactory();
     if (!$this->inputFilterFactoryDefaultsInitialized) {
         $this->inputFilterFactoryDefaultsInitialized = true;
         $dfc = $inputFilterFactory->getDefaultFilterChain();
         $dvc = $inputFilterFactory->getDefaultValidatorChain();
         if (empty($dfc)) {
             $inputFilterFactory->setDefaultFilterChain($dfc = new FilterChain());
         }
         if (empty($dvc)) {
             $inputFilterFactory->setDefaultValidatorChain($dvc = new ValidatorChain());
         }
         $initializer = array($this, 'initializeApplicationServiceLocators');
         $dfc->getPluginManager()->addInitializer($initializer, false);
         $dvc->getPluginManager()->addInitializer($initializer, false);
     }
     return $inputFilterFactory;
 }

作者:hjr    项目:zf   
/**
  * Constructor.
  *
  * @param  string  $host OPTIONAL Hostname of remote connection (default: 127.0.0.1)
  * @param  integer $port OPTIONAL Port number (default: null)
  * @throws \Zend\Mail\Protocol\Exception
  * @return void
  */
 public function __construct($host = '127.0.0.1', $port = null)
 {
     $this->_validHost = new Validator\ValidatorChain();
     $this->_validHost->addValidator(new HostnameValidator(HostnameValidator::ALLOW_ALL));
     if (!$this->_validHost->isValid($host)) {
         throw new Protocol\Exception\RuntimeException(implode(', ', $this->_validHost->getMessages()));
     }
     $this->_host = $host;
     $this->_port = $port;
 }

作者:alab100110    项目:zf   
/**
  * Constructor.
  *
  * @param  string  $host OPTIONAL Hostname of remote connection (default: 127.0.0.1)
  * @param  integer $port OPTIONAL Port number (default: null)
  * @throws \Zend\Mail\Protocol\Exception
  * @return void
  */
 public function __construct($host = '127.0.0.1', $port = null)
 {
     $this->_validHost = new Validator\ValidatorChain();
     $this->_validHost->addValidator(new HostnameValidator\Hostname(HostnameValidator\Hostname::ALLOW_ALL));
     if (!$this->_validHost->isValid($host)) {
         throw new Exception(join(', ', $this->_validHost->getMessages()));
     }
     $this->_host = $host;
     $this->_port = $port;
 }

作者:coolm    项目:use   
/**
  * {@inheritDoc}
  *
  * @return ValidatorInterface
  */
 public function createService(ServiceLocatorInterface $serviceLocator)
 {
     $services = $serviceLocator->getServiceLocator();
     /* @var $options InputFilterOptionsInterface */
     $options = $services->get(ModuleOptions::class);
     /* @var $userMapper \CmsUser\Persistence\UserMapperInterface */
     $userMapper = $services->get('MapperManager')->get($options->getUserEntityClass());
     $identityField = $services->get('FormElementManager')->get('CmsAuthenticationIdentity')->getName();
     $validatorChain = new ValidatorChain();
     $validatorChain->attachByName('Callback', ['messages' => [Callback::INVALID_VALUE => 'Your birthday is wrong. ' . 'Please provide the correct birthday'], 'callback' => function ($value, $context = []) use($userMapper, $identityField) {
         if (!empty($context[$identityField])) {
             if ($identity = $userMapper->findByIdentity($context[$identityField])) {
                 return new \DateTime($value) == $identity->getBirthday();
             }
         }
         return true;
     }], true);
     return $validatorChain;
 }


问题


面经


文章

微信
公众号

扫码关注公众号