本文整理汇总了PHP中Illuminate\Validation\Validator::passes方法的典型用法代码示例。如果您正苦于以下问题:PHP Validator::passes方法的具体用法?PHP Validator::passes怎么用?PHP Validator::passes使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Illuminate\Validation\Validator
的用法示例。
在下文中一共展示了Validator::passes方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: validateForm
/**
* @param Form $form
* @return bool
*/
public function validateForm(Form $form)
{
if ($form != $this->form) {
throw new ValidationException("Cannot validate different form with the same validator.");
}
return $this->validator->passes();
}
示例2: validate
/**
* Validate the form
*
* @param null $scope
* @param null $options
* @return mixed
* @throws \Exception
*/
private function validate()
{
if (isset($this->validator)) {
throw new \Exception('Cannot validate the same form twice, use the existing result');
}
$fieldRules = $this->getFieldValidationRules($this->formHandler->getFormBlueprint()->getAll());
$validationRules = $fieldRules['rules'];
$validationAttributeNames = $fieldRules['names'];
// Get validation rules from any assigned entities (models)
foreach ($this->formHandler->getEntities() as $entity) {
if (is_callable([$entity['entity'], 'getValidationRules'])) {
try {
$entityRules = $entity['entity']->getValidationRules();
} catch (\BadMethodCallException $e) {
$entityRules = [];
}
foreach ($entityRules as $field => $entityRule) {
// If we already have rules for that parameter, concatenate them
if (isset($validationRules[$field])) {
$validationRules[$field] .= '|' . $entityRule;
} else {
$validationRules[$field] = $entityRule;
}
}
}
}
$this->validator = \Validator::make($this->formHandler->getData(), $validationRules);
$this->validator->setAttributeNames($validationAttributeNames);
$this->isValid = $this->validator->passes();
}
示例3: 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();
}
示例4: isValid
/**
* Returns whether the input data is valid.
*
* @throws NoValidationRulesFoundException
* @return bool
*/
public function isValid()
{
$this->beforeValidation();
if (!isset($this->rules)) {
throw new NoValidationRulesFoundException('no validation rules found in class ' . get_called_class());
}
$this->validator = Validator::make($this->getInputData(), $this->getPreparedRules(), $this->getMessages());
$this->afterValidation();
return $this->validator->passes();
}
示例5: validate
public function validate()
{
$this->initValidator();
if (!$this->validator->passes()) {
throw new ProcessorException(ProcessorException::INVALID_PARAM, $this->error());
}
$this->validateAmount();
$this->validateDestination();
$this->validateTime();
return true;
}
示例6: 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;
}
示例7: passes
/**
* Determine if the data passes the validation rules.
*
* @return bool
*/
public function passes()
{
if ($this->isRemoteValidationRequest()) {
return $this->validateJsRemoteRequest($this->data['_jsvalidation'], [$this, 'parent::passes']);
}
return parent::passes();
}
示例8: validate
/**
* Validate input data.
*
* @param $input
*
* @return bool
*/
protected function validate($input)
{
$data = $rules = [];
foreach ($this->builder->fields() as $field) {
if (!method_exists($field, 'rules') || !($rule = $field->rules())) {
continue;
}
$columns = $field->column();
if (is_string($columns)) {
if (!array_key_exists($columns, $input)) {
continue;
}
$data[$field->label()] = array_get($input, $columns);
$rules[$field->label()] = $rule;
}
if (is_array($columns)) {
foreach ($columns as $key => $column) {
if (!array_key_exists($column, $input)) {
continue;
}
$data[$field->label() . $key] = array_get($input, $column);
$rules[$field->label() . $key] = $rule;
}
}
}
$this->validator = Validator::make($data, $rules);
return $this->validator->passes();
}
示例9:
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);
}
示例10: valid
/**
* Returns whether the current state of the validator is valid.
*
* @param bool $partial Whether a partial validation is okay.
* @return bool
*/
public function valid($partial = false)
{
if ($partial) {
$this->useFields(array_keys($this->values));
}
// Generate our implementation from the app.
$this->validator = self::$factory->make($this->values, $this->rules);
if ($this->validator->passes()) {
return true;
}
$this->errors = $this->validator->messages();
return false;
}
示例11: validate
/**
* Validate the values
*
* @param array $values
*
* @return bool
*/
public function validate(array $values)
{
$values = $this->snakeArrayKeys($values);
$this->validator = $this->make($values, $this->getRules());
// Make sure any forbidden keys are reported
foreach ($this->forbiddenKeys as $key) {
if (array_key_exists($key, $values)) {
$this->addErrorMessage($key, sprintf('%s should not be set', $key));
return false;
}
}
$passes = $this->validator->passes();
// Validate the sub rules
foreach ($this->getSubValidators() as $key => $validator) {
// Skip missing data, if it were required the require rule would
// kick in
if (!isset($values[$key])) {
continue;
}
$subValues = $values[$key];
if (count($subValues)) {
// If the 0 index is set it means we have multiple sub
// objects to validate
if (isset($subValues[0])) {
foreach ($subValues as $subValueSet) {
/** @var Validator $validator */
$validator = new $validator();
$passes = $passes && $this->subValidate($validator, $subValueSet, $key);
}
} else {
/** @var Validator $validator */
$validator = new $validator();
$passes = $passes && $this->subValidate($validator, $subValues, $key);
}
}
}
return $passes;
}
示例12: validate
/**
* Validate the model instance
*
* @param array $rules Validation rules
* @param array $customMessages Custom error messages
* @param array $customAttributes Custom attributes
* @return bool
* @throws InvalidModelException
*/
public function validate(array $rules = array(), array $customMessages = array(), array $customAttributes = array())
{
if ($this->fireModelEvent('validating') === false) {
if ($this->throwOnValidation) {
throw new InvalidModelException($this);
} else {
return false;
}
}
// check for overrides, then remove any empty rules
$rules = empty($rules) ? static::$rules : $rules;
foreach ($rules as $field => $rls) {
if ($rls == '') {
unset($rules[$field]);
}
}
if (empty($rules)) {
$success = true;
} else {
$customMessages = empty($customMessages) ? static::$customMessages : $customMessages;
$customAttributes = empty($customAttributes) ? static::$customAttributes : $customAttributes;
if ($this->forceEntityHydrationFromInput || empty($this->attributes) && $this->autoHydrateEntityFromInput) {
$this->fill(Input::all());
}
$data = $this->getAttributes();
// the data under validation
// perform validation
$this->validator = static::makeValidator($data, $rules, $customMessages, $customAttributes);
$success = $this->validator->passes();
if ($success) {
// if the model is valid, unset old errors
if ($this->validationErrors === null || $this->validationErrors->count() > 0) {
$this->validationErrors = new MessageBag();
}
} else {
// otherwise set the new ones
$this->validationErrors = $this->validator->messages();
// stash the input to the current session
if (!self::$externalValidator && Input::hasSession()) {
Input::flash();
}
}
}
$this->fireModelEvent('validated', false);
if (!$success && $this->throwOnValidation) {
throw new InvalidModelException($this);
}
return $success;
}
示例13: setResponse
/**
* Set the response based on validation.
*
* @param Validator $validator
* @param FormBuilder $builder
*/
protected function setResponse(Validator $validator, FormBuilder $builder)
{
if (!$validator->passes()) {
$builder->setSave(false)->setFormErrors($validator->getMessageBag());
$this->dispatch(new SetErrorMessages($builder));
}
$this->dispatch(new RepopulateFields($builder));
}
示例14: passes
/**
* Determine if the data passes the validation rules.
*
* @return bool
*/
public function passes()
{
return $this->validator->passes();
}
示例15: testCustomValidators
public function testCustomValidators()
{
$trans = $this->getRealTranslator();
$trans->addResource('array', array('validation.foo' => 'foo!'), 'en', 'messages');
$v = new Validator($trans, array('name' => 'taylor'), array('name' => 'Foo'));
$v->addExtension('Foo', function () {
return false;
});
$this->assertFalse($v->passes());
$v->getMessages()->setFormat(':message');
$this->assertEquals('foo!', $v->getMessages()->first('name'));
}