Overview

Namespaces

  • None
  • PHP
  • Wei
    • Validator

Classes

  • Apc
  • App
  • ArrayCache
  • Asset
  • Base
  • BaseCache
  • Bicache
  • Cache
  • Config
  • Cookie
  • Couchbase
  • Counter
  • Db
  • DbCache
  • E
  • Env
  • Error
  • FileCache
  • Gravatar
  • Http
  • Lock
  • Logger
  • Memcache
  • Memcached
  • MongoCache
  • Password
  • PhpError
  • Pinyin
  • Record
  • Redis
  • Request
  • Response
  • Router
  • SafeUrl
  • Session
  • Soap
  • T
  • Ua
  • Upload
  • Url
  • Uuid
  • Validate
  • View
  • WeChatApp
  • Wei
  • Overview
  • Namespace
  • Class
  • Tree

Class Validate

A validator service

Wei\Base
Extended by Wei\Validate
Namespace: Wei
Author: Twin Huang twinhuang@qq.com
Located at Validate.php
Methods summary
public mixed
# __invoke( array $options = array() )

Create a new validator and validate by specified options

Create a new validator and validate by specified options

Parameters

$options

Returns

mixed
$this
public boolean
# valid( array $options = array() )

Validate the data by the given options

Validate the data by the given options

Parameters

$options
The options for validation

Returns

boolean
Whether pass the validation or not

Throws

InvalidArgumentException
When validation rule is not array, string or instance of BaseValidator
protected array
# prepareProps( string $field, string $rule )

Prepare name and messages property option for rule validator

Prepare name and messages property option for rule validator

Parameters

$field
$rule

Returns

array
public mixed
# addValidRule( string $field, string $rule )

Add valid rule

Add valid rule

Parameters

$field
The field name
$rule
The rule name

Returns

mixed
$this
public mixed
# addInvalidRule( string $field, string $rule )

Add invalid rule

Add invalid rule

Parameters

$field
The field name
$rule
The rule name

Returns

mixed
$this
public array
# getValidFields( )

Returns the valid fields

Returns the valid fields

Returns

array
public array
# getInvalidFields( )

Returns the invalid fields

Returns the invalid fields

Returns

array
public boolean
# isFieldValid( string $field )

Check if field is valid

Check if field is valid

Parameters

$field

Returns

boolean
public boolean
# isFieldInvalid( string $field )

Check if field is invalid

Check if field is invalid

Parameters

$field

Returns

boolean
public mixed
# setRules( array $rules = null )

Set field rules

Set field rules

Parameters

$rules

Returns

mixed
$this
public array
# getRules( )

Get validator rules

Get validator rules

Returns

array
public array
# getFieldRules( string $field )

Get validator rules by specified field

Get validator rules by specified field

Parameters

$field

Returns

array
public array
# getRuleParams( string $field, string $rule )

Get validation rule parameters

Get validation rule parameters

Parameters

$field
The validation field
$rule
The validation rule

Returns

array
public array
# getValidRules( string $field )

Get valid rules by field

Get valid rules by field

Parameters

$field

Returns

array
public array
# getInvalidRules( string $field = null )

Get invalid rules by field

Get invalid rules by field

Parameters

$field

Returns

array
public boolean
# isValid( )

Returns the validation result

Returns the validation result

Returns

boolean
public
# addRule( string $field, string $rule, mixed $parameters )

Adds rule for specified field

Adds rule for specified field

Parameters

$field
The name of field
$rule
The name of rule
$parameters
The parameters for rule
public boolean
# hasRule( string $field, string $rule )

Returns whether the validation rule exists in specified field

Returns whether the validation rule exists in specified field

Parameters

$field
$rule

Returns

boolean
public boolean
# removeRule( string $field, string $rule )

Removes the rule in field

Removes the rule in field

Parameters

$field
The name of field
$rule
The name of rule

Returns

boolean
public boolean
# removeField( string $field )

Removes the validate field

Removes the validate field

Parameters

$field

Returns

boolean
public mixed
# setData( array|object $data )

Sets data for validation

Sets data for validation

Parameters

$data

Returns

mixed
$this

Throws

InvalidArgumentException
when argument type is not array or object
public array
# getData( )

Returns validation data

Returns validation data

Returns

array
public mixed
# getFieldData( string $field )

Returns validation field data

Returns validation field data

Parameters

$field
The name of field

Returns

mixed
public mixed
# setFieldData( string $field, mixed $data )

Sets data for validation field

Sets data for validation field

Parameters

$field
The name of field
$data
The data of field

Returns

mixed
$this
public mixed
# setMessages( array $messages = null )

Set custom messages

Set custom messages

Parameters

$messages

Returns

mixed
$this
public array
# getMessages( )

Returns custom message

Returns custom message

Returns

array
public array
# getDetailMessages( )

Returns detail invalid messages

Returns detail invalid messages

Returns

array
public array
# getSummaryMessages( )

Returns summary invalid messages

Returns summary invalid messages

Returns

array
public string
# getJoinedMessage( string $separator = "\n" )

Returns error message string connected by specified separator

Returns error message string connected by specified separator

Parameters

$separator

Returns

string
public false|string
# getFirstMessage( )

Returns the first error message string

Returns the first error message string

Returns

false|string
public Wei\Validator\BaseValidator
# getRuleValidator( string $field, string $rule )

Returns the rule validator object

Returns the rule validator object

Parameters

$field
$rule

Returns

Wei\Validator\BaseValidator
public
# setNames( array $names )

Sets field names

Sets field names

Parameters

$names
public array
# getNames( )

Returns field names

Returns field names

Returns

array
public boolean
# validateOne( string|Wei\Validator\BaseValidator|integer $rule, array|null $input, mixed $options = array(), null & $validator = null, array $props = array() )

Parameters

$rule
$input
$options
$validator
$validator
$props

Returns

boolean
public Wei\Validator\BaseValidator
# createRuleValidator( string $rule, array $options = array() )

Create a rule validator instance by specified rule name

Create a rule validator instance by specified rule name

Parameters

$rule
The name of rule validator
$options
The property options for rule validator

Returns

Wei\Validator\BaseValidator

Throws

InvalidArgumentException
When validator not found
Methods inherited from Wei\Base
__call(), __construct(), __get(), getOption(), setOption()
Properties summary
protected array $rules

The validation rules

The validation rules

# array()
protected array $data

The data to be validated

The data to be validated

# array()
protected array $messages

The invalid messages

The invalid messages

# array()
protected array $names

The names for messages

The names for messages

# array()
protected callable $beforeValidate

The callback triggered before validation

The callback triggered before validation

#
protected callable $ruleValid

The callback triggered when every rule is valid

The callback triggered when every rule is valid

#
protected callable $ruleInvalid

The callback triggered when every rule is invalid

The callback triggered when every rule is invalid

#
protected callable $fieldValid

The callback triggered when every field is valid

The callback triggered when every field is valid

#
protected callable $fieldInvalid

The callback triggered when every field is invalid

The callback triggered when every field is invalid

#
protected callable $success

The callback triggered after all rules are valid

The callback triggered after all rules are valid

#
protected callable $failure

The callback triggered when the validation is invalid

The callback triggered when the validation is invalid

#
protected boolean $breakRule

Whether break the validation flow when any field's rule is not valid

Whether break the validation flow when any field's rule is not valid

# false
protected boolean $breakField

Whether break the validation flow when any field is not valid

Whether break the validation flow when any field is not valid

# false
protected boolean $skip

Whether skip the current field validation when the filed's rule is not valid, so every field contains one invalid rule at most

Whether skip the current field validation when the filed's rule is not valid, so every field contains one invalid rule at most

# false
protected string $validRules

The valid rules array, which use the field as key, and the rules as value

The valid rules array, which use the field as key, and the rules as value

# array()
protected string $invalidRules

The invalid rules array, which use the field as key, and the rules as value

The invalid rules array, which use the field as key, and the rules as value

# array()
protected boolean|null $result

The validation result

The validation result

#
protected array<Validator\BaseValidator> $ruleValidators

The rule validator instances

The rule validator instances

# array()
Properties inherited from Wei\Base
$providers, $wei
Wei Framework API documentation generated by ApiGen