本文整理汇总了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();
}
示例2: validationFails
public function validationFails(Validator $validator)
{
$this->success = false;
$this->errors = $validator->getMessageBag();
$this->validationErrors = $validator->getMessageBag();
return $this->toJson();
}
示例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');
}
示例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);
}
示例5: __construct
public function __construct(Validator $validator)
{
$errors = '';
foreach ($validator->errors()->getMessages() as $key => $messages) {
$errors .= implode(' ', $messages) . ' ';
}
parent::__construct(422, trim($errors));
}
示例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;
}
示例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;
}
示例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;
}
示例9: validate
public function validate(\Illuminate\Validation\Validator $validator)
{
if ($validator->fails()) {
$this->validation_errors = $validator->messages();
return false;
}
return true;
}
示例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;
}
示例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();
}
示例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);
}
示例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());
}
示例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();
}
示例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());
}
}