pclib  2.3.2
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...
 
 addEvent ($name, $callback)
 Add event handler to $object->$name property. 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
 
 $onValidateElement
 Occurs before element validation. More...
 
- Data Fields inherited from BaseObject
 $onNewInstance
 Occurs when new instance of the class is created. More...
 
 $onMissingMethod
 Occurs when called method does not exist. More...
 
 $serviceLocator
 var function() Return service object when requested with service(). More...
 

Protected Member Functions

 validateRule ($value, $rule, $param=null)
 Validate $value using $rule. More...
 
- Protected Member Functions inherited from BaseObject
 fireEvent ($name, array $args=array())
 Run all event handlers in $object->$name property. More...
 
 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 (   $rule)

Check if validator has handler for rule $rule.

Parameters
string$ruleRule name
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 (   $name,
  $function,
  $message 
)

Set or add new rule.

Parameters
string$nameRule name
callable$functionRule handler
string$messageRule error message
validate (   $value,
  $rules 
)

Validate $value against $rules.

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

Parameters
mixed$value
string$rules
Returns
bool isValid
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 (   $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 (   $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

Field Documentation

$onValidateElement

Occurs before element validation.


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