You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@shindig.apache.org by ch...@apache.org on 2008/05/08 01:48:22 UTC

svn commit: r654331 [5/6] - in /incubator/shindig/trunk/php: ./ src/common/Zend/ src/common/Zend/Feed/ src/common/Zend/Feed/Builder/ src/common/Zend/Feed/Builder/Header/ src/common/Zend/Feed/Entry/ src/common/Zend/Http/ src/common/Zend/Http/Client/ src...

Added: incubator/shindig/trunk/php/src/common/Zend/Uri/Http.php
URL: http://svn.apache.org/viewvc/incubator/shindig/trunk/php/src/common/Zend/Uri/Http.php?rev=654331&view=auto
==============================================================================
--- incubator/shindig/trunk/php/src/common/Zend/Uri/Http.php (added)
+++ incubator/shindig/trunk/php/src/common/Zend/Uri/Http.php Wed May  7 16:48:15 2008
@@ -0,0 +1,631 @@
+<?php
+
+/**
+ * Zend Framework
+ *
+ * LICENSE
+ *
+ * This source file is subject to the new BSD license that is bundled
+ * with this package in the file LICENSE.txt.
+ * It is also available through the world-wide-web at this URL:
+ * http://framework.zend.com/license/new-bsd
+ * If you did not receive a copy of the license and are unable to
+ * obtain it through the world-wide-web, please send an email
+ * to license@zend.com so we can send you a copy immediately.
+ *
+ * @category   Zend
+ * @package    Zend_Uri
+ * @copyright  Copyright (c) 2005-2008 Zend Technologies USA Inc. (http://www.zend.com)
+ * @license    http://framework.zend.com/license/new-bsd     New BSD License
+ * @version    $Id: Http.php 8064 2008-02-16 10:58:39Z thomas $
+ */
+
+
+/**
+ * @see Zend_Uri
+ */
+require_once 'Zend/Uri.php';
+
+
+/**
+ * @see Zend_Validate_Hostname
+ */
+require_once 'Zend/Validate/Hostname.php';
+
+
+/**
+ * @category   Zend
+ * @package    Zend_Uri
+ * @copyright  Copyright (c) 2005-2008 Zend Technologies USA Inc. (http://www.zend.com)
+ * @license    http://framework.zend.com/license/new-bsd     New BSD License
+ */
+class Zend_Uri_Http extends Zend_Uri
+{
+    /**
+     * URI parts are divided among these instance variables
+     */
+    protected $_username    = '';
+    protected $_password    = '';
+    protected $_host        = '';
+    protected $_port        = '';
+    protected $_path        = '';
+    protected $_query       = '';
+    protected $_fragment    = '';
+
+    /**
+     * Regular expression grammar rules for validation; values added by constructor
+     */
+    protected $_regex = array();
+
+    /**
+     * Constructor accepts a string $scheme (e.g., http, https) and a scheme-specific part of the URI
+     * (e.g., example.com/path/to/resource?query=param#fragment)
+     *
+     * @param string $scheme
+     * @param string $schemeSpecific
+     * @throws Zend_Uri_Exception
+     * @return void
+     */
+    protected function __construct($scheme, $schemeSpecific = '')
+    {
+        // Set the scheme
+        $this->_scheme = $scheme;
+
+        // Set up grammar rules for validation via regular expressions. These
+        // are to be used with slash-delimited regular expression strings.
+        $this->_regex['alphanum']   = '[^\W_]';
+        $this->_regex['escaped']    = '(?:%[\da-fA-F]{2})';
+        $this->_regex['mark']       = '[-_.!~*\'()\[\]]';
+        $this->_regex['reserved']   = '[;\/?:@&=+$,]';
+        $this->_regex['unreserved'] = '(?:' . $this->_regex['alphanum'] . '|' . $this->_regex['mark'] . ')';
+        $this->_regex['segment']    = '(?:(?:' . $this->_regex['unreserved'] . '|' . $this->_regex['escaped']
+                                    . '|[:@&=+$,;])*)';
+        $this->_regex['path']       = '(?:\/' . $this->_regex['segment'] . '?)+';
+        $this->_regex['uric']       = '(?:' . $this->_regex['reserved'] . '|' . $this->_regex['unreserved'] . '|'
+                                    . $this->_regex['escaped'] . ')';
+        // If no scheme-specific part was supplied, the user intends to create
+        // a new URI with this object.  No further parsing is required.
+        if (strlen($schemeSpecific) == 0) {
+            return;
+        }
+
+        // Parse the scheme-specific URI parts into the instance variables.
+        $this->_parseUri($schemeSpecific);
+
+        // Validate the URI
+        if (!$this->valid()) {
+	    require_once 'Zend/Uri/Exception.php';
+            throw new Zend_Uri_Exception('Invalid URI supplied');
+        }
+    }
+
+    /**
+     * Parse the scheme-specific portion of the URI and place its parts into instance variables.
+     *
+     * @param string $schemeSpecific
+     * @throws Zend_Uri_Exception
+     * @return void
+     */
+    protected function _parseUri($schemeSpecific)
+    {
+        // High-level decomposition parser
+        $pattern = '~^((//)([^/?#]*))([^?#]*)(\?([^#]*))?(#(.*))?$~';
+        $status = @preg_match($pattern, $schemeSpecific, $matches);
+        if ($status === false) {
+	    require_once 'Zend/Uri/Exception.php';
+            throw new Zend_Uri_Exception('Internal error: scheme-specific decomposition failed');
+        }
+
+        // Failed decomposition; no further processing needed
+        if (!$status) {
+            return;
+        }
+
+        // Save URI components that need no further decomposition
+        $this->_path     = isset($matches[4]) ? $matches[4] : '';
+        $this->_query    = isset($matches[6]) ? $matches[6] : '';
+        $this->_fragment = isset($matches[8]) ? $matches[8] : '';
+
+        // Additional decomposition to get username, password, host, and port
+        $combo = isset($matches[3]) ? $matches[3] : '';
+        $pattern = '~^(([^:@]*)(:([^@]*))?@)?([^:]+)(:(.*))?$~';
+        $status = @preg_match($pattern, $combo, $matches);
+        if ($status === false) {
+	    require_once 'Zend/Uri/Exception.php';
+            throw new Zend_Uri_Exception('Internal error: authority decomposition failed');
+        }
+
+        // Failed decomposition; no further processing needed
+        if (!$status) {
+            return;
+        }
+
+        // Save remaining URI components
+        $this->_username = isset($matches[2]) ? $matches[2] : '';
+        $this->_password = isset($matches[4]) ? $matches[4] : '';
+        $this->_host     = isset($matches[5]) ? $matches[5] : '';
+        $this->_port     = isset($matches[7]) ? $matches[7] : '';
+
+    }
+
+    /**
+     * Returns a URI based on current values of the instance variables. If any
+     * part of the URI does not pass validation, then an exception is thrown.
+     *
+     * @throws Zend_Uri_Exception
+     * @return string
+     */
+    public function getUri()
+    {
+        if (!$this->valid()) {
+	    require_once 'Zend/Uri/Exception.php';
+            throw new Zend_Uri_Exception('One or more parts of the URI are invalid');
+        }
+        $password = strlen($this->_password) ? ":$this->_password" : '';
+        $auth = strlen($this->_username) ? "$this->_username$password@" : '';
+        $port = strlen($this->_port) ? ":$this->_port" : '';
+        $query = strlen($this->_query) ? "?$this->_query" : '';
+        $fragment = strlen($this->_fragment) ? "#$this->_fragment" : '';
+        return "$this->_scheme://$auth$this->_host$port$this->_path$query$fragment";
+    }
+
+    /**
+     * Validate the current URI from the instance variables. Returns true if and only if all
+     * parts pass validation.
+     *
+     * @return boolean
+     */
+    public function valid()
+    {
+        /**
+         * Return true if and only if all parts of the URI have passed validation
+         */
+        return $this->validateUsername()
+            && $this->validatePassword()
+            && $this->validateHost()
+            && $this->validatePort()
+            && $this->validatePath()
+            && $this->validateQuery()
+            && $this->validateFragment();
+    }
+
+    /**
+     * Returns the username portion of the URL, or FALSE if none.
+     *
+     * @return string
+     */
+    public function getUsername()
+    {
+        return strlen($this->_username) ? $this->_username : false;
+    }
+
+    /**
+     * Returns true if and only if the username passes validation. If no username is passed,
+     * then the username contained in the instance variable is used.
+     *
+     * @param string $username
+     * @throws Zend_Uri_Exception
+     * @return boolean
+     */
+    public function validateUsername($username = null)
+    {
+        if ($username === null) {
+            $username = $this->_username;
+        }
+
+        // If the username is empty, then it is considered valid
+        if (strlen($username) == 0) {
+            return true;
+        }
+        /**
+         * Check the username against the allowed values
+         *
+         * @link http://www.faqs.org/rfcs/rfc2396.html
+         */
+        $status = @preg_match('/^(' . $this->_regex['alphanum']  . '|' . $this->_regex['mark'] . '|'
+                            . $this->_regex['escaped'] . '|[;:&=+$,])+$/', $username);
+        if ($status === false) {
+	    require_once 'Zend/Uri/Exception.php';
+            throw new Zend_Uri_Exception('Internal error: username validation failed');
+        }
+
+        return $status == 1;
+    }
+
+    /**
+     * Sets the username for the current URI, and returns the old username
+     *
+     * @param string $username
+     * @throws Zend_Uri_Exception
+     * @return string
+     */
+    public function setUsername($username)
+    {
+        if (!$this->validateUsername($username)) {
+	    require_once 'Zend/Uri/Exception.php';
+            throw new Zend_Uri_Exception("Username \"$username\" is not a valid HTTP username");
+        }
+        $oldUsername = $this->_username;
+        $this->_username = $username;
+        return $oldUsername;
+    }
+
+    /**
+     * Returns the password portion of the URL, or FALSE if none.
+     *
+     * @return string
+     */
+    public function getPassword()
+    {
+        return strlen($this->_password) ? $this->_password : false;
+    }
+
+    /**
+     * Returns true if and only if the password passes validation. If no password is passed,
+     * then the password contained in the instance variable is used.
+     *
+     * @param string $password
+     * @throws Zend_Uri_Exception
+     * @return boolean
+     */
+    public function validatePassword($password = null)
+    {
+        if ($password === null) {
+            $password = $this->_password;
+        }
+
+        // If the password is empty, then it is considered valid
+        if (strlen($password) == 0) {
+            return true;
+        }
+
+        // If the password is nonempty, but there is no username, then it is considered invalid
+        if (strlen($password) > 0 && strlen($this->_username) == 0) {
+            return false;
+        }
+
+        /**
+         * Check the password against the allowed values
+         *
+         * @link http://www.faqs.org/rfcs/rfc2396.html
+         */
+        $status = @preg_match('/^(' . $this->_regex['alphanum']  . '|' . $this->_regex['mark'] . '|'
+                             . $this->_regex['escaped'] . '|[;:&=+$,])+$/', $password);
+        if ($status === false) {
+	    require_once 'Zend/Uri/Exception.php';
+            throw new Zend_Uri_Exception('Internal error: password validation failed.');
+        }
+        return $status == 1;
+    }
+
+    /**
+     * Sets the password for the current URI, and returns the old password
+     *
+     * @param string $password
+     * @throws Zend_Uri_Exception
+     * @return string
+     */
+    public function setPassword($password)
+    {
+        if (!$this->validatePassword($password)) {
+	    require_once 'Zend/Uri/Exception.php';
+            throw new Zend_Uri_Exception("Password \"$password\" is not a valid HTTP password.");
+        }
+        $oldPassword = $this->_password;
+        $this->_password = $password;
+        return $oldPassword;
+    }
+
+    /**
+     * Returns the domain or host IP portion of the URL, or FALSE if none.
+     *
+     * @return string
+     */
+    public function getHost()
+    {
+        return strlen($this->_host) ? $this->_host : false;
+    }
+
+    /**
+     * Returns true if and only if the host string passes validation. If no host is passed,
+     * then the host contained in the instance variable is used.
+     *
+     * @param string $host
+     * @return boolean
+     * @uses Zend_Filter
+     */
+    public function validateHost($host = null)
+    {
+        if ($host === null) {
+            $host = $this->_host;
+        }
+
+        /**
+         * If the host is empty, then it is considered invalid
+         */
+        if (strlen($host) == 0) {
+            return false;
+        }
+
+        /**
+         * Check the host against the allowed values; delegated to Zend_Filter.
+         */
+        $validate = new Zend_Validate_Hostname(Zend_Validate_Hostname::ALLOW_ALL);
+        return $validate->isValid($host);
+    }
+
+    /**
+     * Sets the host for the current URI, and returns the old host
+     *
+     * @param string $host
+     * @throws Zend_Uri_Exception
+     * @return string
+     */
+    public function setHost($host)
+    {
+        if (!$this->validateHost($host)) {
+	    require_once 'Zend/Uri/Exception.php';
+            throw new Zend_Uri_Exception("Host \"$host\" is not a valid HTTP host");
+        }
+        $oldHost = $this->_host;
+        $this->_host = $host;
+        return $oldHost;
+    }
+
+    /**
+     * Returns the TCP port, or FALSE if none.
+     *
+     * @return string
+     */
+    public function getPort()
+    {
+        return strlen($this->_port) ? $this->_port : false;
+    }
+
+    /**
+     * Returns true if and only if the TCP port string passes validation. If no port is passed,
+     * then the port contained in the instance variable is used.
+     *
+     * @param string $port
+     * @return boolean
+     */
+    public function validatePort($port = null)
+    {
+        if ($port === null) {
+            $port = $this->_port;
+        }
+
+        // If the port is empty, then it is considered valid
+        if (!strlen($port)) {
+            return true;
+        }
+
+        // Check the port against the allowed values
+        return ctype_digit((string)$port) && 1 <= $port && $port <= 65535;
+    }
+
+    /**
+     * Sets the port for the current URI, and returns the old port
+     *
+     * @param string $port
+     * @throws Zend_Uri_Exception
+     * @return string
+     */
+    public function setPort($port)
+    {
+        if (!$this->validatePort($port)) {
+	    require_once 'Zend/Uri/Exception.php';
+            throw new Zend_Uri_Exception("Port \"$port\" is not a valid HTTP port.");
+        }
+        $oldPort = $this->_port;
+        $this->_port = $port;
+        return $oldPort;
+    }
+
+    /**
+     * Returns the path and filename portion of the URL, or FALSE if none.
+     *
+     * @return string
+     */
+    public function getPath()
+    {
+        return strlen($this->_path) ? $this->_path : '/';
+    }
+
+    /**
+     * Returns true if and only if the path string passes validation. If no path is passed,
+     * then the path contained in the instance variable is used.
+     *
+     * @param string $path
+     * @throws Zend_Uri_Exception
+     * @return boolean
+     */
+    public function validatePath($path = null)
+    {
+        if ($path === null) {
+            $path = $this->_path;
+        }
+        /**
+         * If the path is empty, then it is considered valid
+         */
+        if (strlen($path) == 0) {
+            return true;
+        }
+        /**
+         * Determine whether the path is well-formed
+         */
+        $pattern = '/^' . $this->_regex['path'] . '$/';
+        $status = @preg_match($pattern, $path);
+        if ($status === false) {
+	    require_once 'Zend/Uri/Exception.php';
+            throw new Zend_Uri_Exception('Internal error: path validation failed');
+        }
+        return (boolean) $status;
+    }
+
+    /**
+     * Sets the path for the current URI, and returns the old path
+     *
+     * @param string $path
+     * @throws Zend_Uri_Exception
+     * @return string
+     */
+    public function setPath($path)
+    {
+        if (!$this->validatePath($path)) {
+	    require_once 'Zend/Uri/Exception.php';
+            throw new Zend_Uri_Exception("Path \"$path\" is not a valid HTTP path");
+        }
+        $oldPath = $this->_path;
+        $this->_path = $path;
+        return $oldPath;
+    }
+
+    /**
+     * Returns the query portion of the URL (after ?), or FALSE if none.
+     *
+     * @return string
+     */
+    public function getQuery()
+    {
+        return strlen($this->_query) ? $this->_query : false;
+    }
+
+    /**
+     * Returns true if and only if the query string passes validation. If no query is passed,
+     * then the query string contained in the instance variable is used.
+     *
+     * @param string $query
+     * @throws Zend_Uri_Exception
+     * @return boolean
+     */
+    public function validateQuery($query = null)
+    {
+        if ($query === null) {
+            $query = $this->_query;
+        }
+
+        // If query is empty, it is considered to be valid
+        if (strlen($query) == 0) {
+            return true;
+        }
+
+        /**
+         * Determine whether the query is well-formed
+         *
+         * @link http://www.faqs.org/rfcs/rfc2396.html
+         */
+        $pattern = '/^' . $this->_regex['uric'] . '*$/';
+        $status = @preg_match($pattern, $query);
+        if ($status === false) {
+	    require_once 'Zend/Uri/Exception.php';
+            throw new Zend_Uri_Exception('Internal error: query validation failed');
+        }
+
+        return $status == 1;
+    }
+
+    /**
+     * Set the query string for the current URI, and return the old query
+     * string This method accepts both strings and arrays.
+     *
+     * @param  string|array $query The query string or array
+     * @return string              Old query string
+     */
+    public function setQuery($query)
+    {
+        $oldQuery = $this->_query;
+        
+        // If query is empty, set an empty string
+        if (empty($query)) {
+            $this->_query = '';
+            return $oldQuery;
+        }
+
+        // If query is an array, make a string out of it
+        if (is_array($query)) {
+            $query = http_build_query($query, '', '&');
+        
+        // If it is a string, make sure it is valid. If not parse and encode it
+        } else {
+            $query = (string) $query;
+            if (! $this->validateQuery($query)) {
+                parse_str($query, $query_array);
+                $query = http_build_query($query_array, '', '&');   
+            }
+        }
+
+        // Make sure the query is valid, and set it
+        if (! $this->validateQuery($query)) {
+	    require_once 'Zend/Uri/Exception.php';
+            throw new Zend_Uri_Exception("'$query' is not a valid query string");
+        }
+        
+        $this->_query = $query;
+        
+        return $oldQuery;
+    }
+
+    /**
+     * Returns the fragment portion of the URL (after #), or FALSE if none.
+     *
+     * @return string|false
+     */
+    public function getFragment()
+    {
+        return strlen($this->_fragment) ? $this->_fragment : false;
+    }
+
+    /**
+     * Returns true if and only if the fragment passes validation. If no fragment is passed,
+     * then the fragment contained in the instance variable is used.
+     *
+     * @param string $fragment
+     * @throws Zend_Uri_Exception
+     * @return boolean
+     */
+    public function validateFragment($fragment = null)
+    {
+        if ($fragment === null) {
+            $fragment = $this->_fragment;
+        }
+
+        // If fragment is empty, it is considered to be valid
+        if (strlen($fragment) == 0) {
+            return true;
+        }
+
+        /**
+         * Determine whether the fragment is well-formed
+         *
+         * @link http://www.faqs.org/rfcs/rfc2396.html
+         */
+        $pattern = '/^' . $this->_regex['uric'] . '*$/';
+        $status = @preg_match($pattern, $fragment);
+        if ($status === false) {
+	    require_once 'Zend/Uri/Exception.php';
+            throw new Zend_Uri_Exception('Internal error: fragment validation failed');
+        }
+
+        return (boolean) $status;
+    }
+
+    /**
+     * Sets the fragment for the current URI, and returns the old fragment
+     *
+     * @param string $fragment
+     * @throws Zend_Uri_Exception
+     * @return string
+     */
+    public function setFragment($fragment)
+    {
+        if (!$this->validateFragment($fragment)) {
+	    require_once 'Zend/Uri/Exception.php';
+            throw new Zend_Uri_Exception("Fragment \"$fragment\" is not a valid HTTP fragment");
+        }
+        $oldFragment = $this->_fragment;
+        $this->_fragment = $fragment;
+        return $oldFragment;
+    }
+}
+

Added: incubator/shindig/trunk/php/src/common/Zend/Validate.php
URL: http://svn.apache.org/viewvc/incubator/shindig/trunk/php/src/common/Zend/Validate.php?rev=654331&view=auto
==============================================================================
--- incubator/shindig/trunk/php/src/common/Zend/Validate.php (added)
+++ incubator/shindig/trunk/php/src/common/Zend/Validate.php Wed May  7 16:48:15 2008
@@ -0,0 +1,171 @@
+<?php
+
+/**
+ * Zend Framework
+ *
+ * LICENSE
+ *
+ * This source file is subject to the new BSD license that is bundled
+ * with this package in the file LICENSE.txt.
+ * It is also available through the world-wide-web at this URL:
+ * http://framework.zend.com/license/new-bsd
+ * If you did not receive a copy of the license and are unable to
+ * obtain it through the world-wide-web, please send an email
+ * to license@zend.com so we can send you a copy immediately.
+ *
+ * @category   Zend
+ * @package    Zend_Validate
+ * @copyright  Copyright (c) 2005-2008 Zend Technologies USA Inc. (http://www.zend.com)
+ * @license    http://framework.zend.com/license/new-bsd     New BSD License
+ * @version    $Id: Validate.php 8911 2008-03-19 20:22:15Z thomas $
+ */
+
+
+/**
+ * @see Zend_Validate_Interface
+ */
+require_once 'Zend/Validate/Interface.php';
+
+
+/**
+ * @category   Zend
+ * @package    Zend_Validate
+ * @copyright  Copyright (c) 2005-2008 Zend Technologies USA Inc. (http://www.zend.com)
+ * @license    http://framework.zend.com/license/new-bsd     New BSD License
+ */
+class Zend_Validate implements Zend_Validate_Interface
+{
+    /**
+     * Validator chain
+     *
+     * @var array
+     */
+    protected $_validators = array();
+
+    /**
+     * Array of validation failure messages
+     *
+     * @var array
+     */
+    protected $_messages = array();
+
+    /**
+     * Array of validation failure message codes
+     *
+     * @var array
+     * @deprecated Since 1.5.0
+     */
+    protected $_errors = array();
+
+    /**
+     * Adds a validator to the end of the chain
+     *
+     * If $breakChainOnFailure is true, then if the validator fails, the next validator in the chain,
+     * if one exists, will not be executed.
+     *
+     * @param  Zend_Validate_Interface $validator
+     * @param  boolean                 $breakChainOnFailure
+     * @return Zend_Validate Provides a fluent interface
+     */
+    public function addValidator(Zend_Validate_Interface $validator, $breakChainOnFailure = false)
+    {
+        $this->_validators[] = array(
+            'instance' => $validator,
+            'breakChainOnFailure' => (boolean) $breakChainOnFailure
+            );
+        return $this;
+    }
+
+    /**
+     * Returns true if and only if $value passes all validations in the chain
+     *
+     * Validators are run in the order in which they were added to the chain (FIFO).
+     *
+     * @param  mixed $value
+     * @return boolean
+     */
+    public function isValid($value)
+    {
+        $this->_messages = array();
+        $this->_errors   = array();
+        $result = true;
+        foreach ($this->_validators as $element) {
+            $validator = $element['instance'];
+            if ($validator->isValid($value)) {
+                continue;
+            }
+            $result = false;
+            $messages = $validator->getMessages();
+            $this->_messages = array_merge($this->_messages, $messages);
+            $this->_errors   = array_merge($this->_errors,   array_keys($messages));
+            if ($element['breakChainOnFailure']) {
+                break;
+            }
+        }
+        return $result;
+    }
+
+    /**
+     * Defined by Zend_Validate_Interface
+     *
+     * Returns array of validation failure messages
+     *
+     * @return array
+     */
+    public function getMessages()
+    {
+        return $this->_messages;
+    }
+
+    /**
+     * Defined by Zend_Validate_Interface
+     *
+     * Returns array of validation failure message codes
+     *
+     * @return array
+     * @deprecated Since 1.5.0
+     */
+    public function getErrors()
+    {
+        return $this->_errors;
+    }
+
+    /**
+     * @param  mixed    $value
+     * @param  string   $classBaseName
+     * @param  array    $args          OPTIONAL
+     * @param  mixed    $namespaces    OPTIONAL
+     * @return boolean
+     * @throws Zend_Validate_Exception
+     */
+    public static function is($value, $classBaseName, array $args = array(), $namespaces = array())
+    {
+        $namespaces = array_merge(array('Zend_Validate'), (array) $namespaces);
+        foreach ($namespaces as $namespace) {
+            $className = $namespace . '_' . ucfirst($classBaseName);
+            try {
+                require_once 'Zend/Loader.php';
+                @Zend_Loader::loadClass($className);
+                if (class_exists($className, false)) {
+                    $class = new ReflectionClass($className);
+                    if ($class->implementsInterface('Zend_Validate_Interface')) {
+                        if ($class->hasMethod('__construct')) {
+                            $object = $class->newInstanceArgs($args);
+                        } else {
+                            $object = $class->newInstance();
+                        }
+                        return $object->isValid($value);
+                    }
+                }
+            } catch (Zend_Validate_Exception $ze) {
+                // if there is an exception while validating throw it
+                throw $ze;
+            } catch (Zend_Exception $ze) {
+                // fallthrough and continue for missing validation classes
+            }
+        }
+        require_once 'Zend/Validate/Exception.php';
+        throw new Zend_Validate_Exception("Validate class not found from basename '$classBaseName'");
+    }
+
+}

Added: incubator/shindig/trunk/php/src/common/Zend/Validate/Abstract.php
URL: http://svn.apache.org/viewvc/incubator/shindig/trunk/php/src/common/Zend/Validate/Abstract.php?rev=654331&view=auto
==============================================================================
--- incubator/shindig/trunk/php/src/common/Zend/Validate/Abstract.php (added)
+++ incubator/shindig/trunk/php/src/common/Zend/Validate/Abstract.php Wed May  7 16:48:15 2008
@@ -0,0 +1,346 @@
+<?php
+
+/**
+ * Zend Framework
+ *
+ * LICENSE
+ *
+ * This source file is subject to the new BSD license that is bundled
+ * with this package in the file LICENSE.txt.
+ * It is also available through the world-wide-web at this URL:
+ * http://framework.zend.com/license/new-bsd
+ * If you did not receive a copy of the license and are unable to
+ * obtain it through the world-wide-web, please send an email
+ * to license@zend.com so we can send you a copy immediately.
+ *
+ * @category   Zend
+ * @package    Zend_Validate
+ * @copyright  Copyright (c) 2005-2008 Zend Technologies USA Inc. (http://www.zend.com)
+ * @license    http://framework.zend.com/license/new-bsd     New BSD License
+ * @version    $Id: Abstract.php 8113 2008-02-18 13:15:27Z matthew $
+ */
+
+
+/**
+ * @see Zend_Validate_Interface
+ */
+require_once 'Zend/Validate/Interface.php';
+
+
+/**
+ * @category   Zend
+ * @package    Zend_Validate
+ * @copyright  Copyright (c) 2005-2008 Zend Technologies USA Inc. (http://www.zend.com)
+ * @license    http://framework.zend.com/license/new-bsd     New BSD License
+ */
+abstract class Zend_Validate_Abstract implements Zend_Validate_Interface
+{
+    /**
+     * The value to be validated
+     *
+     * @var mixed
+     */
+    protected $_value;
+
+    /**
+     * Additional variables available for validation failure messages
+     *
+     * @var array
+     */
+    protected $_messageVariables = array();
+
+    /**
+     * Validation failure message template definitions
+     *
+     * @var array
+     */
+    protected $_messageTemplates = array();
+
+    /**
+     * Array of validation failure messages
+     *
+     * @var array
+     */
+    protected $_messages = array();
+
+    /**
+     * Flag indidcating whether or not value should be obfuscated in error 
+     * messages
+     * @var bool
+     */
+    protected $_obscureValue = false;
+
+    /**
+     * Array of validation failure message codes
+     *
+     * @var array
+     * @deprecated Since 1.5.0
+     */
+    protected $_errors = array();
+
+    /**
+     * Translation object
+     * @var Zend_Translate
+     */
+    protected $_translator;
+
+    /**
+     * Default translation object for all validate objects
+     * @var Zend_Translate
+     */
+    protected static $_defaultTranslator;
+
+    /**
+     * Returns array of validation failure messages
+     *
+     * @return array
+     */
+    public function getMessages()
+    {
+        return $this->_messages;
+    }
+
+    /**
+     * Returns an array of the names of variables that are used in constructing validation failure messages
+     *
+     * @return array
+     */
+    public function getMessageVariables()
+    {
+        return array_keys($this->_messageVariables);
+    }
+
+    /**
+     * Sets the validation failure message template for a particular key
+     *
+     * @param  string $messageString
+     * @param  string $messageKey     OPTIONAL
+     * @return Zend_Validate_Abstract Provides a fluent interface
+     * @throws Zend_Validate_Exception
+     */
+    public function setMessage($messageString, $messageKey = null)
+    {
+        if ($messageKey === null) {
+            $keys = array_keys($this->_messageTemplates);
+            $messageKey = current($keys);
+        }
+        if (!isset($this->_messageTemplates[$messageKey])) {
+            require_once 'Zend/Validate/Exception.php';
+            throw new Zend_Validate_Exception("No message template exists for key '$messageKey'");
+        }
+        $this->_messageTemplates[$messageKey] = $messageString;
+        return $this;
+    }
+
+    /**
+     * Sets validation failure message templates given as an array, where the array keys are the message keys,
+     * and the array values are the message template strings.
+     *
+     * @param  array $messages
+     * @return Zend_Validate_Abstract
+     */
+    public function setMessages(array $messages)
+    {
+        foreach ($messages as $key => $message) {
+            $this->setMessage($message, $key);
+        }
+        return $this;
+    }
+
+    /**
+     * Magic function returns the value of the requested property, if and only if it is the value or a
+     * message variable.
+     *
+     * @param  string $property
+     * @return mixed
+     * @throws Zend_Validate_Exception
+     */
+    public function __get($property)
+    {
+        if ($property == 'value') {
+            return $this->_value;
+        }
+        if (array_key_exists($property, $this->_messageVariables)) {
+            return $this->{$this->_messageVariables[$property]};
+        }
+        /**
+         * @see Zend_Validate_Exception
+         */
+        require_once 'Zend/Validate/Exception.php';
+        throw new Zend_Validate_Exception("No property exists by the name '$property'");
+    }
+
+    /**
+     * Constructs and returns a validation failure message with the given message key and value.
+     *
+     * Returns null if and only if $messageKey does not correspond to an existing template.
+     *
+     * If a translator is available and a translation exists for $messageKey, 
+     * the translation will be used.
+     *
+     * @param  string $messageKey
+     * @param  string $value
+     * @return string
+     */
+    protected function _createMessage($messageKey, $value)
+    {
+        if (!isset($this->_messageTemplates[$messageKey])) {
+            return null;
+        }
+
+        $message = $this->_messageTemplates[$messageKey];
+
+        if (null !== ($translator = $this->getTranslator())) {
+            if ($translator->isTranslated($messageKey)) {
+                $message = $translator->translate($messageKey);
+            }
+        }
+
+        if ($this->getObscureValue()) {
+            $value = str_repeat('*', strlen($value));
+        }
+
+        $message = str_replace('%value%', (string) $value, $message);
+        foreach ($this->_messageVariables as $ident => $property) {
+            $message = str_replace("%$ident%", $this->$property, $message);
+        }
+        return $message;
+    }
+
+    /**
+     * @param  string $messageKey OPTIONAL
+     * @param  string $value      OPTIONAL
+     * @return void
+     */
+    protected function _error($messageKey = null, $value = null)
+    {
+        if ($messageKey === null) {
+            $keys = array_keys($this->_messageTemplates);
+            $messageKey = current($keys);
+        }
+        if ($value === null) {
+            $value = $this->_value;
+        }
+        $this->_errors[]              = $messageKey;
+        $this->_messages[$messageKey] = $this->_createMessage($messageKey, $value);
+    }
+
+    /**
+     * Sets the value to be validated and clears the messages and errors arrays
+     *
+     * @param  mixed $value
+     * @return void
+     */
+    protected function _setValue($value)
+    {
+        $this->_value    = $value;
+        $this->_messages = array();
+        $this->_errors   = array();
+    }
+
+    /**
+     * Returns array of validation failure message codes
+     *
+     * @return array
+     * @deprecated Since 1.5.0
+     */
+    public function getErrors()
+    {
+        return $this->_errors;
+    }
+
+    /**
+     * Set flag indicating whether or not value should be obfuscated in messages
+     * 
+     * @param  bool $flag 
+     * @return Zend_Validate_Abstract
+     */
+    public function setObscureValue($flag)
+    {
+        $this->_obscureValue = (bool) $flag;
+        return $this;
+    }
+
+    /**
+     * Retrieve flag indicating whether or not value should be obfuscated in 
+     * messages
+     * 
+     * @return bool
+     */
+    public function getObscureValue()
+    {
+        return $this->_obscureValue;
+    }
+
+    /**
+     * Set translation object
+     * 
+     * @param  Zend_Translate|Zend_Translate_Adapter|null $translator 
+     * @return Zend_Validate_Abstract
+     */
+    public function setTranslator($translator = null)
+    {
+        if ((null === $translator) || ($translator instanceof Zend_Translate_Adapter)) {
+            $this->_translator = $translator;
+        } elseif ($translator instanceof Zend_Translate) {
+            $this->_translator = $translator->getAdapter();
+        } else {
+            require_once 'Zend/Validate/Exception.php';
+            throw new Zend_Validate_Exception('Invalid translator specified');
+        }
+        return $this;
+    }
+
+    /**
+     * Return translation object
+     * 
+     * @return Zend_Translate_Adapter|null
+     */
+    public function getTranslator()
+    {
+        if (null === $this->_translator) {
+            return self::getDefaultTranslator();
+        }
+
+        return $this->_translator;
+    }
+
+    /**
+     * Set default translation object for all validate objects
+     * 
+     * @param  Zend_Translate|Zend_Translate_Adapter|null $translator 
+     * @return void
+     */
+    public static function setDefaultTranslator($translator = null)
+    {
+        if ((null === $translator) || ($translator instanceof Zend_Translate_Adapter)) {
+            self::$_defaultTranslator = $translator;
+        } elseif ($translator instanceof Zend_Translate) {
+            self::$_defaultTranslator = $translator->getAdapter();
+        } else {
+            require_once 'Zend/Validate/Exception.php';
+            throw new Zend_Validate_Exception('Invalid translator specified');
+        }
+    }
+
+    /**
+     * Get default translation object for all validate objects
+     * 
+     * @return Zend_Translate_Adapter|null
+     */
+    public static function getDefaultTranslator()
+    {
+        if (null === self::$_defaultTranslator) {
+            require_once 'Zend/Registry.php';
+            if (Zend_Registry::isRegistered('Zend_Translate')) {
+                $translator = Zend_Registry::get('Zend_Translate');
+                if ($translator instanceof Zend_Translate_Adapter) {
+                    return $translator;
+                } elseif ($translator instanceof Zend_Translate) {
+                    return $translator->getAdapter();
+                }
+            }
+        }
+        return self::$_defaultTranslator;
+    }
+}

Added: incubator/shindig/trunk/php/src/common/Zend/Validate/Alnum.php
URL: http://svn.apache.org/viewvc/incubator/shindig/trunk/php/src/common/Zend/Validate/Alnum.php?rev=654331&view=auto
==============================================================================
--- incubator/shindig/trunk/php/src/common/Zend/Validate/Alnum.php (added)
+++ incubator/shindig/trunk/php/src/common/Zend/Validate/Alnum.php Wed May  7 16:48:15 2008
@@ -0,0 +1,120 @@
+<?php
+
+/**
+ * Zend Framework
+ *
+ * LICENSE
+ *
+ * This source file is subject to the new BSD license that is bundled
+ * with this package in the file LICENSE.txt.
+ * It is also available through the world-wide-web at this URL:
+ * http://framework.zend.com/license/new-bsd
+ * If you did not receive a copy of the license and are unable to
+ * obtain it through the world-wide-web, please send an email
+ * to license@zend.com so we can send you a copy immediately.
+ *
+ * @category   Zend
+ * @package    Zend_Validate
+ * @copyright  Copyright (c) 2005-2008 Zend Technologies USA Inc. (http://www.zend.com)
+ * @license    http://framework.zend.com/license/new-bsd     New BSD License
+ * @version    $Id: Alnum.php 8064 2008-02-16 10:58:39Z thomas $
+ */
+
+
+/**
+ * @see Zend_Validate_Abstract
+ */
+require_once 'Zend/Validate/Abstract.php';
+
+
+/**
+ * @category   Zend
+ * @package    Zend_Validate
+ * @copyright  Copyright (c) 2005-2008 Zend Technologies USA Inc. (http://www.zend.com)
+ * @license    http://framework.zend.com/license/new-bsd     New BSD License
+ */
+class Zend_Validate_Alnum extends Zend_Validate_Abstract
+{
+    /**
+     * Validation failure message key for when the value contains non-alphabetic or non-digit characters
+     */
+    const NOT_ALNUM = 'notAlnum';
+
+    /**
+     * Validation failure message key for when the value is an empty string
+     */
+    const STRING_EMPTY = 'stringEmpty';
+
+    /**
+     * Whether to allow white space characters; off by default
+     *
+     * @var boolean
+     */
+    public $allowWhiteSpace;
+
+    /**
+     * Alphanumeric filter used for validation
+     *
+     * @var Zend_Filter_Alnum
+     */
+    protected static $_filter = null;
+
+    /**
+     * Validation failure message template definitions
+     *
+     * @var array
+     */
+    protected $_messageTemplates = array(
+        self::NOT_ALNUM    => "'%value%' has not only alphabetic and digit characters",
+        self::STRING_EMPTY => "'%value%' is an empty string"
+    );
+
+    /**
+     * Sets default option values for this instance
+     *
+     * @param  boolean $allowWhiteSpace
+     * @return void
+     */
+    public function __construct($allowWhiteSpace = false)
+    {
+        $this->allowWhiteSpace = (boolean) $allowWhiteSpace;
+    }
+
+    /**
+     * Defined by Zend_Validate_Interface
+     *
+     * Returns true if and only if $value contains only alphabetic and digit characters
+     *
+     * @param  string $value
+     * @return boolean
+     */
+    public function isValid($value)
+    {
+        $valueString = (string) $value;
+
+        $this->_setValue($valueString);
+
+        if ('' === $valueString) {
+            $this->_error(self::STRING_EMPTY);
+            return false;
+        }
+
+        if (null === self::$_filter) {
+            /**
+             * @see Zend_Filter_Alnum
+             */
+            require_once 'Zend/Filter/Alnum.php';
+            self::$_filter = new Zend_Filter_Alnum();
+        }
+
+        self::$_filter->allowWhiteSpace = $this->allowWhiteSpace;
+
+        if ($valueString !== self::$_filter->filter($valueString)) {
+            $this->_error(self::NOT_ALNUM);
+            return false;
+        }
+
+        return true;
+    }
+
+}

Added: incubator/shindig/trunk/php/src/common/Zend/Validate/Alpha.php
URL: http://svn.apache.org/viewvc/incubator/shindig/trunk/php/src/common/Zend/Validate/Alpha.php?rev=654331&view=auto
==============================================================================
--- incubator/shindig/trunk/php/src/common/Zend/Validate/Alpha.php (added)
+++ incubator/shindig/trunk/php/src/common/Zend/Validate/Alpha.php Wed May  7 16:48:15 2008
@@ -0,0 +1,120 @@
+<?php
+
+/**
+ * Zend Framework
+ *
+ * LICENSE
+ *
+ * This source file is subject to the new BSD license that is bundled
+ * with this package in the file LICENSE.txt.
+ * It is also available through the world-wide-web at this URL:
+ * http://framework.zend.com/license/new-bsd
+ * If you did not receive a copy of the license and are unable to
+ * obtain it through the world-wide-web, please send an email
+ * to license@zend.com so we can send you a copy immediately.
+ *
+ * @category   Zend
+ * @package    Zend_Validate
+ * @copyright  Copyright (c) 2005-2008 Zend Technologies USA Inc. (http://www.zend.com)
+ * @license    http://framework.zend.com/license/new-bsd     New BSD License
+ * @version    $Id: Alpha.php 8064 2008-02-16 10:58:39Z thomas $
+ */
+
+
+/**
+ * @see Zend_Validate_Abstract
+ */
+require_once 'Zend/Validate/Abstract.php';
+
+
+/**
+ * @category   Zend
+ * @package    Zend_Validate
+ * @copyright  Copyright (c) 2005-2008 Zend Technologies USA Inc. (http://www.zend.com)
+ * @license    http://framework.zend.com/license/new-bsd     New BSD License
+ */
+class Zend_Validate_Alpha extends Zend_Validate_Abstract
+{
+    /**
+     * Validation failure message key for when the value contains non-alphabetic characters
+     */
+    const NOT_ALPHA = 'notAlpha';
+
+    /**
+     * Validation failure message key for when the value is an empty string
+     */
+    const STRING_EMPTY = 'stringEmpty';
+
+    /**
+     * Whether to allow white space characters; off by default
+     *
+     * @var boolean
+     */
+    public $allowWhiteSpace;
+
+    /**
+     * Alphabetic filter used for validation
+     *
+     * @var Zend_Filter_Alpha
+     */
+    protected static $_filter = null;
+
+    /**
+     * Validation failure message template definitions
+     *
+     * @var array
+     */
+    protected $_messageTemplates = array(
+        self::NOT_ALPHA    => "'%value%' has not only alphabetic characters",
+        self::STRING_EMPTY => "'%value%' is an empty string"
+    );
+
+    /**
+     * Sets default option values for this instance
+     *
+     * @param  boolean $allowWhiteSpace
+     * @return void
+     */
+    public function __construct($allowWhiteSpace = false)
+    {
+        $this->allowWhiteSpace = (boolean) $allowWhiteSpace;
+    }
+
+    /**
+     * Defined by Zend_Validate_Interface
+     *
+     * Returns true if and only if $value contains only alphabetic characters
+     *
+     * @param  string $value
+     * @return boolean
+     */
+    public function isValid($value)
+    {
+        $valueString = (string) $value;
+
+        $this->_setValue($valueString);
+
+        if ('' === $valueString) {
+            $this->_error(self::STRING_EMPTY);
+            return false;
+        }
+
+        if (null === self::$_filter) {
+            /**
+             * @see Zend_Filter_Alpha
+             */
+            require_once 'Zend/Filter/Alpha.php';
+            self::$_filter = new Zend_Filter_Alpha();
+        }
+
+        self::$_filter->allowWhiteSpace = $this->allowWhiteSpace;
+
+        if ($valueString !== self::$_filter->filter($valueString)) {
+            $this->_error(self::NOT_ALPHA);
+            return false;
+        }
+
+        return true;
+    }
+
+}

Added: incubator/shindig/trunk/php/src/common/Zend/Validate/Barcode.php
URL: http://svn.apache.org/viewvc/incubator/shindig/trunk/php/src/common/Zend/Validate/Barcode.php?rev=654331&view=auto
==============================================================================
--- incubator/shindig/trunk/php/src/common/Zend/Validate/Barcode.php (added)
+++ incubator/shindig/trunk/php/src/common/Zend/Validate/Barcode.php Wed May  7 16:48:15 2008
@@ -0,0 +1,99 @@
+<?php
+
+/**
+ * Zend Framework
+ *
+ * LICENSE
+ *
+ * This source file is subject to the new BSD license that is bundled
+ * with this package in the file LICENSE.txt.
+ * It is also available through the world-wide-web at this URL:
+ * http://framework.zend.com/license/new-bsd
+ * If you did not receive a copy of the license and are unable to
+ * obtain it through the world-wide-web, please send an email
+ * to license@zend.com so we can send you a copy immediately.
+ *
+ * @category   Zend
+ * @package    Zend_Validate
+ * @copyright  Copyright (c) 2005-2008 Zend Technologies USA Inc. (http://www.zend.com)
+ * @license    http://framework.zend.com/license/new-bsd     New BSD License
+ * @version    $Id: Barcode.php 8211 2008-02-20 14:29:24Z darby $
+ */
+
+
+/**
+ * @see Zend_Validate_Abstract
+ */
+require_once 'Zend/Validate/Abstract.php';
+
+
+/**
+ * @category   Zend
+ * @package    Zend_Validate
+ * @copyright  Copyright (c) 2005-2008 Zend Technologies USA Inc. (http://www.zend.com)
+ * @license    http://framework.zend.com/license/new-bsd     New BSD License
+ */
+class Zend_Validate_Barcode extends Zend_Validate_Abstract
+{
+    /**
+     * Barcode validator
+     *
+     * @var Zend_Validate_Abstract
+     */
+    protected $_barcodeValidator;
+
+    /**
+     * Generates the standard validator object
+     *
+     * @param  string $barcodeType - Barcode validator to use
+     * @return void
+     * @throws Zend_Validate_Exception
+     */
+    public function __construct($barcodeType)
+    {
+        $this->setType($barcodeType);
+    }
+
+    /**
+     * Sets a new barcode validator
+     *
+     * @param  string $barcodeType - Barcode validator to use
+     * @return void
+     * @throws Zend_Validate_Exception
+     */
+    public function setType($barcodeType)
+    {
+        switch (strtolower($barcodeType)) {
+            case 'upc':
+            case 'upc-a':
+                $className = 'UpcA';
+                break;
+            case 'ean13':
+            case 'ean-13':
+                $className = 'Ean13';
+                break;
+            default:
+                require_once 'Zend/Validate/Exception.php';
+                throw new Zend_Validate_Exception("Barcode type '$barcodeType' is not supported'");
+                break;
+        }
+
+        require_once 'Zend/Validate/Barcode/' . $className . '.php';
+
+        $class = 'Zend_Validate_Barcode_' . $className;
+        $this->_barcodeValidator = new $class;
+    }
+
+    /**
+     * Defined by Zend_Validate_Interface
+     *
+     * Returns true if and only if $value contains a valid barcode
+     *
+     * @param  string $value
+     * @return boolean
+     */
+    public function isValid($value)
+    {
+        return call_user_func(array($this->_barcodeValidator, 'isValid'), $value);
+    }
+}

Added: incubator/shindig/trunk/php/src/common/Zend/Validate/Barcode/Ean13.php
URL: http://svn.apache.org/viewvc/incubator/shindig/trunk/php/src/common/Zend/Validate/Barcode/Ean13.php?rev=654331&view=auto
==============================================================================
--- incubator/shindig/trunk/php/src/common/Zend/Validate/Barcode/Ean13.php (added)
+++ incubator/shindig/trunk/php/src/common/Zend/Validate/Barcode/Ean13.php Wed May  7 16:48:15 2008
@@ -0,0 +1,100 @@
+<?php
+
+/**
+ * Zend Framework
+ *
+ * LICENSE
+ *
+ * This source file is subject to the new BSD license that is bundled
+ * with this package in the file LICENSE.txt.
+ * It is also available through the world-wide-web at this URL:
+ * http://framework.zend.com/license/new-bsd
+ * If you did not receive a copy of the license and are unable to
+ * obtain it through the world-wide-web, please send an email
+ * to license@zend.com so we can send you a copy immediately.
+ *
+ * @category   Zend
+ * @package    Zend_Validate
+ * @copyright  Copyright (c) 2005-2008 Zend Technologies USA Inc. (http://www.zend.com)
+ * @license    http://framework.zend.com/license/new-bsd     New BSD License
+ * @version    $Id: Ean13.php 8210 2008-02-20 14:09:05Z andries $
+ */
+
+
+/**
+ * @see Zend_Validate_Abstract
+ */
+require_once 'Zend/Validate/Abstract.php';
+
+
+/**
+ * @category   Zend
+ * @package    Zend_Validate
+ * @copyright  Copyright (c) 2005-2008 Zend Technologies USA Inc. (http://www.zend.com)
+ * @license    http://framework.zend.com/license/new-bsd     New BSD License
+ */
+class Zend_Validate_Barcode_Ean13 extends Zend_Validate_Abstract
+{
+    /**
+     * Validation failure message key for when the value is
+     * an invalid barcode
+     */
+    const INVALID = 'invalid';
+
+    /**
+     * Validation failure message key for when the value is
+     * not 13 characters long
+     */
+    const INVALID_LENGTH = 'invalidLength';
+
+    /**
+     * Validation failure message template definitions
+     *
+     * @var array
+     */
+    protected $_messageTemplates = array(
+        self::INVALID        => "'%value%' is an invalid EAN-13 barcode",
+        self::INVALID_LENGTH => "'%value%' should be 13 characters",
+    );
+
+    /**
+     * Defined by Zend_Validate_Interface
+     *
+     * Returns true if and only if $value contains a valid barcode
+     *
+     * @param  string $value
+     * @return boolean
+     */
+    public function isValid($value)
+    {
+        $valueString = (string) $value;
+        $this->_setValue($valueString);
+
+        if (strlen($valueString) !== 13) {
+            $this->_error(self::INVALID_LENGTH);
+            return false;
+        }
+
+        $barcode = strrev(substr($valueString, 0, -1));
+        $oddSum  = 0;
+        $evenSum = 0;
+
+        for ($i = 0; $i < 12; $i++) {
+            if ($i % 2 === 0) {
+                $oddSum += $barcode[$i] * 3;
+            } elseif ($i % 2 === 1) {
+                $evenSum += $barcode[$i];
+            }
+        }
+
+        $calculation = ($oddSum + $evenSum) % 10;
+        $checksum    = ($calculation === 0) ? 0 : 10 - $calculation;
+
+        if ($valueString[12] != $checksum) {
+            $this->_error(self::INVALID);
+            return false;
+        }
+
+        return true;
+    }
+}

Added: incubator/shindig/trunk/php/src/common/Zend/Validate/Barcode/UpcA.php
URL: http://svn.apache.org/viewvc/incubator/shindig/trunk/php/src/common/Zend/Validate/Barcode/UpcA.php?rev=654331&view=auto
==============================================================================
--- incubator/shindig/trunk/php/src/common/Zend/Validate/Barcode/UpcA.php (added)
+++ incubator/shindig/trunk/php/src/common/Zend/Validate/Barcode/UpcA.php Wed May  7 16:48:15 2008
@@ -0,0 +1,100 @@
+<?php
+
+/**
+ * Zend Framework
+ *
+ * LICENSE
+ *
+ * This source file is subject to the new BSD license that is bundled
+ * with this package in the file LICENSE.txt.
+ * It is also available through the world-wide-web at this URL:
+ * http://framework.zend.com/license/new-bsd
+ * If you did not receive a copy of the license and are unable to
+ * obtain it through the world-wide-web, please send an email
+ * to license@zend.com so we can send you a copy immediately.
+ *
+ * @category   Zend
+ * @package    Zend_Validate
+ * @copyright  Copyright (c) 2005-2008 Zend Technologies USA Inc. (http://www.zend.com)
+ * @license    http://framework.zend.com/license/new-bsd     New BSD License
+ * @version    $Id: UpcA.php 8210 2008-02-20 14:09:05Z andries $
+ */
+
+
+/**
+ * @see Zend_Validate_Abstract
+ */
+require_once 'Zend/Validate/Abstract.php';
+
+
+/**
+ * @category   Zend
+ * @package    Zend_Validate
+ * @copyright  Copyright (c) 2005-2008 Zend Technologies USA Inc. (http://www.zend.com)
+ * @license    http://framework.zend.com/license/new-bsd     New BSD License
+ */
+class Zend_Validate_Barcode_UpcA extends Zend_Validate_Abstract
+{
+    /**
+     * Validation failure message key for when the value is
+     * an invalid barcode
+     */
+    const INVALID = 'invalid';
+
+    /**
+     * Validation failure message key for when the value is
+     * not 12 characters long
+     */
+    const INVALID_LENGTH = 'invalidLength';
+
+    /**
+     * Validation failure message template definitions
+     *
+     * @var array
+     */
+    protected $_messageTemplates = array(
+        self::INVALID        => "'%value%' is an invalid UPC-A barcode",
+        self::INVALID_LENGTH => "'%value%' should be 12 characters",
+    );
+
+    /**
+     * Defined by Zend_Validate_Interface
+     *
+     * Returns true if and only if $value contains a valid barcode
+     *
+     * @param  string $value
+     * @return boolean
+     */
+    public function isValid($value)
+    {
+        $valueString = (string) $value;
+        $this->_setValue($valueString);
+
+        if (strlen($valueString) !== 12) {
+            $this->_error(self::INVALID_LENGTH);
+            return false;
+        }
+
+        $barcode = substr($valueString, 0, -1);
+        $oddSum  = 0;
+        $evenSum = 0;
+
+        for ($i = 0; $i < 11; $i++) {
+            if ($i % 2 === 0) {
+                $oddSum += $barcode[$i] * 3;
+            } elseif ($i % 2 === 1) {
+                $evenSum += $barcode[$i];
+            }
+        }
+
+        $calculation = ($oddSum + $evenSum) % 10;
+        $checksum    = ($calculation === 0) ? 0 : 10 - $calculation;
+
+        if ($valueString[11] != $checksum) {
+            $this->_error(self::INVALID);
+            return false;
+        }
+
+        return true;
+    }
+}

Added: incubator/shindig/trunk/php/src/common/Zend/Validate/Between.php
URL: http://svn.apache.org/viewvc/incubator/shindig/trunk/php/src/common/Zend/Validate/Between.php?rev=654331&view=auto
==============================================================================
--- incubator/shindig/trunk/php/src/common/Zend/Validate/Between.php (added)
+++ incubator/shindig/trunk/php/src/common/Zend/Validate/Between.php Wed May  7 16:48:15 2008
@@ -0,0 +1,200 @@
+<?php
+
+/**
+ * Zend Framework
+ *
+ * LICENSE
+ *
+ * This source file is subject to the new BSD license that is bundled
+ * with this package in the file LICENSE.txt.
+ * It is also available through the world-wide-web at this URL:
+ * http://framework.zend.com/license/new-bsd
+ * If you did not receive a copy of the license and are unable to
+ * obtain it through the world-wide-web, please send an email
+ * to license@zend.com so we can send you a copy immediately.
+ *
+ * @category   Zend
+ * @package    Zend_Validate
+ * @copyright  Copyright (c) 2005-2008 Zend Technologies USA Inc. (http://www.zend.com)
+ * @license    http://framework.zend.com/license/new-bsd     New BSD License
+ * @version    $Id: Between.php 8064 2008-02-16 10:58:39Z thomas $
+ */
+
+
+/**
+ * @see Zend_Validate_Abstract
+ */
+require_once 'Zend/Validate/Abstract.php';
+
+
+/**
+ * @category   Zend
+ * @package    Zend_Validate
+ * @copyright  Copyright (c) 2005-2008 Zend Technologies USA Inc. (http://www.zend.com)
+ * @license    http://framework.zend.com/license/new-bsd     New BSD License
+ */
+class Zend_Validate_Between extends Zend_Validate_Abstract
+{
+    /**
+     * Validation failure message key for when the value is not between the min and max, inclusively
+     */
+    const NOT_BETWEEN        = 'notBetween';
+
+    /**
+     * Validation failure message key for when the value is not strictly between the min and max
+     */
+    const NOT_BETWEEN_STRICT = 'notBetweenStrict';
+
+    /**
+     * Validation failure message template definitions
+     *
+     * @var array
+     */
+    protected $_messageTemplates = array(
+        self::NOT_BETWEEN        => "'%value%' is not between '%min%' and '%max%', inclusively",
+        self::NOT_BETWEEN_STRICT => "'%value%' is not strictly between '%min%' and '%max%'"
+    );
+
+    /**
+     * Additional variables available for validation failure messages
+     *
+     * @var array
+     */
+    protected $_messageVariables = array(
+        'min' => '_min',
+        'max' => '_max'
+    );
+
+    /**
+     * Minimum value
+     *
+     * @var mixed
+     */
+    protected $_min;
+
+    /**
+     * Maximum value
+     *
+     * @var mixed
+     */
+    protected $_max;
+
+    /**
+     * Whether to do inclusive comparisons, allowing equivalence to min and/or max
+     *
+     * If false, then strict comparisons are done, and the value may equal neither
+     * the min nor max options
+     *
+     * @var boolean
+     */
+    protected $_inclusive;
+
+    /**
+     * Sets validator options
+     *
+     * @param  mixed   $min
+     * @param  mixed   $max
+     * @param  boolean $inclusive
+     * @return void
+     */
+    public function __construct($min, $max, $inclusive = true)
+    {
+        $this->setMin($min)
+             ->setMax($max)
+             ->setInclusive($inclusive);
+    }
+
+    /**
+     * Returns the min option
+     *
+     * @return mixed
+     */
+    public function getMin()
+    {
+        return $this->_min;
+    }
+
+    /**
+     * Sets the min option
+     *
+     * @param  mixed $min
+     * @return Zend_Validate_Between Provides a fluent interface
+     */
+    public function setMin($min)
+    {
+        $this->_min = $min;
+        return $this;
+    }
+
+    /**
+     * Returns the max option
+     *
+     * @return mixed
+     */
+    public function getMax()
+    {
+        return $this->_max;
+    }
+
+    /**
+     * Sets the max option
+     *
+     * @param  mixed $max
+     * @return Zend_Validate_Between Provides a fluent interface
+     */
+    public function setMax($max)
+    {
+        $this->_max = $max;
+        return $this;
+    }
+
+    /**
+     * Returns the inclusive option
+     *
+     * @return boolean
+     */
+    public function getInclusive()
+    {
+        return $this->_inclusive;
+    }
+
+    /**
+     * Sets the inclusive option
+     *
+     * @param  boolean $inclusive
+     * @return Zend_Validate_Between Provides a fluent interface
+     */
+    public function setInclusive($inclusive)
+    {
+        $this->_inclusive = $inclusive;
+        return $this;
+    }
+
+    /**
+     * Defined by Zend_Validate_Interface
+     *
+     * Returns true if and only if $value is between min and max options, inclusively
+     * if inclusive option is true.
+     *
+     * @param  mixed $value
+     * @return boolean
+     */
+    public function isValid($value)
+    {
+        $this->_setValue($value);
+
+        if ($this->_inclusive) {
+            if ($this->_min > $value || $value > $this->_max) {
+                $this->_error(self::NOT_BETWEEN);
+                return false;
+            }
+        } else {
+            if ($this->_min >= $value || $value >= $this->_max) {
+                $this->_error(self::NOT_BETWEEN_STRICT);
+                return false;
+            }
+        }
+        return true;
+    }
+
+}

Added: incubator/shindig/trunk/php/src/common/Zend/Validate/Ccnum.php
URL: http://svn.apache.org/viewvc/incubator/shindig/trunk/php/src/common/Zend/Validate/Ccnum.php?rev=654331&view=auto
==============================================================================
--- incubator/shindig/trunk/php/src/common/Zend/Validate/Ccnum.php (added)
+++ incubator/shindig/trunk/php/src/common/Zend/Validate/Ccnum.php Wed May  7 16:48:15 2008
@@ -0,0 +1,111 @@
+<?php
+
+/**
+ * Zend Framework
+ *
+ * LICENSE
+ *
+ * This source file is subject to the new BSD license that is bundled
+ * with this package in the file LICENSE.txt.
+ * It is also available through the world-wide-web at this URL:
+ * http://framework.zend.com/license/new-bsd
+ * If you did not receive a copy of the license and are unable to
+ * obtain it through the world-wide-web, please send an email
+ * to license@zend.com so we can send you a copy immediately.
+ *
+ * @category   Zend
+ * @package    Zend_Validate
+ * @copyright  Copyright (c) 2005-2008 Zend Technologies USA Inc. (http://www.zend.com)
+ * @license    http://framework.zend.com/license/new-bsd     New BSD License
+ * @version    $Id: Ccnum.php 8064 2008-02-16 10:58:39Z thomas $
+ */
+
+
+/**
+ * @see Zend_Validate_Abstract
+ */
+require_once 'Zend/Validate/Abstract.php';
+
+
+/**
+ * @category   Zend
+ * @package    Zend_Validate
+ * @copyright  Copyright (c) 2005-2008 Zend Technologies USA Inc. (http://www.zend.com)
+ * @license    http://framework.zend.com/license/new-bsd     New BSD License
+ */
+class Zend_Validate_Ccnum extends Zend_Validate_Abstract
+{
+    /**
+     * Validation failure message key for when the value is not of valid length
+     */
+    const LENGTH   = 'ccnumLength';
+
+    /**
+     * Validation failure message key for when the value fails the mod-10 checksum
+     */
+    const CHECKSUM = 'ccnumChecksum';
+
+    /**
+     * Digits filter for input
+     *
+     * @var Zend_Filter_Digits
+     */
+    protected static $_filter = null;
+
+    /**
+     * Validation failure message template definitions
+     *
+     * @var array
+     */
+    protected $_messageTemplates = array(
+        self::LENGTH   => "'%value%' must contain between 13 and 19 digits",
+        self::CHECKSUM => "Luhn algorithm (mod-10 checksum) failed on '%value%'"
+    );
+
+    /**
+     * Defined by Zend_Validate_Interface
+     *
+     * Returns true if and only if $value follows the Luhn algorithm (mod-10 checksum)
+     *
+     * @param  string $value
+     * @return boolean
+     */
+    public function isValid($value)
+    {
+        $this->_setValue($value);
+
+        if (null === self::$_filter) {
+            /**
+             * @see Zend_Filter_Digits
+             */
+            require_once 'Zend/Filter/Digits.php';
+            self::$_filter = new Zend_Filter_Digits();
+        }
+
+        $valueFiltered = self::$_filter->filter($value);
+
+        $length = strlen($valueFiltered);
+
+        if ($length < 13 || $length > 19) {
+            $this->_error(self::LENGTH);
+            return false;
+        }
+
+        $sum    = 0;
+        $weight = 2;
+
+        for ($i = $length - 2; $i >= 0; $i--) {
+            $digit = $weight * $valueFiltered[$i];
+            $sum += floor($digit / 10) + $digit % 10;
+            $weight = $weight % 2 + 1;
+        }
+
+        if ((10 - $sum % 10) % 10 != $valueFiltered[$length - 1]) {
+            $this->_error(self::CHECKSUM, $valueFiltered);
+            return false;
+        }
+
+        return true;
+    }
+
+}

Added: incubator/shindig/trunk/php/src/common/Zend/Validate/Date.php
URL: http://svn.apache.org/viewvc/incubator/shindig/trunk/php/src/common/Zend/Validate/Date.php?rev=654331&view=auto
==============================================================================
--- incubator/shindig/trunk/php/src/common/Zend/Validate/Date.php (added)
+++ incubator/shindig/trunk/php/src/common/Zend/Validate/Date.php Wed May  7 16:48:15 2008
@@ -0,0 +1,181 @@
+<?php
+
+/**
+ * Zend Framework
+ *
+ * LICENSE
+ *
+ * This source file is subject to the new BSD license that is bundled
+ * with this package in the file LICENSE.txt.
+ * It is also available through the world-wide-web at this URL:
+ * http://framework.zend.com/license/new-bsd
+ * If you did not receive a copy of the license and are unable to
+ * obtain it through the world-wide-web, please send an email
+ * to license@zend.com so we can send you a copy immediately.
+ *
+ * @category   Zend
+ * @package    Zend_Validate
+ * @copyright  Copyright (c) 2005-2008 Zend Technologies USA Inc. (http://www.zend.com)
+ * @license    http://framework.zend.com/license/new-bsd     New BSD License
+ * @version    $Id: Date.php 8553 2008-03-05 16:39:50Z darby $
+ */
+
+
+/**
+ * @see Zend_Validate_Abstract
+ */
+require_once 'Zend/Validate/Abstract.php';
+
+
+/**
+ * @category   Zend
+ * @package    Zend_Validate
+ * @copyright  Copyright (c) 2005-2008 Zend Technologies USA Inc. (http://www.zend.com)
+ * @license    http://framework.zend.com/license/new-bsd     New BSD License
+ */
+class Zend_Validate_Date extends Zend_Validate_Abstract
+{
+    /**
+     * Validation failure message key for when the value does not follow the YYYY-MM-DD format
+     */
+    const NOT_YYYY_MM_DD = 'dateNotYYYY-MM-DD';
+
+    /**
+     * Validation failure message key for when the value does not appear to be a valid date
+     */
+    const INVALID        = 'dateInvalid';
+
+    /**
+     * Validation failure message key for when the value does not fit the given dateformat or locale
+     */
+    const FALSEFORMAT    = 'dateFalseFormat';
+
+    /**
+     * Validation failure message template definitions
+     *
+     * @var array
+     */
+    protected $_messageTemplates = array(
+        self::NOT_YYYY_MM_DD => "'%value%' is not of the format YYYY-MM-DD",
+        self::INVALID        => "'%value%' does not appear to be a valid date",
+        self::FALSEFORMAT    => "'%value%' does not fit given date format"
+    );
+
+    /**
+     * Optional format
+     *
+     * @var string|null
+     */
+    protected $_format;
+
+    /**
+     * Optional locale
+     *
+     * @var string|Zend_Locale|null
+     */
+    protected $_locale;
+
+    /**
+     * Sets validator options
+     *
+     * @param  string             $format OPTIONAL
+     * @param  string|Zend_Locale $locale OPTIONAL
+     * @return void
+     */
+    public function __construct($format = null, $locale = null)
+    {
+        $this->setFormat($format);
+        $this->setLocale($locale);
+    }
+
+    /**
+     * Returns the locale option
+     *
+     * @return string|Zend_Locale|null
+     */
+    public function getLocale()
+    {
+        return $this->_locale;
+    }
+
+    /**
+     * Sets the locale option
+     *
+     * @param  string|Zend_Locale $locale
+     * @return Zend_Validate_Date provides a fluent interface
+     */
+    public function setLocale($locale = null)
+    {
+        if ($locale !== null) {
+            require_once 'Zend/Locale.php';
+            if (!Zend_Locale::isLocale($locale)) {
+                require_once 'Zend/Validate/Exception.php';
+                throw new Zend_Validate_Exception("The locale '$locale' is no known locale");
+            }
+        }
+        $this->_locale = $locale;
+        return $this;
+    }
+
+    /**
+     * Returns the locale option
+     *
+     * @return string|null
+     */
+    public function getFormat()
+    {
+        return $this->_format;
+    }
+
+    /**
+     * Sets the format option
+     *
+     * @param  string $format
+     * @return Zend_Validate_Date provides a fluent interface
+     */
+    public function setFormat($format = null)
+    {
+        $this->_format = $format;
+        return $this;
+    }
+
+    /**
+     * Defined by Zend_Validate_Interface
+     *
+     * Returns true if $value is a valid date of the format YYYY-MM-DD
+     * If optional $format or $locale is set the date format is checked
+     * according to Zend_Date, see Zend_Date::isDate()
+     *
+     * @param  string $value
+     * @return boolean
+     */
+    public function isValid($value)
+    {
+        $valueString = (string) $value;
+
+        $this->_setValue($valueString);
+
+        if (($this->_format !== null) or ($this->_locale !== null)) {
+            require_once 'Zend/Date.php';
+            if (!Zend_Date::isDate($value, $this->_format, $this->_locale)) {
+                $this->_error(self::FALSEFORMAT);
+                return false;
+            }
+        } else {
+            if (!preg_match('/^\d{4}-\d{2}-\d{2}$/', $valueString)) {
+                $this->_error(self::NOT_YYYY_MM_DD);
+                return false;
+            }
+
+            list($year, $month, $day) = sscanf($valueString, '%d-%d-%d');
+
+            if (!checkdate($month, $day, $year)) {
+                $this->_error(self::INVALID);
+                return false;
+            }
+        }
+
+        return true;
+    }
+
+}

Added: incubator/shindig/trunk/php/src/common/Zend/Validate/Digits.php
URL: http://svn.apache.org/viewvc/incubator/shindig/trunk/php/src/common/Zend/Validate/Digits.php?rev=654331&view=auto
==============================================================================
--- incubator/shindig/trunk/php/src/common/Zend/Validate/Digits.php (added)
+++ incubator/shindig/trunk/php/src/common/Zend/Validate/Digits.php Wed May  7 16:48:15 2008
@@ -0,0 +1,100 @@
+<?php
+
+/**
+ * Zend Framework
+ *
+ * LICENSE
+ *
+ * This source file is subject to the new BSD license that is bundled
+ * with this package in the file LICENSE.txt.
+ * It is also available through the world-wide-web at this URL:
+ * http://framework.zend.com/license/new-bsd
+ * If you did not receive a copy of the license and are unable to
+ * obtain it through the world-wide-web, please send an email
+ * to license@zend.com so we can send you a copy immediately.
+ *
+ * @category   Zend
+ * @package    Zend_Validate
+ * @copyright  Copyright (c) 2005-2008 Zend Technologies USA Inc. (http://www.zend.com)
+ * @license    http://framework.zend.com/license/new-bsd     New BSD License
+ * @version    $Id: Digits.php 8064 2008-02-16 10:58:39Z thomas $
+ */
+
+
+/**
+ * @see Zend_Validate_Abstract
+ */
+require_once 'Zend/Validate/Abstract.php';
+
+
+/**
+ * @category   Zend
+ * @package    Zend_Validate
+ * @copyright  Copyright (c) 2005-2008 Zend Technologies USA Inc. (http://www.zend.com)
+ * @license    http://framework.zend.com/license/new-bsd     New BSD License
+ */
+class Zend_Validate_Digits extends Zend_Validate_Abstract
+{
+    /**
+     * Validation failure message key for when the value contains non-digit characters
+     */
+    const NOT_DIGITS = 'notDigits';
+
+    /**
+     * Validation failure message key for when the value is an empty string
+     */
+    const STRING_EMPTY = 'stringEmpty';
+
+    /**
+     * Digits filter used for validation
+     *
+     * @var Zend_Filter_Digits
+     */
+    protected static $_filter = null;
+
+    /**
+     * Validation failure message template definitions
+     *
+     * @var array
+     */
+    protected $_messageTemplates = array(
+        self::NOT_DIGITS   => "'%value%' contains not only digit characters",
+        self::STRING_EMPTY => "'%value%' is an empty string"
+    );
+
+    /**
+     * Defined by Zend_Validate_Interface
+     *
+     * Returns true if and only if $value only contains digit characters
+     *
+     * @param  string $value
+     * @return boolean
+     */
+    public function isValid($value)
+    {
+        $valueString = (string) $value;
+
+        $this->_setValue($valueString);
+
+        if ('' === $valueString) {
+            $this->_error(self::STRING_EMPTY);
+            return false;
+        }
+
+        if (null === self::$_filter) {
+            /**
+             * @see Zend_Filter_Digits
+             */
+            require_once 'Zend/Filter/Digits.php';
+            self::$_filter = new Zend_Filter_Digits();
+        }
+
+        if ($valueString !== self::$_filter->filter($valueString)) {
+            $this->_error(self::NOT_DIGITS);
+            return false;
+        }
+
+        return true;
+    }
+
+}

Added: incubator/shindig/trunk/php/src/common/Zend/Validate/EmailAddress.php
URL: http://svn.apache.org/viewvc/incubator/shindig/trunk/php/src/common/Zend/Validate/EmailAddress.php?rev=654331&view=auto
==============================================================================
--- incubator/shindig/trunk/php/src/common/Zend/Validate/EmailAddress.php (added)
+++ incubator/shindig/trunk/php/src/common/Zend/Validate/EmailAddress.php Wed May  7 16:48:15 2008
@@ -0,0 +1,245 @@
+<?php
+
+/**
+ * Zend Framework
+ *
+ * LICENSE
+ *
+ * This source file is subject to the new BSD license that is bundled
+ * with this package in the file LICENSE.txt.
+ * It is also available through the world-wide-web at this URL:
+ * http://framework.zend.com/license/new-bsd
+ * If you did not receive a copy of the license and are unable to
+ * obtain it through the world-wide-web, please send an email
+ * to license@zend.com so we can send you a copy immediately.
+ *
+ * @category   Zend
+ * @package    Zend_Validate
+ * @copyright  Copyright (c) 2005-2008 Zend Technologies USA Inc. (http://www.zend.com)
+ * @license    http://framework.zend.com/license/new-bsd     New BSD License
+ * @version    $Id: EmailAddress.php 8986 2008-03-21 21:38:32Z matthew $
+ */
+
+
+/**
+ * @see Zend_Validate_Abstract
+ */
+require_once 'Zend/Validate/Abstract.php';
+
+
+/**
+ * @see Zend_Validate_Hostname
+ */
+require_once 'Zend/Validate/Hostname.php';
+
+
+/**
+ * @category   Zend
+ * @package    Zend_Validate
+ * @copyright  Copyright (c) 2005-2008 Zend Technologies USA Inc. (http://www.zend.com)
+ * @license    http://framework.zend.com/license/new-bsd     New BSD License
+ */
+class Zend_Validate_EmailAddress extends Zend_Validate_Abstract
+{
+
+    const INVALID            = 'emailAddressInvalid';
+    const INVALID_HOSTNAME   = 'emailAddressInvalidHostname';
+    const INVALID_MX_RECORD  = 'emailAddressInvalidMxRecord';
+    const DOT_ATOM           = 'emailAddressDotAtom';
+    const QUOTED_STRING      = 'emailAddressQuotedString';
+    const INVALID_LOCAL_PART = 'emailAddressInvalidLocalPart';
+
+    /**
+     * @var array
+     */
+    protected $_messageTemplates = array(
+        self::INVALID            => "'%value%' is not a valid email address in the basic format local-part@hostname",
+        self::INVALID_HOSTNAME   => "'%hostname%' is not a valid hostname for email address '%value%'",
+        self::INVALID_MX_RECORD  => "'%hostname%' does not appear to have a valid MX record for the email address '%value%'",
+        self::DOT_ATOM           => "'%localPart%' not matched against dot-atom format",
+        self::QUOTED_STRING      => "'%localPart%' not matched against quoted-string format",
+        self::INVALID_LOCAL_PART => "'%localPart%' is not a valid local part for email address '%value%'"
+    );
+
+    /**
+     * @var array
+     */
+    protected $_messageVariables = array(
+        'hostname'  => '_hostname',
+        'localPart' => '_localPart'
+    );
+
+    /**
+     * Local object for validating the hostname part of an email address
+     *
+     * @var Zend_Validate_Hostname
+     */
+    public $hostnameValidator;
+
+    /**
+     * Whether we check for a valid MX record via DNS
+     *
+     * @var boolean
+     */
+    protected $_validateMx = false;
+
+    /**
+     * @var string
+     */
+    protected $_hostname;
+
+    /**
+     * @var string
+     */
+    protected $_localPart;
+
+    /**
+     * Instantiates hostname validator for local use
+     *
+     * You can pass a bitfield to determine what types of hostnames are allowed.
+     * These bitfields are defined by the ALLOW_* constants in Zend_Validate_Hostname
+     * The default is to allow DNS hostnames only
+     *
+     * @param integer                $allow             OPTIONAL
+     * @param bool                   $validateMx        OPTIONAL
+     * @param Zend_Validate_Hostname $hostnameValidator OPTIONAL
+     * @return void
+     */
+    public function __construct($allow = Zend_Validate_Hostname::ALLOW_DNS, $validateMx = false, Zend_Validate_Hostname $hostnameValidator = null)
+    {
+        $this->setValidateMx($validateMx);
+        $this->setHostnameValidator($hostnameValidator, $allow);
+    }
+
+    /**
+     * @param Zend_Validate_Hostname $hostnameValidator OPTIONAL
+     * @param int                    $allow             OPTIONAL
+     * @return void
+     */
+    public function setHostnameValidator(Zend_Validate_Hostname $hostnameValidator = null, $allow = Zend_Validate_Hostname::ALLOW_DNS)
+    {
+        if ($hostnameValidator === null) {
+            $hostnameValidator = new Zend_Validate_Hostname($allow);
+        }
+        $this->hostnameValidator = $hostnameValidator;
+    }
+
+    /**
+     * Whether MX checking via dns_get_mx is supported or not
+     *
+     * This currently only works on UNIX systems
+     *
+     * @return boolean
+     */
+    public function validateMxSupported()
+    {
+        return function_exists('dns_get_mx');
+    }
+
+    /**
+     * Set whether we check for a valid MX record via DNS
+     *
+     * This only applies when DNS hostnames are validated
+     *
+     * @param boolean $allowed Set allowed to true to validate for MX records, and false to not validate them
+     */
+    public function setValidateMx($allowed)
+    {
+        $this->_validateMx = (bool) $allowed;
+    }
+
+    /**
+     * Defined by Zend_Validate_Interface
+     *
+     * Returns true if and only if $value is a valid email address
+     * according to RFC2822
+     *
+     * @link   http://www.ietf.org/rfc/rfc2822.txt RFC2822
+     * @link   http://www.columbia.edu/kermit/ascii.html US-ASCII characters
+     * @param  string $value
+     * @return boolean
+     */
+    public function isValid($value)
+    {
+        $valueString = (string) $value;
+
+        $this->_setValue($valueString);
+
+        // Split email address up
+        if (!preg_match('/^(.+)@([^@]+)$/', $valueString, $matches)) {
+            $this->_error(self::INVALID);
+            return false;
+        }
+
+        $this->_localPart = $matches[1];
+        $this->_hostname  = $matches[2];
+
+        // Match hostname part
+        $hostnameResult = $this->hostnameValidator->setTranslator($this->getTranslator())
+                               ->isValid($this->_hostname);
+        if (!$hostnameResult) {
+            $this->_error(self::INVALID_HOSTNAME);
+
+            // Get messages and errors from hostnameValidator
+            foreach ($this->hostnameValidator->getMessages() as $message) {
+                $this->_messages[] = $message;
+            }
+            foreach ($this->hostnameValidator->getErrors() as $error) {
+                $this->_errors[] = $error;
+            }
+        }
+
+        // MX check on hostname via dns_get_record()
+        if ($this->_validateMx) {
+            if ($this->validateMxSupported()) {
+                $result = dns_get_mx($this->_hostname, $mxHosts);
+                if (count($mxHosts) < 1) {
+                    $hostnameResult = false;
+                    $this->_error(self::INVALID_MX_RECORD);
+                }
+            } else {
+                /**
+                 * MX checks are not supported by this system
+                 * @see Zend_Validate_Exception
+                 */
+                require_once 'Zend/Validate/Exception.php';
+                throw new Zend_Validate_Exception('Internal error: MX checking not available on this system');
+            }
+        }
+
+        // First try to match the local part on the common dot-atom format
+        $localResult = false;
+
+        // Dot-atom characters are: 1*atext *("." 1*atext)
+        // atext: ALPHA / DIGIT / and "!", "#", "$", "%", "&", "'", "*",
+        //        "-", "/", "=", "?", "^", "_", "`", "{", "|", "}", "~"
+        $atext = 'a-zA-Z0-9\x21\x23\x24\x25\x26\x27\x2a\x2b\x2d\x2f\x3d\x3f\x5e\x5f\x60\x7b\x7c\x7d';
+        if (preg_match('/^[' . $atext . ']+(\x2e+[' . $atext . ']+)*$/', $this->_localPart)) {
+            $localResult = true;
+        } else {
+            // Try quoted string format
+
+            // Quoted-string characters are: DQUOTE *([FWS] qtext/quoted-pair) [FWS] DQUOTE
+            // qtext: Non white space controls, and the rest of the US-ASCII characters not
+            //   including "\" or the quote character
+            $noWsCtl    = '\x01-\x08\x0b\x0c\x0e-\x1f\x7f';
+            $qtext      = $noWsCtl . '\x21\x23-\x5b\x5d-\x7e';
+            $ws         = '\x20\x09';
+            if (preg_match('/^\x22([' . $ws . $qtext . '])*[$ws]?\x22$/', $this->_localPart)) {
+                $localResult = true;
+            } else {
+                $this->_error(self::DOT_ATOM);
+                $this->_error(self::QUOTED_STRING);
+                $this->_error(self::INVALID_LOCAL_PART);
+            }
+        }
+
+        // If both parts valid, return true
+        if ($localResult && $hostnameResult) {
+            return true;
+        } else {
+            return false;
+        }
+    }
+
+}

Added: incubator/shindig/trunk/php/src/common/Zend/Validate/Exception.php
URL: http://svn.apache.org/viewvc/incubator/shindig/trunk/php/src/common/Zend/Validate/Exception.php?rev=654331&view=auto
==============================================================================
--- incubator/shindig/trunk/php/src/common/Zend/Validate/Exception.php (added)
+++ incubator/shindig/trunk/php/src/common/Zend/Validate/Exception.php Wed May  7 16:48:15 2008
@@ -0,0 +1,37 @@
+<?php
+
+/**
+ * Zend Framework
+ *
+ * LICENSE
+ *
+ * This source file is subject to the new BSD license that is bundled
+ * with this package in the file LICENSE.txt.
+ * It is also available through the world-wide-web at this URL:
+ * http://framework.zend.com/license/new-bsd
+ * If you did not receive a copy of the license and are unable to
+ * obtain it through the world-wide-web, please send an email
+ * to license@zend.com so we can send you a copy immediately.
+ *
+ * @category   Zend
+ * @package    Zend_Validate
+ * @copyright  Copyright (c) 2005-2008 Zend Technologies USA Inc. (http://www.zend.com)
+ * @license    http://framework.zend.com/license/new-bsd     New BSD License
+ * @version    $Id: Exception.php 8064 2008-02-16 10:58:39Z thomas $
+ */
+
+
+/**
+ * @see Zend_Exception
+ */
+require_once 'Zend/Exception.php';
+
+
+/**
+ * @category   Zend
+ * @package    Zend_Validate
+ * @copyright  Copyright (c) 2005-2008 Zend Technologies USA Inc. (http://www.zend.com)
+ * @license    http://framework.zend.com/license/new-bsd     New BSD License
+ */
+class Zend_Validate_Exception extends Zend_Exception
+{}

Added: incubator/shindig/trunk/php/src/common/Zend/Validate/Float.php
URL: http://svn.apache.org/viewvc/incubator/shindig/trunk/php/src/common/Zend/Validate/Float.php?rev=654331&view=auto
==============================================================================
--- incubator/shindig/trunk/php/src/common/Zend/Validate/Float.php (added)
+++ incubator/shindig/trunk/php/src/common/Zend/Validate/Float.php Wed May  7 16:48:15 2008
@@ -0,0 +1,75 @@
+<?php
+
+/**
+ * Zend Framework
+ *
+ * LICENSE
+ *
+ * This source file is subject to the new BSD license that is bundled
+ * with this package in the file LICENSE.txt.
+ * It is also available through the world-wide-web at this URL:
+ * http://framework.zend.com/license/new-bsd
+ * If you did not receive a copy of the license and are unable to
+ * obtain it through the world-wide-web, please send an email
+ * to license@zend.com so we can send you a copy immediately.
+ *
+ * @category   Zend
+ * @package    Zend_Validate
+ * @copyright  Copyright (c) 2005-2008 Zend Technologies USA Inc. (http://www.zend.com)
+ * @license    http://framework.zend.com/license/new-bsd     New BSD License
+ * @version    $Id: Float.php 8910 2008-03-19 20:19:23Z thomas $
+ */
+
+
+/**
+ * @see Zend_Validate_Abstract
+ */
+require_once 'Zend/Validate/Abstract.php';
+
+
+/**
+ * @category   Zend
+ * @package    Zend_Validate
+ * @copyright  Copyright (c) 2005-2008 Zend Technologies USA Inc. (http://www.zend.com)
+ * @license    http://framework.zend.com/license/new-bsd     New BSD License
+ */
+class Zend_Validate_Float extends Zend_Validate_Abstract
+{
+
+    const NOT_FLOAT = 'notFloat';
+
+    /**
+     * @var array
+     */
+    protected $_messageTemplates = array(
+        self::NOT_FLOAT => "'%value%' does not appear to be a float"
+    );
+
+    /**
+     * Defined by Zend_Validate_Interface
+     *
+     * Returns true if and only if $value is a floating-point value
+     *
+     * @param  string $value
+     * @return boolean
+     */
+    public function isValid($value)
+    {
+        $valueString = (string) $value;
+
+        $this->_setValue($valueString);
+
+        $locale = localeconv();
+
+        $valueFiltered = str_replace($locale['thousands_sep'], '', $valueString);
+        $valueFiltered = str_replace($locale['decimal_point'], '.', $valueFiltered);
+
+        if (strval(floatval($valueFiltered)) != $valueFiltered) {
+            $this->_error();
+            return false;
+        }
+
+        return true;
+    }
+
+}

Added: incubator/shindig/trunk/php/src/common/Zend/Validate/GreaterThan.php
URL: http://svn.apache.org/viewvc/incubator/shindig/trunk/php/src/common/Zend/Validate/GreaterThan.php?rev=654331&view=auto
==============================================================================
--- incubator/shindig/trunk/php/src/common/Zend/Validate/GreaterThan.php (added)
+++ incubator/shindig/trunk/php/src/common/Zend/Validate/GreaterThan.php Wed May  7 16:48:15 2008
@@ -0,0 +1,114 @@
+<?php
+
+/**
+ * Zend Framework
+ *
+ * LICENSE
+ *
+ * This source file is subject to the new BSD license that is bundled
+ * with this package in the file LICENSE.txt.
+ * It is also available through the world-wide-web at this URL:
+ * http://framework.zend.com/license/new-bsd
+ * If you did not receive a copy of the license and are unable to
+ * obtain it through the world-wide-web, please send an email
+ * to license@zend.com so we can send you a copy immediately.
+ *
+ * @category   Zend
+ * @package    Zend_Validate
+ * @copyright  Copyright (c) 2005-2008 Zend Technologies USA Inc. (http://www.zend.com)
+ * @license    http://framework.zend.com/license/new-bsd     New BSD License
+ * @version    $Id: GreaterThan.php 8064 2008-02-16 10:58:39Z thomas $
+ */
+
+
+/**
+ * @see Zend_Validate_Abstract
+ */
+require_once 'Zend/Validate/Abstract.php';
+
+
+/**
+ * @category   Zend
+ * @package    Zend_Validate
+ * @copyright  Copyright (c) 2005-2008 Zend Technologies USA Inc. (http://www.zend.com)
+ * @license    http://framework.zend.com/license/new-bsd     New BSD License
+ */
+class Zend_Validate_GreaterThan extends Zend_Validate_Abstract
+{
+
+    const NOT_GREATER = 'notGreaterThan';
+
+    /**
+     * @var array
+     */
+    protected $_messageTemplates = array(
+        self::NOT_GREATER => "'%value%' is not greater than '%min%'"
+    );
+
+    /**
+     * @var array
+     */
+    protected $_messageVariables = array(
+        'min' => '_min'
+    );
+
+    /**
+     * Minimum value
+     *
+     * @var mixed
+     */
+    protected $_min;
+
+    /**
+     * Sets validator options
+     *
+     * @param  mixed $min
+     * @return void
+     */
+    public function __construct($min)
+    {
+        $this->setMin($min);
+    }
+
+    /**
+     * Returns the min option
+     *
+     * @return mixed
+     */
+    public function getMin()
+    {
+        return $this->_min;
+    }
+
+    /**
+     * Sets the min option
+     *
+     * @param  mixed $min
+     * @return Zend_Validate_GreaterThan Provides a fluent interface
+     */
+    public function setMin($min)
+    {
+        $this->_min = $min;
+        return $this;
+    }
+
+    /**
+     * Defined by Zend_Validate_Interface
+     *
+     * Returns true if and only if $value is greater than min option
+     *
+     * @param  mixed $value
+     * @return boolean
+     */
+    public function isValid($value)
+    {
+        $this->_setValue($value);
+
+        if ($this->_min >= $value) {
+            $this->_error();
+            return false;
+        }
+        return true;
+    }
+
+}