當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。