ZenMagick 0.9.6


org.zenmagick.validation.ZMValidator

Class ZMValidator

ZMObject
|
+--ZMValidator

public class ZMValidator
extends ZMObject

A validator framework.

Author:
DerManoMann
Version:
$Id: ZMValidator.php 2147 2009-04-08 04:41:01Z dermanomann $

Fields inherited from org.zenmagick.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.

void

insertJSValidation(string id)

Convenience method that will generate the JavaScript validation rules and include the generic validation code.

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(mixed req, string id)

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

protected boolean

validateSession(mixed req, string id)

Validate session token.

Methods inherited from org.zenmagick.ZMObject
attachMethod, get, getAttachedMethods, getPropertyNames, set, singleton

Constructor Detail

ZMValidator

public ZMValidator()

Create new instance. /


Method Detail

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.

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

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

getMessages

public array getMessages()

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

Returns:
A list of localized messages.

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.

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.

insertJSValidation

public void insertJSValidation(string id)

Convenience method that will generate the JavaScript validation rules and include the generic validation code.

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

instance

public static void instance()

Get instance. /


resolveAlias

protected string resolveAlias(string id)

Resolve alias.

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

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 .

validate

public boolean validate(mixed req, 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 field map using the magic key __obj.

Parameters:
req - A (request) map or an object.
id - The ruleset id.
Returns:
true if the validation was successful, false if not.

validateSession

protected boolean validateSession(mixed req, string id)

Validate session token.

Parameters:
req - A (request) map or an object.
id - The ruleset id.
Returns:
true if the validation was successful, false if not.

ZenMagick 0.9.6