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


PHP Validator::passes方法代码示例

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


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

示例1: validateForm

 /**
  * @param Form $form
  * @return bool
  */
 public function validateForm(Form $form)
 {
     if ($form != $this->form) {
         throw new ValidationException("Cannot validate different form with the same validator.");
     }
     return $this->validator->passes();
 }
开发者ID:okneloper,项目名称:forms,代码行数:11,代码来源:IlluminateValidator.php

示例2: validate

 /**
  * Validate the form
  *
  * @param null $scope
  * @param null $options
  * @return mixed
  * @throws \Exception
  */
 private function validate()
 {
     if (isset($this->validator)) {
         throw new \Exception('Cannot validate the same form twice, use the existing result');
     }
     $fieldRules = $this->getFieldValidationRules($this->formHandler->getFormBlueprint()->getAll());
     $validationRules = $fieldRules['rules'];
     $validationAttributeNames = $fieldRules['names'];
     // Get validation rules from any assigned entities (models)
     foreach ($this->formHandler->getEntities() as $entity) {
         if (is_callable([$entity['entity'], 'getValidationRules'])) {
             try {
                 $entityRules = $entity['entity']->getValidationRules();
             } catch (\BadMethodCallException $e) {
                 $entityRules = [];
             }
             foreach ($entityRules as $field => $entityRule) {
                 // If we already have rules for that parameter, concatenate them
                 if (isset($validationRules[$field])) {
                     $validationRules[$field] .= '|' . $entityRule;
                 } else {
                     $validationRules[$field] = $entityRule;
                 }
             }
         }
     }
     $this->validator = \Validator::make($this->formHandler->getData(), $validationRules);
     $this->validator->setAttributeNames($validationAttributeNames);
     $this->isValid = $this->validator->passes();
 }
开发者ID:andyvenus,项目名称:laravel-forms,代码行数:38,代码来源:LaravelValidatorExtension.php

示例3: isValid

 /**
  * Test Valid Data
  * @return bool
  */
 public function isValid()
 {
     $vRules = $this->getValidationRules();
     $rules = $vRules->getRules();
     $messages = $vRules->getMessages();
     $currentData = $this->export();
     $this->validator = Validator::make($currentData, $rules, $messages);
     return $this->validator->passes();
 }
开发者ID:thiagodionizio,项目名称:laravel-pagseguro,代码行数:13,代码来源:ValidateTrait.php

示例4: isValid

 /**
  * Returns whether the input data is valid.
  *
  * @throws NoValidationRulesFoundException
  * @return bool
  */
 public function isValid()
 {
     $this->beforeValidation();
     if (!isset($this->rules)) {
         throw new NoValidationRulesFoundException('no validation rules found in class ' . get_called_class());
     }
     $this->validator = Validator::make($this->getInputData(), $this->getPreparedRules(), $this->getMessages());
     $this->afterValidation();
     return $this->validator->passes();
 }
开发者ID:christiannwamba,项目名称:laravel-site,代码行数:16,代码来源:BaseValidator.php

示例5: validate

 public function validate()
 {
     $this->initValidator();
     if (!$this->validator->passes()) {
         throw new ProcessorException(ProcessorException::INVALID_PARAM, $this->error());
     }
     $this->validateAmount();
     $this->validateDestination();
     $this->validateTime();
     return true;
 }
开发者ID:fintech-fab,项目名称:money-transfer-emulator,代码行数:11,代码来源:Input.php

示例6: runValidation

 /**
  * Validates the model.
  *
  * @param array $customRules
  * @param array $customMessages
  * @param array $attributeNames
  *
  * @return bool
  */
 protected function runValidation(array $customRules = [], array $customMessages = [], array $attributeNames = [])
 {
     $rules = empty($customRules) ? $this->getRules() : $customRules;
     $messages = empty($customMessages) ? $this->getCustomMessages() : $customMessages;
     $attributeNames = empty($attributeNames) ? $this->getAttributeNames() : $attributeNames;
     $attributes = $this->prepareAttributes();
     $this->validator = $this->makeValidator($attributes, $rules, $messages);
     $this->validator->setAttributeNames($attributeNames);
     $success = $this->validator->passes();
     if (!$success) {
         $this->setErrors($this->validator->errors());
     }
     return $success;
 }
开发者ID:vinicius73,项目名称:laravel-model-shield,代码行数:23,代码来源:ShieldValidator.php

示例7: passes

 /**
  * Determine if the data passes the validation rules.
  *
  * @return bool
  */
 public function passes()
 {
     if ($this->isRemoteValidationRequest()) {
         return $this->validateJsRemoteRequest($this->data['_jsvalidation'], [$this, 'parent::passes']);
     }
     return parent::passes();
 }
开发者ID:samuelfa,项目名称:laravel-jsvalidation,代码行数:12,代码来源:Validator.php

示例8: validate

 /**
  * Validate input data.
  *
  * @param $input
  *
  * @return bool
  */
 protected function validate($input)
 {
     $data = $rules = [];
     foreach ($this->builder->fields() as $field) {
         if (!method_exists($field, 'rules') || !($rule = $field->rules())) {
             continue;
         }
         $columns = $field->column();
         if (is_string($columns)) {
             if (!array_key_exists($columns, $input)) {
                 continue;
             }
             $data[$field->label()] = array_get($input, $columns);
             $rules[$field->label()] = $rule;
         }
         if (is_array($columns)) {
             foreach ($columns as $key => $column) {
                 if (!array_key_exists($column, $input)) {
                     continue;
                 }
                 $data[$field->label() . $key] = array_get($input, $column);
                 $rules[$field->label() . $key] = $rule;
             }
         }
     }
     $this->validator = Validator::make($data, $rules);
     return $this->validator->passes();
 }
开发者ID:z-song,项目名称:laravel-admin,代码行数:35,代码来源:Form.php

示例9:

 function it_returns_messages_on_failed_validation(Validator $validator, MessageBag $bag)
 {
     $validator->setData($data = [])->shouldBeCalled();
     $validator->passes()->willReturn(false);
     $validator->messages()->willReturn($bag);
     $bag->all()->willReturn($messages = ['foo' => 'failed']);
     $this->validate($data)->shouldReturn(false);
     $this->getMessages()->shouldReturn($messages);
 }
开发者ID:desmart,项目名称:deform-laravel,代码行数:9,代码来源:ValidatorAdapterSpec.php

示例10: valid

 /**
  * Returns whether the current state of the validator is valid.
  *
  * @param bool $partial Whether a partial validation is okay.
  * @return bool
  */
 public function valid($partial = false)
 {
     if ($partial) {
         $this->useFields(array_keys($this->values));
     }
     // Generate our implementation from the app.
     $this->validator = self::$factory->make($this->values, $this->rules);
     if ($this->validator->passes()) {
         return true;
     }
     $this->errors = $this->validator->messages();
     return false;
 }
开发者ID:tippingcanoe,项目名称:validator,代码行数:19,代码来源:Base.php

示例11: validate

 /**
  * Validate the values
  *
  * @param array $values
  *
  * @return bool
  */
 public function validate(array $values)
 {
     $values = $this->snakeArrayKeys($values);
     $this->validator = $this->make($values, $this->getRules());
     // Make sure any forbidden keys are reported
     foreach ($this->forbiddenKeys as $key) {
         if (array_key_exists($key, $values)) {
             $this->addErrorMessage($key, sprintf('%s should not be set', $key));
             return false;
         }
     }
     $passes = $this->validator->passes();
     // Validate the sub rules
     foreach ($this->getSubValidators() as $key => $validator) {
         // Skip missing data, if it were required the require rule would
         // kick in
         if (!isset($values[$key])) {
             continue;
         }
         $subValues = $values[$key];
         if (count($subValues)) {
             // If the 0 index is set it means we have multiple sub
             // objects to validate
             if (isset($subValues[0])) {
                 foreach ($subValues as $subValueSet) {
                     /** @var Validator $validator */
                     $validator = new $validator();
                     $passes = $passes && $this->subValidate($validator, $subValueSet, $key);
                 }
             } else {
                 /** @var Validator $validator */
                 $validator = new $validator();
                 $passes = $passes && $this->subValidate($validator, $subValues, $key);
             }
         }
     }
     return $passes;
 }
开发者ID:sellerlabs,项目名称:beakers,代码行数:45,代码来源:Validator.php

示例12: validate

 /**
  * Validate the model instance
  *
  * @param array $rules            Validation rules
  * @param array $customMessages   Custom error messages
  * @param array $customAttributes Custom attributes
  * @return bool
  * @throws InvalidModelException
  */
 public function validate(array $rules = array(), array $customMessages = array(), array $customAttributes = array())
 {
     if ($this->fireModelEvent('validating') === false) {
         if ($this->throwOnValidation) {
             throw new InvalidModelException($this);
         } else {
             return false;
         }
     }
     // check for overrides, then remove any empty rules
     $rules = empty($rules) ? static::$rules : $rules;
     foreach ($rules as $field => $rls) {
         if ($rls == '') {
             unset($rules[$field]);
         }
     }
     if (empty($rules)) {
         $success = true;
     } else {
         $customMessages = empty($customMessages) ? static::$customMessages : $customMessages;
         $customAttributes = empty($customAttributes) ? static::$customAttributes : $customAttributes;
         if ($this->forceEntityHydrationFromInput || empty($this->attributes) && $this->autoHydrateEntityFromInput) {
             $this->fill(Input::all());
         }
         $data = $this->getAttributes();
         // the data under validation
         // perform validation
         $this->validator = static::makeValidator($data, $rules, $customMessages, $customAttributes);
         $success = $this->validator->passes();
         if ($success) {
             // if the model is valid, unset old errors
             if ($this->validationErrors === null || $this->validationErrors->count() > 0) {
                 $this->validationErrors = new MessageBag();
             }
         } else {
             // otherwise set the new ones
             $this->validationErrors = $this->validator->messages();
             // stash the input to the current session
             if (!self::$externalValidator && Input::hasSession()) {
                 Input::flash();
             }
         }
     }
     $this->fireModelEvent('validated', false);
     if (!$success && $this->throwOnValidation) {
         throw new InvalidModelException($this);
     }
     return $success;
 }
开发者ID:weyforth,项目名称:ardent,代码行数:58,代码来源:Ardent.php

示例13: setResponse

 /**
  * Set the response based on validation.
  *
  * @param Validator   $validator
  * @param FormBuilder $builder
  */
 protected function setResponse(Validator $validator, FormBuilder $builder)
 {
     if (!$validator->passes()) {
         $builder->setSave(false)->setFormErrors($validator->getMessageBag());
         $this->dispatch(new SetErrorMessages($builder));
     }
     $this->dispatch(new RepopulateFields($builder));
 }
开发者ID:jacksun101,项目名称:streams-platform,代码行数:14,代码来源:FormValidator.php

示例14: passes

 /**
  * Determine if the data passes the validation rules.
  *
  * @return bool
  */
 public function passes()
 {
     return $this->validator->passes();
 }
开发者ID:Kremon,项目名称:laravel-jsvalidation,代码行数:9,代码来源:DelegatedValidator.php

示例15: testCustomValidators

 public function testCustomValidators()
 {
     $trans = $this->getRealTranslator();
     $trans->addResource('array', array('validation.foo' => 'foo!'), 'en', 'messages');
     $v = new Validator($trans, array('name' => 'taylor'), array('name' => 'Foo'));
     $v->addExtension('Foo', function () {
         return false;
     });
     $this->assertFalse($v->passes());
     $v->getMessages()->setFormat(':message');
     $this->assertEquals('foo!', $v->getMessages()->first('name'));
 }
开发者ID:j-ew-s,项目名称:BabyName,代码行数:12,代码来源:ValidatorTest.php


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