~cdparra/gelee/trunk

« back to all changes in this revision

Viewing changes to webui/ecosystem/workspace/ecosystem/uwa-server-original/server/lib/Zend/Validate/Alpha.php

  • Committer: parra
  • Date: 2010-03-15 02:39:02 UTC
  • Revision ID: svn-v4:ac5bba68-f036-4e09-846e-8f32731cc928:trunk/gelee:1433
merged gelee at svn

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
<?php
 
2
 
 
3
/**
 
4
 * Zend Framework
 
5
 *
 
6
 * LICENSE
 
7
 *
 
8
 * This source file is subject to the new BSD license that is bundled
 
9
 * with this package in the file LICENSE.txt.
 
10
 * It is also available through the world-wide-web at this URL:
 
11
 * http://framework.zend.com/license/new-bsd
 
12
 * If you did not receive a copy of the license and are unable to
 
13
 * obtain it through the world-wide-web, please send an email
 
14
 * to license@zend.com so we can send you a copy immediately.
 
15
 *
 
16
 * @category   Zend
 
17
 * @package    Zend_Validate
 
18
 * @copyright  Copyright (c) 2005-2008 Zend Technologies USA Inc. (http://www.zend.com)
 
19
 * @license    http://framework.zend.com/license/new-bsd     New BSD License
 
20
 * @version    $Id: Alpha.php 8064 2008-02-16 10:58:39Z thomas $
 
21
 */
 
22
 
 
23
 
 
24
/**
 
25
 * @see Zend_Validate_Abstract
 
26
 */
 
27
require_once 'Zend/Validate/Abstract.php';
 
28
 
 
29
 
 
30
/**
 
31
 * @category   Zend
 
32
 * @package    Zend_Validate
 
33
 * @copyright  Copyright (c) 2005-2008 Zend Technologies USA Inc. (http://www.zend.com)
 
34
 * @license    http://framework.zend.com/license/new-bsd     New BSD License
 
35
 */
 
36
class Zend_Validate_Alpha extends Zend_Validate_Abstract
 
37
{
 
38
    /**
 
39
     * Validation failure message key for when the value contains non-alphabetic characters
 
40
     */
 
41
    const NOT_ALPHA = 'notAlpha';
 
42
 
 
43
    /**
 
44
     * Validation failure message key for when the value is an empty string
 
45
     */
 
46
    const STRING_EMPTY = 'stringEmpty';
 
47
 
 
48
    /**
 
49
     * Whether to allow white space characters; off by default
 
50
     *
 
51
     * @var boolean
 
52
     */
 
53
    public $allowWhiteSpace;
 
54
 
 
55
    /**
 
56
     * Alphabetic filter used for validation
 
57
     *
 
58
     * @var Zend_Filter_Alpha
 
59
     */
 
60
    protected static $_filter = null;
 
61
 
 
62
    /**
 
63
     * Validation failure message template definitions
 
64
     *
 
65
     * @var array
 
66
     */
 
67
    protected $_messageTemplates = array(
 
68
        self::NOT_ALPHA    => "'%value%' has not only alphabetic characters",
 
69
        self::STRING_EMPTY => "'%value%' is an empty string"
 
70
    );
 
71
 
 
72
    /**
 
73
     * Sets default option values for this instance
 
74
     *
 
75
     * @param  boolean $allowWhiteSpace
 
76
     * @return void
 
77
     */
 
78
    public function __construct($allowWhiteSpace = false)
 
79
    {
 
80
        $this->allowWhiteSpace = (boolean) $allowWhiteSpace;
 
81
    }
 
82
 
 
83
    /**
 
84
     * Defined by Zend_Validate_Interface
 
85
     *
 
86
     * Returns true if and only if $value contains only alphabetic characters
 
87
     *
 
88
     * @param  string $value
 
89
     * @return boolean
 
90
     */
 
91
    public function isValid($value)
 
92
    {
 
93
        $valueString = (string) $value;
 
94
 
 
95
        $this->_setValue($valueString);
 
96
 
 
97
        if ('' === $valueString) {
 
98
            $this->_error(self::STRING_EMPTY);
 
99
            return false;
 
100
        }
 
101
 
 
102
        if (null === self::$_filter) {
 
103
            /**
 
104
             * @see Zend_Filter_Alpha
 
105
             */
 
106
            require_once 'Zend/Filter/Alpha.php';
 
107
            self::$_filter = new Zend_Filter_Alpha();
 
108
        }
 
109
 
 
110
        self::$_filter->allowWhiteSpace = $this->allowWhiteSpace;
 
111
 
 
112
        if ($valueString !== self::$_filter->filter($valueString)) {
 
113
            $this->_error(self::NOT_ALPHA);
 
114
            return false;
 
115
        }
 
116
 
 
117
        return true;
 
118
    }
 
119
 
 
120
}