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


PHP Validator::getData方法代碼示例

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


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

示例1: validatePhone

 /**
  * Validates a phone number.
  *
  * @param  string                                     $attribute
  * @param  mixed                                      $value
  * @param  array                                      $parameters
  * @param  \Illuminate\Contracts\Validation\Validator $validator
  * @return bool
  * @throws \Propaganistas\LaravelPhone\Exceptions\InvalidParameterException
  * @throws \Propaganistas\LaravelPhone\Exceptions\NoValidCountryFoundException
  */
 public function validatePhone($attribute, $value, array $parameters, Validator $validator)
 {
     $this->attribute = $attribute;
     $this->data = $validator->getData();
     $this->parameters = array_map('strtoupper', $parameters);
     $this->determineCountries();
     $this->determineTypes();
     $this->checkLeftoverParameters();
     $phoneUtil = PhoneNumberUtil::getInstance();
     // Perform validation.
     foreach ($this->allowedCountries as $country) {
         try {
             // For default countries or country field, the following throws NumberParseException if
             // not parsed correctly against the supplied country.
             // For automatic detection: tries to discover the country code using from the number itself.
             $phoneProto = $phoneUtil->parse($value, $country);
             // For automatic detection, the number should have a country code.
             // Check if type is allowed.
             if ($phoneProto->hasCountryCode() && empty($this->allowedTypes) || in_array($phoneUtil->getNumberType($phoneProto), $this->allowedTypes)) {
                 // Automatic detection:
                 if ($country == 'ZZ') {
                     // Validate if the international phone number is valid for its contained country.
                     return $phoneUtil->isValidNumber($phoneProto);
                 }
                 // Force validation of number against the specified country.
                 return $phoneUtil->isValidNumberForRegion($phoneProto, $country);
             }
         } catch (NumberParseException $e) {
             // Proceed to default validation error.
         }
     }
     return false;
 }
開發者ID:summer11123,項目名稱:Laravel-Phone,代碼行數:44,代碼來源:PhoneValidator.php

示例2: extendUpdate

 /**
  * Extend update validations.
  *
  * @param  \Illuminate\Contracts\Validation\Validator  $validator
  *
  * @return void
  */
 protected function extendUpdate(ValidatorResolver $validator)
 {
     $name = Keyword::make($validator->getData()['name']);
     $validator->after(function (ValidatorResolver $v) use($name) {
         if ($this->isRoleNameGuest($name)) {
             $v->errors()->add('name', trans('orchestra/control::response.roles.reserved-word'));
         }
     });
 }
開發者ID:quetzyg,項目名稱:control,代碼行數:16,代碼來源:Role.php

示例3: filterValidatorData

 /**
  * [filterValidatorData description]
  * @param  Validator $validator [description]
  * @param  [type]    $keys      [description]
  * @return [type]               [description]
  */
 private function filterValidatorData(Validator $validator, $keys)
 {
     $data = $validator->getData();
     return $keys == '*' ? $data : array_keyfilter($data, $keys);
 }
開發者ID:unionbt,項目名稱:hanpaimall,代碼行數:11,代碼來源:ValidatesRequests.php


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