PHP Class Controller_Validator_Abstract, atk4

If you are writing your own validator rules to a very specific objects, you can use extend either this class or Validator_Basic. NOTE: How to write rules: Do not attempt to put all the rules for a single field on a line. Many rules will change the value of acumulator, so please add as many rules as necessary is(array( 'name|len|gt|20', 'name|!rude', 'name|to_ucfirst', )); Finally - you can add one validator inside another to extends it's rules.
Inheritance: extends AbstractController
Show file Open project: atk4/atk4 Class Usage Examples

Public Properties

Property Type Description
$acc Next are system fields, do not access when in doubt.
$active_field Name of the field which is currently beind processed.
$alias $alias['mandatory']='required'; $alias['must_have']='required';
$bail_out
$caption
$cast
$consumed
$current_ruleset
$custom_error
$custom_hook Call this to set a different hook when rules are going to be applied. By default you have to call now() on() used by default for when validator is added, however if you call it manually (avoiding 3rd argument) it will override the default hook. This is done to avoid double-validation
$default_exception
$has_hook
$prefix When transformivg value (such as len) - will contain a modifier to the error message.
$rules Each ruleset is broken down by field and is stored in this array in a normal form. You can get rules for a particular field by calling $this->getRules(field);.
$source Validator can check either a model, array, form or any other object as long as it supports array_access. If you are using Model then you can use some additional functionality foreach selecting fields.

Public Methods

Method Description
applyRules ( $field, $ruleset ) This is the main body for rule processing.
applyRulesets ( ) Go through the list of defined rules and call the corresponding filters and convertors.
expandFieldDefinition ( $field_definition, &$normalized_rules ) Provided with a multiple field definition, this will convert them into an array.
fail ( ) {{{ Methods which are called by the rules
get ( $field ) Returns the original value of the field.
getActualFields ( ) Get list of fields which we are going to validate. In some cases it makes no sense to validate fields which are not appearing individually the form, therefore this method will look carefully at what you are validating.
getRules ( $field ) Call this to get list of parsed rules for specified field.
init ( ) {{{ Initialization method
is ( ) This method will go through all the rules you specify, expand and normalize them and assign into array indexed by field name.
normalizeRules ( $rules ) Provided with string containing rules, this will convert it into normal (array) form.
now ( ) Apply rules now.
on ( $hook, $object = null, $default_hook = false )
pullRule ( $alias = false ) Pulls next rule out of the rule stack (current_ruleset) May allow alias ($name).
pushRule ( ) Adds new rule into a rule-set, which will be executed next.
resolveRuleAlias ( $rule )
rule_caption ( $a ) }}}
rule_fail ( ) The only rule in Validator_Abstract. Will fail.
set ( $field, $value ) Changes the original value of the field (for normalization).
setSource ( $source ) If you are adding this Controller inside a Model, you don't need to set source. If you want controller to work with an array or some other object, use setSource().
stop ( )

Method Details

applyRules() public method

This is the main body for rule processing.
public applyRules ( $field, $ruleset )

applyRulesets() public method

Go through the list of defined rules and call the corresponding filters and convertors.
public applyRulesets ( )

expandFieldDefinition() public method

In: "name,surname,foo" (Basic) In: "%boolean,-@address" (Advanced) Out: array('name','surname','foo')
public expandFieldDefinition ( $field_definition, &$normalized_rules )

fail() public method

{{{ Methods which are called by the rules
public fail ( )

get() public method

Returns the original value of the field.
public get ( $field )

getActualFields() public method

Get list of fields which we are going to validate. In some cases it makes no sense to validate fields which are not appearing individually the form, therefore this method will look carefully at what you are validating.
public getActualFields ( )

getRules() public method

Call this to get list of parsed rules for specified field.
public getRules ( $field )

init() public method

{{{ Initialization method
public init ( )

is() public method

You do not need to have your fields defined at this point, unless you specify wildcards. This method takes various arguments as described in documentation.
public is ( )

normalizeRules() public method

In: "int|required|alphanum|save" (Basic) In: "int!|a-z|" (Advanced) Out: array('int','required','alphanum','save')
public normalizeRules ( $rules )

now() public method

Apply rules now.
public now ( )

on() public method

public on ( $hook, $object = null, $default_hook = false )

pullRule() public method

Pulls next rule out of the rule stack (current_ruleset) May allow alias ($name).
public pullRule ( $alias = false )

pushRule() public method

You can specify single or multiple rules, this method accepts variable arguments. Rules must be normalized.
public pushRule ( )

resolveRuleAlias() public method

public resolveRuleAlias ( $rule )

rule_caption() public method

}}}
public rule_caption ( $a )

rule_fail() public method

The only rule in Validator_Abstract. Will fail.
public rule_fail ( )

set() public method

Changes the original value of the field (for normalization).
public set ( $field, $value )

setSource() public method

If you are adding this Controller inside a Model, you don't need to set source. If you want controller to work with an array or some other object, use setSource().
public setSource ( $source )

stop() public method

public stop ( )

Property Details

$acc public property

Next are system fields, do not access when in doubt.
public $acc

$active_field public property

Name of the field which is currently beind processed.
public $active_field

$alias public property

$alias['mandatory']='required'; $alias['must_have']='required';
public $alias

$bail_out public property

public $bail_out

$caption public property

public $caption

$cast public property

public $cast

$consumed public property

public $consumed

$current_ruleset public property

public $current_ruleset

$custom_error public property

public $custom_error

$custom_hook public property

Call this to set a different hook when rules are going to be applied. By default you have to call now() on() used by default for when validator is added, however if you call it manually (avoiding 3rd argument) it will override the default hook. This is done to avoid double-validation
public $custom_hook

$default_exception public property

public $default_exception

$has_hook public property

public $has_hook

$prefix public property

When transformivg value (such as len) - will contain a modifier to the error message.
public $prefix

$rules public property

Each ruleset is broken down by field and is stored in this array in a normal form. You can get rules for a particular field by calling $this->getRules(field);.
public $rules

$source public property

Validator can check either a model, array, form or any other object as long as it supports array_access. If you are using Model then you can use some additional functionality foreach selecting fields.
public $source