Skip to content

Validator


  • Full name: \Qubus\Validation\Validator

Properties

translations

protected array $translations

validators

protected array $validators

allowRuleOverride

protected bool $allowRuleOverride

useHumanizedKeys

protected bool $useHumanizedKeys

Methods

__construct

public __construct(array $messages = []): void

Parameters:

Parameter Type Description
$messages array

setValidator

Register or override existing validator.

public setValidator(mixed $key, \Qubus\Validation\Rule $rule): void

Parameters:

Parameter Type Description
$key mixed
$rule \Qubus\Validation\Rule

getValidator

Get validator object from given $key.

public getValidator(mixed $key): mixed

Parameters:

Parameter Type Description
$key mixed

validate

Validate $inputs.

public validate(array $inputs, array $rules, array $messages = []): \Qubus\Validation\Validation

Parameters:

Parameter Type Description
$inputs array
$rules array
$messages array

Throws:


make

Given $inputs, $rules and $messages to make the Validation class instance.

public make(array $inputs, array $rules, array $messages = []): \Qubus\Validation\Validation

Parameters:

Parameter Type Description
$inputs array
$rules array
$messages array

Throws:


__invoke

Magic invoke method to make Rule instance.

public __invoke(string $rule): \Qubus\Validation\Rule

Parameters:

Parameter Type Description
$rule string

Throws:


registerBaseValidators

Initialize base validators array.

protected registerBaseValidators(): void

addValidator

Given $ruleName and $rule to add new validator.

public addValidator(string $ruleName, \Qubus\Validation\Rule $rule): void

Parameters:

Parameter Type Description
$ruleName string
$rule \Qubus\Validation\Rule

Throws:


allowRuleOverride

Set rule can allow to be overridden.

public allowRuleOverride(bool $status = false): void

Parameters:

Parameter Type Description
$status bool

setUseHumanizedKeys

Set this can use humanize keys.

public setUseHumanizedKeys(bool $useHumanizedKeys = true): void

Parameters:

Parameter Type Description
$useHumanizedKeys bool

isUsingHumanizedKey

Get $this->useHumanizedKeys value.

public isUsingHumanizedKey(): bool

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