Skip to content

Validation


  • Full name: \Qubus\Validation\Validation

Properties

validator

protected mixed $validator

inputs

protected array $inputs

attributes

protected array $attributes

aliases

protected array $aliases

messageSeparator

protected string $messageSeparator

validData

protected array $validData

invalidData

protected array $invalidData

errors

public ?\Qubus\Validation\ErrorBag $errors

Methods

__construct

public __construct(\Qubus\Validation\Validator $validator, array $inputs, array $rules, array $messages = []): void

Parameters:

Parameter Type Description
$validator \Qubus\Validation\Validator
$inputs array
$rules array
$messages array

Throws:


addAttribute

Add attribute rules.

public addAttribute(string $attributeKey, array|string $rules): void

Parameters:

Parameter Type Description
$attributeKey string
$rules array|string

Throws:


getAttribute

Get attribute by key.

public getAttribute(string $attributeKey): null|\Qubus\Validation\Attribute

Parameters:

Parameter Type Description
$attributeKey string

validate

Run validation.

public validate(array $inputs = []): void

Parameters:

Parameter Type Description
$inputs array

Throws:


errors

Get ErrorBag instance.

public errors(): \Qubus\Validation\ErrorBag

validateAttribute

Validate attribute.

protected validateAttribute(\Qubus\Validation\Attribute $attribute): void

Parameters:

Parameter Type Description
$attribute \Qubus\Validation\Attribute

Throws:


isArrayAttribute

Check whether given $attribute is array attribute.

protected isArrayAttribute(\Qubus\Validation\Attribute $attribute): bool

Parameters:

Parameter Type Description
$attribute \Qubus\Validation\Attribute

parseArrayAttribute

Parse array attribute into it's child attributes.

protected parseArrayAttribute(\Qubus\Validation\Attribute $attribute): array

Parameters:

Parameter Type Description
$attribute \Qubus\Validation\Attribute

Throws:


initializeAttributeOnData

Gather a copy of the attribute data filled with any missing attributes.

protected initializeAttributeOnData(string $attributeKey): array

Parameters:

Parameter Type Description
$attributeKey string

Throws:


extractValuesForWildcards

Get all the exact attribute values for a given wildcard attribute.

public extractValuesForWildcards(array $data, string $attributeKey): array

Parameters:

Parameter Type Description
$data array
$attributeKey string

Throws:


getLeadingExplicitAttributePath

Get the explicit part of the attribute name.

protected getLeadingExplicitAttributePath(string $attributeKey): string|null

E.g. 'foo.bar.*.baz' -> 'foo.bar'

Allows us to not spin through all the flattened data for some operations.

Parameters:

Parameter Type Description
$attributeKey string

Return Value:

null when root wildcard


extractDataFromPath

Extract data based on the given dot-notated path.

protected extractDataFromPath(string|null $attributeKey): array

Used to extract a subsection of the data for faster iteration.

Parameters:

Parameter Type Description
$attributeKey string|null

Throws:


addError

Add error to the $this->errors.

protected addError(\Qubus\Validation\Attribute $attribute, mixed $value, \Qubus\Validation\Rule $ruleValidator): void

Parameters:

Parameter Type Description
$attribute \Qubus\Validation\Attribute
$value mixed
$ruleValidator \Qubus\Validation\Rule

isEmptyValue

Check $value is empty value.

protected isEmptyValue(mixed $value): bool

Parameters:

Parameter Type Description
$value mixed

ruleIsOptional

Check the rule is optional.

protected ruleIsOptional(\Qubus\Validation\Attribute $attribute, \Qubus\Validation\Rule $rule): bool

Parameters:

Parameter Type Description
$attribute \Qubus\Validation\Attribute
$rule \Qubus\Validation\Rule

resolveAttributeName

Resolve attribute name.

protected resolveAttributeName(\Qubus\Validation\Attribute $attribute): string

Parameters:

Parameter Type Description
$attribute \Qubus\Validation\Attribute

resolveMessage

Resolve message.

protected resolveMessage(\Qubus\Validation\Attribute $attribute, mixed $value, \Qubus\Validation\Rule $validator): mixed

Parameters:

Parameter Type Description
$attribute \Qubus\Validation\Attribute
$value mixed
$validator \Qubus\Validation\Rule

stringify

Stringify $value.

protected stringify(mixed $value): string

Parameters:

Parameter Type Description
$value mixed

resolveRules

Resolve $rules.

protected resolveRules(mixed $rules): array

Parameters:

Parameter Type Description
$rules mixed

Throws:


parseRule

Parse $rule.

protected parseRule(string $rule): array

Parameters:

Parameter Type Description
$rule string

setAlias

Given $attributeKey and $alias then assign alias.

public setAlias(mixed $attributeKey, mixed $alias): void

Parameters:

Parameter Type Description
$attributeKey mixed
$alias mixed

getAlias

Get attribute alias from given key.

public getAlias(mixed $attributeKey): string|null

Parameters:

Parameter Type Description
$attributeKey mixed

setAliases

Set attributes aliases.

public setAliases(array $aliases): void

Parameters:

Parameter Type Description
$aliases array

passes

Check validations are passed.

public passes(): bool

fails

Check validations are failed.

public fails(): bool

getValue

Given $key and get value.

public getValue(string $key): mixed

Parameters:

Parameter Type Description
$key string

Throws:


setValue

Set input value.

public setValue(string $key, mixed $value): void

Parameters:

Parameter Type Description
$key string
$value mixed

hasValue

Given $key and check value exists.

public hasValue(string $key): bool

Parameters:

Parameter Type Description
$key string

getValidator

Get Validator class instance.

public getValidator(): \Qubus\Validation\Validator

resolveInputAttributes

Given $inputs and resolve input attributes.

protected resolveInputAttributes(array $inputs): array

Parameters:

Parameter Type Description
$inputs array

getValidatedData

Get validated data.

public getValidatedData(): array

setValidData

Set valid data.

protected setValidData(\Qubus\Validation\Attribute $attribute, mixed $value): void

Parameters:

Parameter Type Description
$attribute \Qubus\Validation\Attribute
$value mixed

getValidData

Get valid data.

public getValidData(): array

setInvalidData

Set invalid data.

protected setInvalidData(\Qubus\Validation\Attribute $attribute, mixed $value): void

Parameters:

Parameter Type Description
$attribute \Qubus\Validation\Attribute
$value mixed

getInvalidData

Get invalid data.

public getInvalidData(): array

Inherited methods

setMessage

Given $key and $message to set message.

public setMessage(mixed $key, mixed $message): void

Parameters:

Parameter Type Description
$key mixed
$message mixed

setMessages

Given $messages and set multiple messages.

public setMessages(array $messages): void

Parameters:

Parameter Type Description
$messages array

getMessage

Given message from given $key.

public getMessage(string $key): string

Parameters:

Parameter Type Description
$key string

getMessages

Get all $messages

public getMessages(): array

setTranslation

Given $key and $translation to set translation

public setTranslation(mixed $key, mixed $translation): void

Parameters:

Parameter Type Description
$key mixed
$translation mixed

setTranslations

Given $translations and set multiple translations

public setTranslations(array $translations): void

Parameters:

Parameter Type Description
$translations array

getTranslation

Given translation from given $key

public getTranslation(string $key): string

Parameters:

Parameter Type Description
$key string

getTranslations

Get all $translations

public getTranslations(): array