本文整理汇总了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;
}
示例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'));
}
});
}
示例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);
}