• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

PHP Validation\Validator类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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



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

示例1: __construct

 /**
  * ValidationException constructor.
  *
  * @author Morten Rugaard <[email protected]>
  * @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


示例16: after

 /**
  * Setup the "after" callabck for the validator.
  *
  * @param  \Illuminate\Validation\Validator  $validator
  * @return \Illuminate\Validation\Validator
  */
 protected function after($validator)
 {
     return $validator->after(function ($validator) {
         if ($this->coupon) {
             $this->validateCoupon($validator);
         }
         if ($this->invitation) {
             $this->validateInvitation($validator);
         }
     });
 }
开发者ID:defenestrator,项目名称:groid,代码行数:17,代码来源:RegisterRequest.php


示例17: validateMaximumTeamsNotExceeded

 /**
  * Validate that the maximum number of teams hasn't been exceeded.
  *
  * @param  \Illuminate\Validation\Validator  $validator
  * @param  \Illuminate\Contracts\Auth\Authenticatable  $user
  * @return void
  */
 protected function validateMaximumTeamsNotExceeded($validator, $user)
 {
     if (!($plan = $user->sparkPlan())) {
         return;
     }
     if (is_null($plan->teams)) {
         return;
     }
     if ($plan->teams <= $user->ownedTeams()->count()) {
         $validator->errors()->add('name', 'Please upgrade your subscription to create more teams.');
     }
 }
开发者ID:defenestrator,项目名称:groid,代码行数:19,代码来源:CreateTeam.php


示例18: validateAfterOther

 /**
  * Validate that the date is after another attribute date
  *
  * @param string $attribute
  * @param  mixed $value
  * @param  array $parameters
  * @param  Illuminate\Validation\Validator $validator
  * @return boolean
  */
 public function validateAfterOther($attribute, $value, $parameters, Validator $validator)
 {
     // Require at least one parameter
     $this->requireParameterCount(1, $parameters, 'after_other');
     // Get the other value
     $otherField = $parameters[0];
     $otherValue = $this->getValue($otherField, $validator->getData(), $validator->getFiles());
     // Convert the values to dates if not already
     $value = $this->asDateFromValue($value);
     $otherValue = $this->asDateFromValue($otherValue);
     // Compare that the date is after the other date
     return isset($value) && isset($otherValue) && $value >= $otherValue;
 }
开发者ID:esensi,项目名称:core,代码行数:22,代码来源:DateValidator.php


示例19: setRemoteValidation

 /**
  * Sets data for validate remote rules.
  *
  * @param $attribute
  *
  * @return \Illuminate\Validation\Validator
  */
 protected function setRemoteValidation($attribute, BaseValidator $validator)
 {
     if (!array_key_exists($attribute, $validator->getRules())) {
         throw new BadRequestHttpException("Undefined '{$attribute}' attribute");
     }
     $rules = $validator->getRules()[$attribute];
     $rules = $this->purgeNonRemoteRules($rules, $validator);
     $validator->setRules([$attribute => $rules]);
     if (empty($validator->getRules()[$attribute])) {
         throw new BadRequestHttpException("No validations available for '{$attribute}'");
     }
     return $validator;
 }
开发者ID:suhe,项目名称:bdoportal,代码行数:20,代码来源:Validator.php


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



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
PHP View\Factory类代码示例发布时间:2022-05-23
下一篇:
PHP Validation\Factory类代码示例发布时间:2022-05-23
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap