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


PHP Validation\Validator类代码示例

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


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

示例1: setValidationRules

 protected function setValidationRules($validator)
 {
     $required = new Validator();
     $required->notEmpty();
     $validator->attribute('name', $required);
     $validator->attribute('content', $required);
 }
开发者ID:rikniitt,项目名称:legacy-php-boilerplate,代码行数:7,代码来源:Todo.php

示例2: charsInMemory

 /**
  * Returns the number of characters in memory after parsing given string.
  * @param string $string
  * @return int
  * @throws ParseException
  */
 public static function charsInMemory($string)
 {
     if (!Validator::stringType()->regex('/".*"/')->validate($string)) {
         throw new ParseException('String must be surrounded by double quotes (")');
     }
     return preg_match_all("/(\\\\\\\\|\\\\\"|\\\\x[[:xdigit:]]{2}|.)/", substr($string, 1, strlen($string) - 2));
 }
开发者ID:hamdrew,项目名称:adventofcode,代码行数:13,代码来源:StringMemoryCalculator.php

示例3: __construct

 public function __construct(Client $client, $key)
 {
     $this->client = $client;
     $this->key = $key;
     $baseUrl = $this->client->getConfig('base_uri');
     Validator::notEmpty()->url()->endsWith('/')->setName("URL for NewRelic's Insights API must be valid and have a trailing slash")->assert($baseUrl);
 }
开发者ID:easytaxibr,项目名称:newrelic,代码行数:7,代码来源:Insights.php

示例4: __construct

 /**
  * Validator constructor.
  * @param array $rules Array where each key corresponds to one attribute of the model and the value is a list of
  *                     validation rules supported by Respect\Validation separated by the pipe ("|") character.
  */
 public function __construct(array $rules)
 {
     foreach ($rules as $field => $rule) {
         $this->addAttribute($field, $rule);
     }
     parent::__construct();
 }
开发者ID:gurpreetatwal,项目名称:Skeleton-API,代码行数:12,代码来源:Validator.php

示例5: preprocessValue

 protected function preprocessValue(&$uid)
 {
     if (!Validator::int($uid)) {
         throw new InvalidArgumentException('uid', 'type_invalid');
     }
     $uid = (int) $uid;
 }
开发者ID:Tanklong,项目名称:openvj,代码行数:7,代码来源:UserUidResolver.php

示例6: validate

 public function validate($data)
 {
     $validator = V::key('name', V::string()->length(0, 100), true)->key('email', V::email()->length(0, 200), true)->key('password', V::string()->length(0, 100), true);
     try {
         $validator->assert($data);
         switch ($data['userable_type']) {
             case 'Designer':
                 $this->designerCreationValidator->validate($data);
                 $data['userable_type'] = DesignerModel::class;
                 break;
             case 'Administrator':
                 $this->adminCreationValidator->validate($data);
                 $data['userable_type'] = AdministratorModel::class;
                 break;
             case 'Buyer':
                 $this->buyerCreationValidator->validate($data);
                 $data['userable_type'] = BuyerModel::class;
                 break;
             default:
                 break;
         }
     } catch (AbstractNestedException $e) {
         $errors = $e->findMessages(['email', 'length', 'in']);
         throw new ValidationException('Could not create user.', $errors);
     }
     return true;
 }
开发者ID:HOFB,项目名称:HOFB,代码行数:27,代码来源:UserCreationValidator.php

示例7: index

 public function index($params)
 {
     Validator::notEmpty()->setName('name')->check($params['name']);
     Validator::notEmpty()->setName('password')->check($params['password']);
     $levels = Config::loadData('level');
     $this->render('index.php', ['name' => $params['name']]);
 }
开发者ID:sunpaolo,项目名称:slim3Demo,代码行数:7,代码来源:IndexController.php

示例8: __construct

 /**
  * @param string $category
  * @param string|null $subCategory
  * @throws InvalidArgumentException
  * @throws UserException
  */
 public function __construct($category, $subCategory = null)
 {
     if (!is_string($category)) {
         throw new InvalidArgumentException('category', 'type_invalid');
     }
     if (!mb_check_encoding($category, 'UTF-8')) {
         throw new InvalidArgumentException('category', 'encoding_invalid');
     }
     if (!Validator::length(VJ::TAG_MIN, VJ::TAG_MAX)->validate($category)) {
         throw new UserException('Problem.Tag.invalid_length');
     }
     $keyword = KeywordFilter::isContainGeneric($category);
     if ($keyword !== false) {
         throw new UserException('Problem.Tag.name_forbid', ['keyword' => $keyword]);
     }
     if (!is_string($subCategory)) {
         throw new InvalidArgumentException('subCategory', 'type_invalid');
     }
     if (!mb_check_encoding($subCategory, 'UTF-8')) {
         throw new InvalidArgumentException('subCategory', 'encoding_invalid');
     }
     if (!Validator::length(VJ::TAG_MIN, VJ::TAG_MAX)->validate($subCategory)) {
         throw new UserException('Problem.Tag.invalid_length');
     }
     $keyword = KeywordFilter::isContainGeneric($subCategory);
     if ($keyword !== false) {
         throw new UserException('Problem.Tag.name_forbid', ['keyword' => $keyword]);
     }
     $this->category = $category;
     $this->subCategory = $subCategory;
 }
开发者ID:Tanklong,项目名称:openvj,代码行数:37,代码来源:CategoryTag.php

示例9: __construct

 public function __construct($webapiKey = null, $userLogin = null, $hashedPassword = null)
 {
     $this->properties['webapiKey'] = new Property(['validator' => function ($value) {
         try {
             Validator::string()->noWhitespace()->notEmpty()->length(4)->assert($value);
         } catch (NestedValidationExceptionInterface $e) {
             throw new ValidationException($e);
         }
     }]);
     if (!is_null($webapiKey)) {
         $this->properties['webapiKey']->set($webapiKey)->lock();
     }
     // --------------------
     $this->properties['userLogin'] = new Property(['validator' => function ($value) {
         try {
             Validator::string()->noWhitespace()->notEmpty()->length(4)->assert($value);
         } catch (NestedValidationExceptionInterface $e) {
             throw new ValidationException($e);
         }
     }]);
     if (!is_null($userLogin)) {
         $this->properties['userLogin']->set($userLogin)->lock();
     }
     // ----------------------
     $this->properties['hashedPassword'] = new Property(['validator' => function ($value) {
         try {
             Validator::string()->noWhitespace()->notEmpty()->regex('/^([A-Za-z0-9+\\/]{4})*([A-Za-z0-9+\\/]{4}|[A-Za-z0-9+\\/]{3}=|[A-Za-z0-9+\\/]{2}==)$/')->assert($value);
         } catch (NestedValidationExceptionInterface $e) {
             throw new ValidationException($e);
         }
     }]);
     if (!is_null($hashedPassword)) {
         $this->properties['hashedPassword']->set($hashedPassword)->lock();
     }
 }
开发者ID:rindeal,项目名称:allegro-client,代码行数:35,代码来源:ApiCredentials.php

示例10: validate

 public function validate($prop, $label)
 {
     $value = $this->getValue($prop);
     if (!v::string()->cnpj()->validate($value)) {
         $this->addException("O preenchimento do campo {$label} está inválido");
     }
 }
开发者ID:dindigital,项目名称:din,代码行数:7,代码来源:StringCNPJ.php

示例11: validate

 /**
  * @param $cardNumber
  * @return array
  * @throws NumberValidateException
  */
 public static function validate($cardNumber)
 {
     if (!v::numeric()->noWhitespace()->validate($cardNumber)) {
         throw new NumberValidateException();
     }
     return ['valid' => true, 'type' => 'visa'];
 }
开发者ID:vinyvicente,项目名称:credit-card-brands,代码行数:12,代码来源:Card.php

示例12: setAlternativeEmail

 public function setAlternativeEmail($value)
 {
     if (!v::email()->validate($value)) {
         throw new FieldRequiredException("E-mail alternativo inválido");
     }
     $this->_email .= "," . $value;
 }
开发者ID:dindigital,项目名称:nfe-focus,代码行数:7,代码来源:Receiver.php

示例13: isValid

 public function isValid($validation_data)
 {
     $errors = [];
     foreach ($validation_data as $name => $value) {
         if (isset($_REQUEST[$name])) {
             $rules = explode("|", $value);
             foreach ($rules as $rule) {
                 $exploded = explode(":", $rule);
                 switch ($exploded[0]) {
                     case 'min':
                         $min = $exploded[1];
                         if (Valid::stringType()->length($min)->Validate($_REQUEST[$name]) == false) {
                             $errors[] = $name . " must be at least " . $min . " characters long";
                         }
                         break;
                     case 'email':
                         if (Valid::email()->Validate($_REQUEST[$name]) == false) {
                             $errors[] = $name . " must be a valid email ";
                         }
                         break;
                     case 'equalTo':
                         if (Valid::equals($_REQUEST[$name])->Validate($_REQUEST[$exploded[1]]) == false) {
                             $errors[] = "Values do not match";
                         }
                         break;
                     default:
                         //do nothing
                 }
             }
         } else {
             $errors = "No value found";
         }
     }
     return $errors;
 }
开发者ID:pivnicki,项目名称:acme,代码行数:35,代码来源:Validator.php

示例14: _validate

 private function _validate($param, $type)
 {
     $libConfig = $GLOBALS['app']->getConfiguration()->getRawConfiguration('library');
     $minNameVal = $libConfig["product"]["minNameLength"];
     $maxNameVal = $libConfig["product"]["maxNameLength"];
     $minCodeVal = $libConfig["product"]["minCodeLength"];
     $maxCodeVal = $libConfig["product"]["maxCodeLength"];
     $validateName = v::alnum('-_')->length($minNameVal, $maxNameVal);
     $validateCode = v::alnum('-_')->noWhitespace()->length($minCodeVal, $maxCodeVal);
     $validateToken = v::alnum('-_');
     if (strcmp($type, "name") === 0) {
         $isValid = $validateName->validate($param);
         if (!$isValid) {
             throw new \InvalidArgumentException(\Akzo\Product\ErrorMessages::INVALID_PRODUCT_NAME, \Native5\Core\Http\StatusCodes::NOT_ACCEPTABLE);
         }
     } else {
         if (strcmp($type, "code") === 0) {
             $isValid = $validateCode->validate($param);
             if (!$isValid) {
                 throw new \InvalidArgumentException(\Akzo\Product\ErrorMessages::INVALID_PRODUCT_CODE, \Native5\Core\Http\StatusCodes::NOT_ACCEPTABLE);
             }
         } else {
             if (strcmp($type, "token") === 0) {
                 $isValid = $validateToken->validate($param);
                 if (!$isValid) {
                     throw new \InvalidArgumentException(\Akzo\Product\ErrorMessages::INVALID_TOKEN, \Native5\Core\Http\StatusCodes::NOT_ACCEPTABLE);
                 }
             } else {
                 throw new \InvalidArgumentException('Invalid Validation Type', \Native5\Core\Http\StatusCodes::NOT_ACCEPTABLE);
             }
         }
     }
 }
开发者ID:Aasit,项目名称:DISCOUNT--SRV-I,代码行数:33,代码来源:DAOImpl.php

示例15: validate

 protected function validate()
 {
     $data = filter_input(INPUT_POST, $this->model);
     $error = false;
     foreach ($this->validation_rules as $field => $config) {
         $validator = new v();
         $validator->addRules($config['rules']);
         if ($config['optional']) {
             $this->validate[$field] = v::optional($validator);
         } else {
             $this->validate[$field] = $validator;
         }
         $error = $this->validate[$field]->validate($data[$field]);
     }
     return $error;
 }
开发者ID:10suns,项目名称:simple_form,代码行数:16,代码来源:Form.php


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