PHP 클래스 Fuel\Validation\Validator

부터: 2.0
저자: Fuel Development Team
상속: implements Fuel\Validation\ValidatableInterface
파일 보기 프로젝트 열기: fuelphp/validation 1 사용 예제들

보호된 프로퍼티들

프로퍼티 타입 설명
$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