当前位置: 首页>>代码示例>>PHP>>正文


PHP Validator\ValidatorChain类代码示例

本文整理汇总了PHP中Zend\Validator\ValidatorChain的典型用法代码示例。如果您正苦于以下问题:PHP ValidatorChain类的具体用法?PHP ValidatorChain怎么用?PHP ValidatorChain使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


在下文中一共展示了ValidatorChain类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: createService

 /**
  * {@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;
 }
开发者ID:coolms,项目名称:user,代码行数:30,代码来源:AnswerVerifyValidatorFactory.php

示例2: create

 /**
  * @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;
 }
开发者ID:rieschl,项目名称:techtalks_data,代码行数:30,代码来源:ValidatorFactory.php

示例3: createService

 /**
  * {@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;
 }
开发者ID:coolms,项目名称:user,代码行数:33,代码来源:PasswordVerifyValidatorFactory.php

示例4: createService

 /**
  * {@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;
 }
开发者ID:coolms,项目名称:authentication,代码行数:13,代码来源:CredentialValidatorFactory.php

示例5: getTitleValidatorChain

 /**
  * @return ValidatorChain
  */
 protected function getTitleValidatorChain()
 {
     $stringLength = new StringLength();
     $stringLength->setMin(5);
     $validatorChain = new ValidatorChain();
     //        $validatorChain->attach(new Alnum(true));
     $validatorChain->attach($stringLength);
     return $validatorChain;
 }
开发者ID:samija,项目名称:Deeplifec4tk,代码行数:12,代码来源:AddPost.php

示例6: testValidatorChain

 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')));
 }
开发者ID:navassouza,项目名称:zf2,代码行数:9,代码来源:ValidatorTest.php

示例7: createService

 /**
  * {@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;
 }
开发者ID:coolms,项目名称:user,代码行数:15,代码来源:BirthdayValidatorFactory.php

示例8: __construct

 /**
  * 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;
 }
开发者ID:totolouis,项目名称:ZF2-Auth,代码行数:17,代码来源:AbstractProtocol.php

示例9: createInputFilter

 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;
 }
开发者ID:papertask,项目名称:papertask,代码行数:11,代码来源:ForgotPasswordForm.php

示例10: createService

 /**
  * {@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;
 }
开发者ID:coolms,项目名称:authentication,代码行数:16,代码来源:IdentityValidatorFactory.php

示例11: createService

 /**
  * {@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;
 }
开发者ID:coolms,项目名称:user-org,代码行数:15,代码来源:TerminationDateValidatorFactory.php

示例12: getValidatorChain

 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;
 }
开发者ID:bravadomizzou,项目名称:dewdrop,代码行数:12,代码来源:FileHandler.php

示例13: isValid

 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;
 }
开发者ID:alex-patterson-webdev,项目名称:arp-stdlib,代码行数:13,代码来源:MyCustomValidator.php

示例14: __construct

 /**
  * 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);
 }
开发者ID:leonardovn86,项目名称:zf2_basic2013,代码行数:42,代码来源:Simple.php

示例15: createInputFilter

 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;
 }
开发者ID:papertask,项目名称:papertask,代码行数:16,代码来源:LoginForm.php


注:本文中的Zend\Validator\ValidatorChain类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。