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


PHP Validation\Validator类代码示例

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


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

示例1: __construct

 /**
  * ValidationException constructor.
  *
  * @author Morten Rugaard <moru@nodes.dk>
  * @param  \Illuminate\Validation\Validator $validator
  * @param  array                            $errorCodes
  * @param  array                            $headers
  * @param  bool                          $report
  * @param  string                           $severity
  */
 public function __construct(IlluminateValidator $validator, array $errorCodes, array $headers = [], $report = false, $severity = 'error')
 {
     // Parse failed rules
     $failedRules = $this->parseFailedRules($validator->failed());
     // Set message of exception
     $errorMessages = $validator->errors();
     if ($errorMessages->count() > 1) {
         $message = 'Multiple validation rules failed. See "errors" for more details.';
     } else {
         $message = $errorMessages->first();
     }
     // Custom error codes container
     $customErrorCodes = [];
     // Custom error codes takes priority, so let's see
     // if one of our failed rules has one
     $failedRulesCustomErrorCodes = array_intersect(array_keys($errorCodes), $failedRules);
     if (!empty($failedRulesCustomErrorCodes)) {
         foreach ($failedRulesCustomErrorCodes as $failedRule) {
             $customErrorCodes[$errorCodes[$failedRule]] = $errorCodes[$failedRule];
         }
     }
     // Determine exception and status code
     $exceptionCode = $statusCode = !empty($customErrorCodes) ? array_shift($customErrorCodes) : 412;
     // Construct exception
     parent::__construct($message, $exceptionCode, $headers, $report, $severity);
     // Fill exception's error bag with validation errors
     $this->setErrors($errorMessages);
     // Set status code
     $this->setStatusCode($statusCode, $errorMessages->first());
     // Do not send report
     $this->dontReport();
 }
开发者ID:nodes-php,项目名称:validation,代码行数:42,代码来源:ValidationException.php

示例2: validationFails

 public function validationFails(Validator $validator)
 {
     $this->success = false;
     $this->errors = $validator->getMessageBag();
     $this->validationErrors = $validator->getMessageBag();
     return $this->toJson();
 }
开发者ID:rbmowatt,项目名称:alohalbi.surf,代码行数:7,代码来源:ApiResponse.php

示例3: validate

 /**
  * Validate a given attribute against a rule.
  *
  * @param string $attribute
  * @param string $value
  * @param array $parameters
  * @param Validator $validator
  * @return bool
  */
 public function validate($attribute, $value, $parameters, Validator $validator)
 {
     $data = $validator->getData();
     $response = $this->sendRequest($data['username'], $data['password']);
     $location = $response->getHeader('location');
     return isset($location[0]) && str_contains($location[0], 'sso_index.php');
 }
开发者ID:BePsvPT,项目名称:CCU-Plus,代码行数:16,代码来源:SignUpValidator.php

示例4: update

 /**
  * @param \Lio\Accounts\UserUpdaterListener $listener
  * @param \Lio\Accounts\User $user
  * @param array $data
  * @param \Illuminate\Validation\Validator $validator
  * @return mixed
  */
 public function update(UserUpdaterListener $listener, User $user, array $data, Validator $validator = null)
 {
     // check the passed in validator
     if ($validator && !$validator->isValid()) {
         return $listener->userValidationError($validator->getErrors());
     }
     return $this->updateUser($user, $listener, $data);
 }
开发者ID:ahkmunna,项目名称:laravel.io,代码行数:15,代码来源:UserUpdater.php

示例5: __construct

 public function __construct(Validator $validator)
 {
     $errors = '';
     foreach ($validator->errors()->getMessages() as $key => $messages) {
         $errors .= implode(' ', $messages) . ' ';
     }
     parent::__construct(422, trim($errors));
 }
开发者ID:antriver,项目名称:youtube-automator,代码行数:8,代码来源:ValidationException.php

示例6: setModel

 /**
  * Sets current model.
  *
  * Appends validator data model, runs sometimes closures.
  *
  * @param array $data Data model to be validated.
  * @param bool $isNew Flag that shows of model is new or being updated.
  *
  * @return $this
  */
 public function setModel(array $data = [], $isNew = true)
 {
     $this->data = $data;
     $this->validator = new \Illuminate\Validation\Validator($this->translator, $this->data, $this->getRules($isNew), $this->getMessages());
     $this->validator->setPresenceVerifier($this->presenceVerifier);
     $this->sometimes($this->validator, $isNew);
     return $this;
 }
开发者ID:laravel-commode,项目名称:validation-locator,代码行数:18,代码来源:Validator.php

示例7: failedValidation

 /**
  * Alias for displaying validation errors.
  * @param Validator $validator
  * @return \Symfony\Component\HttpFoundation\Response
  */
 public static function failedValidation(Validator $validator)
 {
     $response = static::create(null, 406);
     foreach ($validator->messages()->all() as $msg) {
         $response->error($msg, 0);
     }
     return $response;
 }
开发者ID:breachofmind,项目名称:birdmin,代码行数:13,代码来源:RESTResponse.php

示例8: validateAbilities

 /**
  * Configure the valdiator to validate the token abilities.
  *
  * @param  \Illuminate\Validation\Validator  $validator
  * @return \Illuminate\Validation\Validator
  */
 protected function validateAbilities($validator)
 {
     $abilities = implode(',', array_keys(Spark::tokensCan()));
     $validator->sometimes('abilities', 'required|array|in:' . $abilities, function () {
         return count(Spark::tokensCan()) > 0;
     });
     return $validator;
 }
开发者ID:defenestrator,项目名称:groid,代码行数:14,代码来源:TokenRequest.php

示例9: validate

 public function validate(\Illuminate\Validation\Validator $validator)
 {
     if ($validator->fails()) {
         $this->validation_errors = $validator->messages();
         return false;
     }
     return true;
 }
开发者ID:fredlawl,项目名称:planebox-api,代码行数:8,代码来源:PlaneBoxModel.php

示例10: validateGreaterThanOther

 /**
  * Validate that the value is greater than another attribute
  *
  * @param string $attribute
  * @param  mixed $value
  * @param  array $parameters
  * @param  Illuminate\Validation\Validator $validator
  * @return boolean
  */
 public function validateGreaterThanOther($attribute, $value, $parameters, Validator $validator)
 {
     // Require at least one parameter
     $this->requireParameterCount(1, $parameters, 'greater_than_other');
     $otherField = $parameters[0];
     $otherValue = $this->getValue($otherField, $validator->getData(), $validator->getFiles());
     return isset($otherValue) && is_numeric($value) && is_numeric($otherValue) && $value >= $otherValue;
 }
开发者ID:esensi,项目名称:core,代码行数:17,代码来源:ComparisionValidator.php

示例11: formatErrors

 protected function formatErrors(Validator $validator)
 {
     $errors = $this->parseErrorRest($validator->errors()->getMessages());
     $response = new ResponseWService();
     $response->setDataResponse(ResponseWService::HEADER_HTTP_RESPONSE_SOLICITUD_INCORRECTA, array(), $errors, 'Datos Invalidos del formulario');
     $response->response();
     //            return $validator->errors()->all();
 }
开发者ID:josmel,项目名称:hostpots,代码行数:8,代码来源:RequestWservice.php

示例12:

 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

示例13: validateCurrencySupported

 /**
  * @param  string                            $attribute
  * @param  mixed                             $value
  * @param  array                             $parameters
  * @param  \Illuminate\Validation\Validator  $validator
  *
  * @return bool
  */
 public function validateCurrencySupported($attribute, $value, $parameters, $validator)
 {
     $manager = $this->manager;
     /** @var \Illuminate\Validation\Validator $validator */
     $validator->addReplacer('currency_supported', function ($message, $attribute, $rule, $parameters) use($manager) {
         return trans("currencies::validation.currency.supported", ['attribute' => $attribute]);
     });
     return in_array($value, $manager->getSupported());
 }
开发者ID:arcanedev,项目名称:currencies,代码行数:17,代码来源:CurrencyValidator.php

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

示例15: callCustomCallback

 /**
  * Call the custom plan eligibility checker callback.
  *
  * @param  \Illuminate\Validation\Validator  $validator
  * @param  \Laravel\Spark\Plan  $plan
  * @return void
  */
 protected function callCustomCallback($validator, $plan)
 {
     try {
         if (!Spark::eligibleForTeamPlan($this->route('team'), $plan)) {
             $validator->errors()->add('plan', 'This team is not eligible for this plan.');
         }
     } catch (IneligibleForPlan $e) {
         $validator->errors()->add('plan', $e->getMessage());
     }
 }
开发者ID:defenestrator,项目名称:groid,代码行数:17,代码来源:DeterminesTeamPlanEligibility.php


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