ZenMagick 0.9.8


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

Class ZMValidator

ZMObject
└─ZMValidator

public class ZMValidator
extends ZMObject

A validator framework.

Author:
DerManoMann
Version:
$Id: ZMValidator.php 2610 2009-11-20 02:45:25Z dermanomann $

Fields inherited from org.zenmagick.core.ZMObject
properties_
Constructor Summary

ZMValidator()

Create new instance.

Method Summary
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.

protected string

resolveAlias(string id)

Resolve alias.

string

toJSString(string id, boolean echo)

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
attachMethod, get, getAttachedMethods, getPropertyNames, set, singleton

Constructor Detail

\mvc\validation\ZMValidator.php at line 40

ZMValidator

public ZMValidator()

Create new instance.


Method Detail

\mvc\validation\ZMValidator.php at line 70

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 94

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 109

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 163

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 125

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 152

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 57

instance

public static void instance()

Get instance.


\mvc\validation\ZMValidator.php at line 80

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 221

toJSString

public string toJSString(string id, boolean echo)

Create JS validation rules for the given rule set.

Parameters:
id - The id of the form to validate (the ZMRuleSet name).
echo - If true, the JavaScript will be echo'ed as well as returned.
Returns:
Formatted JavaScript .

\mvc\validation\ZMValidator.php at line 178

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.8