當前位置: 首頁>>代碼示例>>PHP>>正文


PHP Validator::optional方法代碼示例

本文整理匯總了PHP中Respect\Validation\Validator::optional方法的典型用法代碼示例。如果您正苦於以下問題:PHP Validator::optional方法的具體用法?PHP Validator::optional怎麽用?PHP Validator::optional使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在Respect\Validation\Validator的用法示例。


在下文中一共展示了Validator::optional方法的5個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。

示例1: 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

示例2: __construct

 public function __construct(array $options)
 {
     $options = ['baseUri' => Arr::get($options, 'baseUri', $this->baseUri), 'timeout' => Arr::get($options, 'timeout', $this->timeout), 'proxy' => Arr::get($options, 'proxy', $this->proxy), 'auth' => Arr::get($options, 'auth', $this->auth), 'logger' => Arr::get($options, 'logger')];
     try {
         V::arrayVal()->key('baseUri', V::url()->notEmpty())->key('timeout', V::floatVal()->min(0))->key('proxy', V::optional(V::url()))->key('auth', V::arrayVal()->key('user', V::stringType())->key('pass', V::stringType()))->key('logger', V::instance('\\Psr\\Log\\LoggerInterface'))->assert($options);
     } catch (\InvalidArgumentException $e) {
         $errors = array_filter($e->findMessages(['baseUri' => 'Required correct baseUri', 'timeout' => 'Required correct timeout', 'proxy' => 'Required correct proxy', 'auth' => 'Required correct authuser', 'logger' => 'Required a logger instance of psr\\log']));
         $errmsg = array_shift($errors);
         throw new Exception($errmsg);
     }
     $this->baseUri = $options['baseUri'];
     $this->timeout = $options['timeout'];
     $this->proxy = $options['proxy'];
     $this->auth = $options['auth'];
     $this->logger = $options['logger'];
 }
開發者ID:qinyuguang,項目名稱:libyaf,代碼行數:16,代碼來源:Conf.php

示例3: createNegativeOrOptionalValidator

 /**
  * Create a negative or optional validator instance.
  *
  * @param string $filter
  * @param array  $rules
  *
  * @return \Respect\Validation\Validator
  */
 protected function createNegativeOrOptionalValidator(string $filter, array $rules) : RespectValidator
 {
     list($method, $parameters) = $this->parseStringRule($rules[0]);
     unset($rules[0]);
     $validator = call_user_func_array([RespectValidator::class, str_replace($filter, '', $method)], $parameters);
     if ($filter === '!') {
         return RespectValidator::not($this->createChainableValidators($validator, $rules));
     }
     return RespectValidator::optional($this->createChainableValidators($validator, $rules));
 }
開發者ID:narrowspark,項目名稱:framework,代碼行數:18,代碼來源:Validator.php

示例4: validate

 private function validate()
 {
     try {
         $validator = v::attribute('merchantAlias', v::stringType()->alnum('_')->noWhitespace()->length(1, 30))->attribute('macKey', v::stringType()->length(1))->attribute('transactionCode', v::stringType()->alnum()->noWhitespace()->length(1, 30))->attribute('requestType', v::oneOf(v::stringType()->equals(self::REQUEST_TYPE_FIRST_ATTEMPT), v::stringType()->equals(self::REQUEST_TYPE_RETRY_ATTEMPT)))->attribute('operationId', v::stringType()->digit()->noWhitespace()->length(1, 10))->attribute('operationType', v::oneOf(v::stringType()->equals(self::OPERATION_TYPE_CAPTURE), v::stringType()->equals(self::OPERATION_TYPE_VOID)))->attribute('originalAmount', v::stringType()->digit()->noWhitespace()->length(9, 9))->attribute('currency', v::stringType()->alnum()->noWhitespace()->length(3, 3))->attribute('authCode', v::stringType()->alnum()->noWhitespace()->length(1, 10))->attribute('operationAmount', v::stringType()->digit()->noWhitespace()->length(9, 9))->attribute('user', v::optional(v::stringType()->alnum()->length(0, 20)))->attribute('isTest', v::boolType());
         $validator->assert($this);
     } catch (NestedValidationException $e) {
         throw new ValidationException($e->getFullMessage());
     }
 }
開發者ID:webgriffe,項目名稱:lib-quipago,代碼行數:9,代碼來源:EcRequest.php

示例5: testValidationNotExistingOptionalParameter

 public function testValidationNotExistingOptionalParameter()
 {
     $notExistingValidator = v::optional(v::alpha());
     $validators = array('notExisting' => $notExistingValidator);
     $mw = new Validation($validators);
     $next = function ($req, $res) {
         return $res;
     };
     $response = $mw($this->request, $this->response, $next);
     $errors = array();
     $this->assertFalse($mw->hasErrors());
     $this->assertEquals($errors, $mw->getErrors());
 }
開發者ID:DavidePastore,項目名稱:Slim-Validation,代碼行數:13,代碼來源:ValidationTest.php


注:本文中的Respect\Validation\Validator::optional方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。