ZenMagick 0.9.10


org.zenmagick.mvc.validation\ZMValidator
mvc\validation\ZMValidator.php at line 30

Class ZMValidator

ZMObject
└─ZMValidator

public class ZMValidator
extends ZMObject

A validator framework.

Author:
DerManoMann

Fields inherited from org.zenmagick.core\ZMObject
properties_
Method Summary
void

__construct()

Create new instance.

void

addAlias(string id, string alias)

Add an alias to share rules between different forms.

void

addRule(string id, array rule, boolean override)

Add a new rule for the given rule set id.

void

addRules(string id, array rules, boolean override)

Add a list of new rules for the given rule set id.

array

getMessages()

If a validation was not successful, corresponding error messages will be available here.

ZMRuleSet

getRuleSet(string id, boolean compile)

Get a ZMRuleSet for the given id/name.

boolean

hasRuleSet(string id)

Check if a ZMRuleSet exists for the given id.

static void

instance()

Get instance.

void

load(string yaml, boolean override)

Load rules from a YAML style string.

protected string

resolveAlias(string id)

Resolve alias.

string

toJSString(string id)

Create JS validation rules for the given rule set.

boolean

validate(ZMRequest request, mixed data, string id)

Validate the given request/object using the named (id) rule set.

Methods inherited from org.zenmagick.core\ZMObject
__construct, attachMethod, get, getAttachedMethods, getProperties, getPropertyNames, set, singleton

Method Detail

mvc\validation\ZMValidator.php at line 39

__construct

public void __construct()

Create new instance.


mvc\validation\ZMValidator.php at line 69

addAlias

public void addAlias(string id, string alias)

Add an alias to share rules between different forms.

Adding / modifying an alias is not permitted and the result not defined.

Parameters:
id - A rule id of an existing rule set.
alias - An alias.

mvc\validation\ZMValidator.php at line 93

addRule

public void addRule(string id, array rule, boolean override)

Add a new rule for the given rule set id.

Parameters:
id - The rule set id.
rule - A plain text rule.
override - Optional flag to override or add; default is false (add).

mvc\validation\ZMValidator.php at line 108

addRules

public void addRules(string id, array rules, boolean override)

Add a list of new rules for the given rule set id.

Parameters:
id - The rule set id.
rules - A list of plain text rules.
override - Optional flag to override or add; default is false (add).

mvc\validation\ZMValidator.php at line 162

getMessages

public array getMessages()

If a validation was not successful, corresponding error messages will be available here.

Returns:
A list of localized messages.

mvc\validation\ZMValidator.php at line 124

getRuleSet

public ZMRuleSet getRuleSet(string id, boolean compile)

Get a ZMRuleSet for the given id/name.

Parameters:
id - The id/name of the set.
compile - If set to true, evaluate the rule data (creating objects, etc); default is false.
Returns:
A ZMRuleSet instance, array or null.

mvc\validation\ZMValidator.php at line 151

hasRuleSet

public boolean hasRuleSet(string id)

Check if a ZMRuleSet exists for the given id.

Parameters:
id - The id/name of the set.
Returns:
true if a ZMRuleSet exists, false if not.

mvc\validation\ZMValidator.php at line 56

instance

public static void instance()

Get instance.


mvc\validation\ZMValidator.php at line 173

load

public void load(string yaml, boolean override)

Load rules from a YAML style string.

Parameters:
yaml - The yaml style validation rules.
override - Optional flag to control whether to override existing mappings or to merge; default is true to override.

mvc\validation\ZMValidator.php at line 79

resolveAlias

protected string resolveAlias(string id)

Resolve alias.

Parameters:
id - A rule set id.
Returns:
Either the same id or the aliased id.

mvc\validation\ZMValidator.php at line 236

toJSString

public string toJSString(string id)

Create JS validation rules for the given rule set.

Parameters:
id - The id of the form to validate (the ZMRuleSet name).
Returns:
Formatted JavaScript .

mvc\validation\ZMValidator.php at line 194

validate

public boolean validate(ZMRequest request, mixed data, string id)

Validate the given request/object using the named (id) rule set.

If the request parameter is an object, it will be added to the internally used data map using the magic key __obj.

Parameters:
request - The current request.
data - The data (map or object) to validate.
id - The ruleset id.
Returns:
true if the validation was successful, false if not.

ZenMagick 0.9.10