compared with
Current by Darby Felton
on Jan 19, 2007 11:52.

Key
This line was removed.
This word was removed. This word was added.
This line was added.

Changes (35)

View Page History
<ac:macro ac:name="unmigrated-inline-wiki-markup"><ac:plain-text-body><![CDATA[{zone-template-instance:ZFDEV:Zend Proposal Zone Template}


* Zend_Filter_StringTrim
* Zend_Filter_StripTags
* Zend_Validate_Exception
* Zend_Validate_Interface
* Zend_Validate_EmailAddress
* Zend_Validate_StringLength
* (additional classes from porting existing Zend_Filter methods omitted for brevity)
{zone-data}
{code}
<?php
require_once 'Zend/Validate/EmailAddress.php';
$validEmailAddress = new Zend_Validate_EmailAddress();
if ($validEmailAddress->isValid($someEmail)) {
echo "valid\n";
{code}
<?php
require_once 'Zend/Validate.php';
require_once 'Zend/Validate/StringLength.php';
require_once 'Zend/Validate/EmailAddress.php';
$validator = new Zend_Validate();
$validator->addValidator(new Zend_Validate_StringLength(3, 64))
->addValidator(new Zend_Validate_EmailAddress());
if ($validator->isValid($email)) {
echo 'valid';
In this example, a user is registering an identity with the web application, and the application requires that the user choose a password. For verification purposes, the user is required to enter the chosen password twice, into two separate form fields. The password is case-sensitive, and the values of the two password fields must be equivalent in order for successful registration to occur. The same approach is often undertaken for validating an e-mail address.

Since Zend_Validate_Interface defines {{isValid()}} to accept a single parameter, it is a simple matter to create a validator that ensures that the passwords are equivalent:

{code}
require_once 'Zend/Validate/Interface.php';
class StringsEqual implements Zend_Validate_Interface
{
protected $_expectedValue;


{card:label=Zend_Validate}

The Zend_Validate class may be used to create validation chains, in which each validator added to the chain is run in the order in which it was added to the chain. Thus, the first validator added to the chain is the first one run. If {{$breakChainOnFailure}} is set to {{true}} for a particular validator when it is added, then if the validator fails, the validator chain execution is stopped. The default behavior is that all validators are run, regardless of whether or not the input fails any particular validator in the chain.

Zend_Validate aggregates all failure messages from validators into a single array of strings, again in the order in which they are received. It is expected that it is not necessary to maintain for users the association between failure messages and the particular validator that produced them.

{code}
class Zend_Validate
{
public function addValidator(Zend_Validate_Interface $validator, $breakChainOnFailure = false)
{}

{deck:id=skeletons2}

Zend_Validate_Interface defines a basic set of operations for common validation use cases. The {{getMessages()}} method is used, in the event that {{isValid()}} returns false, to find out why the input failed validation. In some cases, the input will have failed validation for a number of reasons, and {{getMessages()}} faciliates this by returning an array of string messages that describe why the input failed certain validation constraints.

{card:label=Zend_Validate_Interface}
{code}
interface Zend_Validate_Interface
{
/**
*
* @param mixed $value
* @throws Zend_Validate_Exception If validation of $value is impossible
* @return boolean
*/


{card:label=Zend_Validate_Exception}
{code}
class Zend_Validate_Exception extends Zend_Exception
{}
{code}


{card:label=Zend_Validate_EmailAddress}
{code}
class Zend_Valid_EmailAddress implements Zend_Valid_Interface
class Zend_Validate_EmailAddress implements Zend_Validate_Interface
{
public function __construct($domainLocalAllowed = false)


{card:label=Zend_Validate_StringLength}
{code}
class Zend_Valid_StringLength implements Zend_Valid_Interface
class Zend_Validate_StringLength implements Zend_Validate_Interface
{
public function __construct($min = 0, $max = null)


{zone-template-instance}
{zone-template-instance}]]></ac:plain-text-body></ac:macro>