PHP Класс Fuel\Validation\Validator

С версии: 2.0
Автор: Fuel Development Team
Наследование: implements Fuel\Validation\ValidatableInterface
Показать файл Открыть проект Примеры использования класса

Защищенные свойства (Protected)

Свойство Тип Описание
$customRules string[] Contains a list of any custom validation rules
$fields Fuel\Validation\FieldInterface[] Contains a list of fields to be validated
$lastAddedField Fuel\Validation\FieldInterface Keeps track of the last field added for magic method chaining
$lastAddedRule Fuel\Validation\RuleInterface Keeps track of the last rule added for message setting
$messages string[]
$ruleNamespace string Default namespace to look for rules in when a rule is not known

Открытые методы

Метод Описание
__call ( string $name, array $arguments ) Allows validation rules to be dynamically added using method chaining.
addCustomRule ( string $name, string $class ) Adds custom validation rules and allows for core rules to be overridden.
addField ( string | Fuel\Validation\FieldInterface $field, string $label = null ) Adds a new field to the validation object
addRule ( string | Fuel\Validation\FieldInterface $field, Fuel\Validation\RuleInterface $rule ) Adds a rule that can be used to validate a field
createRuleInstance ( string $name, mixed $parameters = [] ) : Fuel\Validation\RuleInterface Creates an instance of the given rule name
getField ( $name ) : Fuel\Validation\FieldInterface Returns the given field
getFieldRules ( string $fieldName ) : Fuel\Validation\RuleInterface[]
getGlobalMessage ( string $ruleName ) : null | string Gets the global message set for a rule
removeGlobalMessage ( string $ruleName ) Removes a global rule message
run ( array $data, Fuel\Validation\ResultInterface $result = null ) : Fuel\Validation\ResultInterface Takes an array of data and validates that against the assigned rules.
runField ( string $field, array $data, Fuel\Validation\ResultInterface $result = null ) : Fuel\Validation\ResultInterface Takes a field name and an array of data and validates the field against the assigned rules.
setGlobalMessage ( string $ruleName, string | null $message ) Sets a custom message for all fields of the given type that are created after the message has been set.
setGlobalMessages ( string[] $messages ) Sets custom messages for one or more rules. Setting the value to "null" will remove the message
setMessage ( string $message ) Sets the failure message for the last added rule

Защищенные методы

Метод Описание
buildMessage ( Fuel\Validation\FieldInterface $field, Fuel\Validation\RuleInterface $rule, $value ) : string Gets a Rule's message and processes that with various tokens
getRuleClassName ( string $name ) : string Returns the full class name for the given validation rule
processMessageTokens ( array $tokens, string $message ) : string Replaces any {} tokens with the matching value from $tokens.
validateField ( string $field, mixed[] $data, Fuel\Validation\ResultInterface $result ) : boolean Validates a single field

Описание методов

__call() публичный Метод

Allows validation rules to be dynamically added using method chaining.
С версии: 2.0
public __call ( string $name, array $arguments )
$name string
$arguments array

addCustomRule() публичный Метод

When wanting to override a core rule just specify the rule name as $name. Eg, 'required', 'minLength'. Note the lowercase first letter. The name of the rule should not contain any whitespace or special characters as the name will be available to use as a function name in the method chaining syntax.
С версии: 2.0
public addCustomRule ( string $name, string $class )
$name string
$class string

addField() публичный Метод

Adds a new field to the validation object
С версии: 2.0
public addField ( string | Fuel\Validation\FieldInterface $field, string $label = null )
$field string | Fuel\Validation\FieldInterface
$label string Field name to use in messages, set to null to use $field

addRule() публичный Метод

Adds a rule that can be used to validate a field
С версии: 2.0
public addRule ( string | Fuel\Validation\FieldInterface $field, Fuel\Validation\RuleInterface $rule )
$field string | Fuel\Validation\FieldInterface
$rule Fuel\Validation\RuleInterface

buildMessage() защищенный Метод

Gets a Rule's message and processes that with various tokens
protected buildMessage ( Fuel\Validation\FieldInterface $field, Fuel\Validation\RuleInterface $rule, $value ) : string
$field Fuel\Validation\FieldInterface
$rule Fuel\Validation\RuleInterface
Результат string

createRuleInstance() публичный Метод

Creates an instance of the given rule name
С версии: 2.0
public createRuleInstance ( string $name, mixed $parameters = [] ) : Fuel\Validation\RuleInterface
$name string
$parameters mixed
Результат Fuel\Validation\RuleInterface

getField() публичный Метод

Returns the given field
С версии: 2.0
public getField ( $name ) : Fuel\Validation\FieldInterface
$name
Результат Fuel\Validation\FieldInterface

getFieldRules() публичный Метод

public getFieldRules ( string $fieldName ) : Fuel\Validation\RuleInterface[]
$fieldName string
Результат Fuel\Validation\RuleInterface[]

getGlobalMessage() публичный Метод

Gets the global message set for a rule
public getGlobalMessage ( string $ruleName ) : null | string
$ruleName string
Результат null | string Will be null if there is no message

getRuleClassName() защищенный Метод

Returns the full class name for the given validation rule
С версии: 2.0
protected getRuleClassName ( string $name ) : string
$name string
Результат string

processMessageTokens() защищенный Метод

Replaces any {} tokens with the matching value from $tokens.
С версии: 2.0
protected processMessageTokens ( array $tokens, string $message ) : string
$tokens array Associative array of token names and values
$message string
Результат string

removeGlobalMessage() публичный Метод

Removes a global rule message
С версии: 2.0
public removeGlobalMessage ( string $ruleName )
$ruleName string

run() публичный Метод

The array is expected to have keys named after fields. This function will call reset() before it runs.
С версии: 2.0
public run ( array $data, Fuel\Validation\ResultInterface $result = null ) : Fuel\Validation\ResultInterface
$data array
$result Fuel\Validation\ResultInterface
Результат Fuel\Validation\ResultInterface

runField() публичный Метод

The array is expected to have keys named after fields. This function will call reset() before it runs.
С версии: 2.0
public runField ( string $field, array $data, Fuel\Validation\ResultInterface $result = null ) : Fuel\Validation\ResultInterface
$field string
$data array
$result Fuel\Validation\ResultInterface
Результат Fuel\Validation\ResultInterface

setGlobalMessage() публичный Метод

Sets a custom message for all fields of the given type that are created after the message has been set.
С версии: 2.0
public setGlobalMessage ( string $ruleName, string | null $message )
$ruleName string Name of the rule to set a message for, eg, required, number, exactLength
$message string | null Set to null to disable the custom message

setGlobalMessages() публичный Метод

Sets custom messages for one or more rules. Setting the value to "null" will remove the message
С версии: 2.0
public setGlobalMessages ( string[] $messages )
$messages string[]

setMessage() публичный Метод

Sets the failure message for the last added rule
С версии: 2.0
public setMessage ( string $message )
$message string

validateField() защищенный Метод

Validates a single field
С версии: 2.0
protected validateField ( string $field, mixed[] $data, Fuel\Validation\ResultInterface $result ) : boolean
$field string
$data mixed[]
$result Fuel\Validation\ResultInterface
Результат boolean

Описание свойств

$customRules защищенное свойство

Contains a list of any custom validation rules
protected string[] $customRules
Результат string[]

$fields защищенное свойство

Contains a list of fields to be validated
protected FieldInterface[],Fuel\Validation $fields
Результат Fuel\Validation\FieldInterface[]

$lastAddedField защищенное свойство

Keeps track of the last field added for magic method chaining
protected FieldInterface,Fuel\Validation $lastAddedField
Результат Fuel\Validation\FieldInterface

$lastAddedRule защищенное свойство

Keeps track of the last rule added for message setting
protected RuleInterface,Fuel\Validation $lastAddedRule
Результат Fuel\Validation\RuleInterface

$messages защищенное свойство

protected string[] $messages
Результат string[]

$ruleNamespace защищенное свойство

Default namespace to look for rules in when a rule is not known
protected string $ruleNamespace
Результат string