PHP 클래스 Valitron\Validator

Validates input against certain criteria
저자: Vance Lucas ([email protected])
파일 보기 프로젝트 열기: vlucas/valitron 1 사용 예제들

보호된 프로퍼티들

프로퍼티 타입 설명
$_errors array
$_fields array
$_instanceRuleMessage array Contains all rule messages that are available to the current valitron instance
$_instanceRules array Contains all rules that are available to the current valitron instance.
$_labels array
$_lang string
$_langDir string
$_ruleMessages array
$_rules array
$_validations array
$validUrlPrefixes array

공개 메소드들

메소드 설명
__construct ( array $data, array $fields = [], string $lang = null, string $langDir = null ) Setup validation
addInstanceRule ( string $name, mixed $callback, string $message = null ) Adds a new validation rule callback that is tied to the current instance only.
addRule ( string $name, mixed $callback, string $message = null ) Register new validation rule callback
data ( ) : array Get array of fields and data
error ( string $field, string $msg, array $params = [] ) Add an error to error messages array
errors ( null | string $field = null ) : array | boolean Get array of error messages
getUniqueRuleName ( $fields )
hasValidator ( string $name ) : boolean Returns true if either a valdiator with the given name has been registered or there is a default validator by that name.
label ( string $value )
labels ( array $labels = [] )
lang ( string $lang = null ) : string Get/set language to use for validation messages
langDir ( string $dir = null ) : string Get/set language file path
message ( string $msg ) Specify validation message to use for error for the last validation rule
reset ( ) Reset object properties
rule ( string | callback $rule, array $fields ) Convenience method to add a single validation rule
rules ( array $rules ) Convenience method to add multiple validation rules with an array
validate ( ) : boolean Run validations and return boolean result
withData ( array $data, array $fields = [] ) : Valitron Replace data on cloned instance

보호된 메소드들

메소드 설명
assertRuleCallback ( $callback )
checkAndSetLabel ( string $field, string $msg, array $params ) : array
getPart ( $data, $identifiers )
getRuleMessages ( ) : array Returns all rule message, the static and instance ones.
getRules ( ) : array Returns all rule callbacks, the static and instance ones.
hasRule ( string $name, string $field ) : boolean Determine whether a field is being validated by the given rule.
stringLength ( string $value ) : integer | false Get the length of a string
validateAccepted ( string $field, mixed $value ) : boolean Validate that a field was "accepted" (based on PHP's string evaluation rules)
validateAlpha ( string $field, mixed $value ) : boolean Validate that a field contains only alphabetic characters
validateAlphaNum ( string $field, mixed $value ) : boolean Validate that a field contains only alpha-numeric characters
validateArray ( string $field, mixed $value ) : boolean Validate that a field is an array
validateBetween ( string $field, mixed $value, array $params ) : boolean Validate the size of a field is between min and max values
validateBoolean ( string $field, mixed $value ) : boolean Validate that a field contains a boolean.
validateContains ( string $field, mixed $value, array $params ) : boolean Validate a field contains a given string
validateCreditCard ( string $field, mixed $value, array $params ) : boolean Validate that a field contains a valid credit card optionally filtered by an array
validateDate ( string $field, mixed $value ) : boolean Validate that a field is a valid date
validateDateAfter ( string $field, mixed $value, array $params ) : boolean Validate the date is after a given date
validateDateBefore ( string $field, mixed $value, array $params ) : boolean Validate the date is before a given date
validateDateFormat ( string $field, mixed $value, array $params ) : boolean Validate that a field matches a date format
validateDifferent ( string $field, mixed $value, array $params ) : boolean Validate that a field is different from another field
validateEmail ( string $field, mixed $value ) : boolean Validate that a field is a valid e-mail address
validateEquals ( string $field, mixed $value, array $params ) : boolean Validate that two values match
validateIn ( string $field, mixed $value, array $params ) : boolean Validate a field is contained within a list of values
validateInstanceOf ( $field, $value, $params )
validateInteger ( string $field, mixed $value ) : boolean Validate that a field is an integer
validateIp ( string $field, mixed $value ) : boolean Validate that a field is a valid IP address
validateLength ( string $field, mixed $value, array $params ) : boolean Validate the length of a string
validateLengthBetween ( string $field, mixed $value, array $params ) : boolean Validate the length of a string (between)
validateLengthMax ( string $field, mixed $value, array $params ) : boolean Validate the length of a string (max)
validateLengthMin ( string $field, mixed $value, array $params ) : boolean Validate the length of a string (min)
validateMax ( string $field, mixed $value, array $params ) : boolean Validate the size of a field is less than a maximum value
validateMin ( string $field, mixed $value, array $params ) : boolean Validate the size of a field is greater than a minimum value.
validateNotIn ( string $field, mixed $value, array $params ) : boolean Validate a field is not contained within a list of values
validateNumeric ( string $field, mixed $value ) : boolean Validate that a field is numeric
validateOptional ( $field, $value, $params ) Validate optional field
validateRegex ( string $field, mixed $value, array $params ) : boolean Validate that a field passes a regular expression check
validateRequired ( string $field, mixed $value ) : boolean Required field validator
validateSlug ( string $field, mixed $value ) : boolean Validate that a field contains only alpha-numeric characters, dashes, and underscores
validateUrl ( string $field, mixed $value ) : boolean Validate that a field is a valid URL by syntax
validateUrlActive ( string $field, mixed $value ) : boolean Validate that a field is an active URL by verifying DNS record

메소드 상세

__construct() 공개 메소드

Setup validation
public __construct ( array $data, array $fields = [], string $lang = null, string $langDir = null )
$data array
$fields array
$lang string
$langDir string

addInstanceRule() 공개 메소드

Adds a new validation rule callback that is tied to the current instance only.
public addInstanceRule ( string $name, mixed $callback, string $message = null )
$name string
$callback mixed
$message string

addRule() 공개 정적인 메소드

Register new validation rule callback
public static addRule ( string $name, mixed $callback, string $message = null )
$name string
$callback mixed
$message string

assertRuleCallback() 보호된 정적인 메소드

protected static assertRuleCallback ( $callback )

checkAndSetLabel() 보호된 메소드

protected checkAndSetLabel ( string $field, string $msg, array $params ) : array
$field string
$msg string
$params array
리턴 array

data() 공개 메소드

Get array of fields and data
public data ( ) : array
리턴 array

error() 공개 메소드

Add an error to error messages array
public error ( string $field, string $msg, array $params = [] )
$field string
$msg string
$params array

errors() 공개 메소드

Get array of error messages
public errors ( null | string $field = null ) : array | boolean
$field null | string
리턴 array | boolean

getPart() 보호된 메소드

protected getPart ( $data, $identifiers )

getRuleMessages() 보호된 메소드

Returns all rule message, the static and instance ones.
protected getRuleMessages ( ) : array
리턴 array

getRules() 보호된 메소드

Returns all rule callbacks, the static and instance ones.
protected getRules ( ) : array
리턴 array

getUniqueRuleName() 공개 메소드

public getUniqueRuleName ( $fields )

hasRule() 보호된 메소드

Determine whether a field is being validated by the given rule.
protected hasRule ( string $name, string $field ) : boolean
$name string The name of the rule
$field string The name of the field
리턴 boolean

hasValidator() 공개 메소드

Returns true if either a valdiator with the given name has been registered or there is a default validator by that name.
public hasValidator ( string $name ) : boolean
$name string
리턴 boolean

label() 공개 메소드

public label ( string $value )
$value string

labels() 공개 메소드

public labels ( array $labels = [] )
$labels array

lang() 공개 정적인 메소드

Get/set language to use for validation messages
public static lang ( string $lang = null ) : string
$lang string
리턴 string

langDir() 공개 정적인 메소드

Get/set language file path
public static langDir ( string $dir = null ) : string
$dir string
리턴 string

message() 공개 메소드

Specify validation message to use for error for the last validation rule
public message ( string $msg )
$msg string

reset() 공개 메소드

Reset object properties
public reset ( )

rule() 공개 메소드

Convenience method to add a single validation rule
public rule ( string | callback $rule, array $fields )
$rule string | callback
$fields array

rules() 공개 메소드

Convenience method to add multiple validation rules with an array
public rules ( array $rules )
$rules array

stringLength() 보호된 메소드

Get the length of a string
protected stringLength ( string $value ) : integer | false
$value string
리턴 integer | false

validate() 공개 메소드

Run validations and return boolean result
public validate ( ) : boolean
리턴 boolean

validateAccepted() 보호된 메소드

This validation rule implies the field is "required"
protected validateAccepted ( string $field, mixed $value ) : boolean
$field string
$value mixed
리턴 boolean

validateAlpha() 보호된 메소드

Validate that a field contains only alphabetic characters
protected validateAlpha ( string $field, mixed $value ) : boolean
$field string
$value mixed
리턴 boolean

validateAlphaNum() 보호된 메소드

Validate that a field contains only alpha-numeric characters
protected validateAlphaNum ( string $field, mixed $value ) : boolean
$field string
$value mixed
리턴 boolean

validateArray() 보호된 메소드

Validate that a field is an array
protected validateArray ( string $field, mixed $value ) : boolean
$field string
$value mixed
리턴 boolean

validateBetween() 보호된 메소드

Validate the size of a field is between min and max values
protected validateBetween ( string $field, mixed $value, array $params ) : boolean
$field string
$value mixed
$params array
리턴 boolean

validateBoolean() 보호된 메소드

Validate that a field contains a boolean.
protected validateBoolean ( string $field, mixed $value ) : boolean
$field string
$value mixed
리턴 boolean

validateContains() 보호된 메소드

Validate a field contains a given string
protected validateContains ( string $field, mixed $value, array $params ) : boolean
$field string
$value mixed
$params array
리턴 boolean

validateCreditCard() 보호된 메소드

Validate that a field contains a valid credit card optionally filtered by an array
protected validateCreditCard ( string $field, mixed $value, array $params ) : boolean
$field string
$value mixed
$params array
리턴 boolean

validateDate() 보호된 메소드

Validate that a field is a valid date
protected validateDate ( string $field, mixed $value ) : boolean
$field string
$value mixed
리턴 boolean

validateDateAfter() 보호된 메소드

Validate the date is after a given date
protected validateDateAfter ( string $field, mixed $value, array $params ) : boolean
$field string
$value mixed
$params array
리턴 boolean

validateDateBefore() 보호된 메소드

Validate the date is before a given date
protected validateDateBefore ( string $field, mixed $value, array $params ) : boolean
$field string
$value mixed
$params array
리턴 boolean

validateDateFormat() 보호된 메소드

Validate that a field matches a date format
protected validateDateFormat ( string $field, mixed $value, array $params ) : boolean
$field string
$value mixed
$params array
리턴 boolean

validateDifferent() 보호된 메소드

Validate that a field is different from another field
protected validateDifferent ( string $field, mixed $value, array $params ) : boolean
$field string
$value mixed
$params array
리턴 boolean

validateEmail() 보호된 메소드

Validate that a field is a valid e-mail address
protected validateEmail ( string $field, mixed $value ) : boolean
$field string
$value mixed
리턴 boolean

validateEquals() 보호된 메소드

Validate that two values match
protected validateEquals ( string $field, mixed $value, array $params ) : boolean
$field string
$value mixed
$params array
리턴 boolean

validateIn() 보호된 메소드

Validate a field is contained within a list of values
protected validateIn ( string $field, mixed $value, array $params ) : boolean
$field string
$value mixed
$params array
리턴 boolean

validateInstanceOf() 보호된 메소드

protected validateInstanceOf ( $field, $value, $params )

validateInteger() 보호된 메소드

Validate that a field is an integer
protected validateInteger ( string $field, mixed $value ) : boolean
$field string
$value mixed
리턴 boolean

validateIp() 보호된 메소드

Validate that a field is a valid IP address
protected validateIp ( string $field, mixed $value ) : boolean
$field string
$value mixed
리턴 boolean

validateLength() 보호된 메소드

Validate the length of a string
protected validateLength ( string $field, mixed $value, array $params ) : boolean
$field string
$value mixed
$params array
리턴 boolean

validateLengthBetween() 보호된 메소드

Validate the length of a string (between)
protected validateLengthBetween ( string $field, mixed $value, array $params ) : boolean
$field string
$value mixed
$params array
리턴 boolean

validateLengthMax() 보호된 메소드

Validate the length of a string (max)
protected validateLengthMax ( string $field, mixed $value, array $params ) : boolean
$field string
$value mixed
$params array
리턴 boolean

validateLengthMin() 보호된 메소드

Validate the length of a string (min)
protected validateLengthMin ( string $field, mixed $value, array $params ) : boolean
$field string
$value mixed
$params array
리턴 boolean

validateMax() 보호된 메소드

Validate the size of a field is less than a maximum value
protected validateMax ( string $field, mixed $value, array $params ) : boolean
$field string
$value mixed
$params array
리턴 boolean

validateMin() 보호된 메소드

Validate the size of a field is greater than a minimum value.
protected validateMin ( string $field, mixed $value, array $params ) : boolean
$field string
$value mixed
$params array
리턴 boolean

validateNotIn() 보호된 메소드

Validate a field is not contained within a list of values
protected validateNotIn ( string $field, mixed $value, array $params ) : boolean
$field string
$value mixed
$params array
리턴 boolean

validateNumeric() 보호된 메소드

Validate that a field is numeric
protected validateNumeric ( string $field, mixed $value ) : boolean
$field string
$value mixed
리턴 boolean

validateOptional() 보호된 메소드

Validate optional field
protected validateOptional ( $field, $value, $params )

validateRegex() 보호된 메소드

Validate that a field passes a regular expression check
protected validateRegex ( string $field, mixed $value, array $params ) : boolean
$field string
$value mixed
$params array
리턴 boolean

validateRequired() 보호된 메소드

Required field validator
protected validateRequired ( string $field, mixed $value ) : boolean
$field string
$value mixed
리턴 boolean

validateSlug() 보호된 메소드

Validate that a field contains only alpha-numeric characters, dashes, and underscores
protected validateSlug ( string $field, mixed $value ) : boolean
$field string
$value mixed
리턴 boolean

validateUrl() 보호된 메소드

Validate that a field is a valid URL by syntax
protected validateUrl ( string $field, mixed $value ) : boolean
$field string
$value mixed
리턴 boolean

validateUrlActive() 보호된 메소드

Validate that a field is an active URL by verifying DNS record
protected validateUrlActive ( string $field, mixed $value ) : boolean
$field string
$value mixed
리턴 boolean

withData() 공개 메소드

Replace data on cloned instance
public withData ( array $data, array $fields = [] ) : Valitron
$data array
$fields array
리턴 Valitron

프로퍼티 상세

$_errors 보호되어 있는 프로퍼티

protected array $_errors
리턴 array

$_fields 보호되어 있는 프로퍼티

protected array $_fields
리턴 array

$_instanceRuleMessage 보호되어 있는 프로퍼티

Contains all rule messages that are available to the current valitron instance
protected array $_instanceRuleMessage
리턴 array

$_instanceRules 보호되어 있는 프로퍼티

Contains all rules that are available to the current valitron instance.
protected array $_instanceRules
리턴 array

$_labels 보호되어 있는 프로퍼티

protected array $_labels
리턴 array

$_lang 보호되어 있는 정적으로 프로퍼티

protected static string $_lang
리턴 string

$_langDir 보호되어 있는 정적으로 프로퍼티

protected static string $_langDir
리턴 string

$_ruleMessages 보호되어 있는 정적으로 프로퍼티

protected static array $_ruleMessages
리턴 array

$_rules 보호되어 있는 정적으로 프로퍼티

protected static array $_rules
리턴 array

$_validations 보호되어 있는 프로퍼티

protected array $_validations
리턴 array

$validUrlPrefixes 보호되어 있는 프로퍼티

protected array $validUrlPrefixes
리턴 array