pclib  3.0.0
Lightweight PHP framework
Public Member Functions | Data Fields | Protected Member Functions | Protected Attributes
ValidatorBase Class Reference

Base class for any pclib Validator. More...

Inheritance diagram for ValidatorBase:
BaseObject Validator

Public Member Functions

 setRule ($name, $function, $message)
 Set or add new rule. More...
 
 hasRule ($rule)
 Check if validator has handler for rule $rule. More...
 
 setError ($id, $messageId, array $args=array())
 Set error message for element $id. More...
 
 getErrors ()
 Return validation errors.
 
 isBlank ($value)
 Check if field is blank (not filled).
 
 notBlank ($value)
 NOT isBlank().
 
 validate ($value, $rules)
 Validate $value against $rules. More...
 
 validateElement ($value, array $elem)
 Validate $value against $elem rules. More...
 
 validateArray (array $values, array $elements)
 Validate array of values, using validation rules in $elements. More...
 
- Public Member Functions inherited from BaseObject
 loadDefaults ($className=null)
 Load default parameters of class $className into object instance.
 
 setProperties (array $defaults)
 Set public properties of object from the array. More...
 
 toArray ()
 Convert object to array. More...
 

Data Fields

 $skipUndefined = false
 Are variables undefined in template valid?
 
 $skipUndefinedRule = false
 Silently skip unknown rules?
 
 $ignoredAttributes = array('id', 'type', 'begin', 'end')
 List of ignored attributes (rules)
 
 $ignoredElements = array()
 List of ignored element types.
 
 $messages
 Array of messages [ruleName: message, ...].
 
 $translator
 var Translator
 
- Data Fields inherited from BaseObject
 $serviceLocator
 var function() Return service object when requested with service().
 

Protected Member Functions

 validateRule ($value, $rule, $param=null)
 Validate $value using $rule. More...
 
- Protected Member Functions inherited from BaseObject
 service ($service, $default=null)
 Try acquire $service and load it into property $this->$service. More...
 

Protected Attributes

 $rules = array()
 Array of rule handlers [ruleName: callable, ...].
 
 $errors = array()
 Array of [fieldName: errorMessage, ...].
 
 $parser
 var TplParser
 

Additional Inherited Members

- Static Public Member Functions inherited from BaseObject
static defaults ()
 Set or retireve default parameters of the object. More...
 

Detailed Description

Base class for any pclib Validator.

Features:

Member Function Documentation

◆ hasRule()

hasRule (   $rule)

Check if validator has handler for rule $rule.

Parameters
string$ruleRule name

◆ setError()

setError (   $id,
  $messageId,
array  $args = array() 
)

Set error message for element $id.

Called when validation of element's value failed.

Parameters
string$idElement-id
string$messageIdId such as 'email', 'required' or full message text

◆ setRule()

setRule (   $name,
  $function,
  $message 
)

Set or add new rule.

Parameters
string$nameRule name
callable$functionRule handler
string$messageRule error message

◆ validate()

validate (   $value,
  $rules 
)

Validate $value against $rules.

Example: validate('1.1.2016', 'date required')

Parameters
mixed$value
string$rules
Returns
bool isValid

◆ validateArray()

validateArray ( array  $values,
array  $elements 
)

Validate array of values, using validation rules in $elements.

Set $this->errors array.

Parameters
array$values[id => value, ...]
array$elements[id => array_of_rules, ...]
Returns
bool isValid

◆ validateElement()

validateElement (   $value,
array  $elem 
)

Validate $value against $elem rules.

Parameters
mixed$value
array$elem[rule => param, ...] e.g. ['date' => 1, 'required' => 1]
Returns
bool isValid

◆ validateRule()

validateRule (   $value,
  $rule,
  $param = null 
)
protected

Validate $value using $rule.

Example: validateRule('1.1.2016', 'date', 'd.m.Y')

Parameters
mixed$value
string$rule
mixed$paramRule parameters
Returns
bool isValid

The documentation for this class was generated from the following file: