~chroot64bit/zivios/gentoo-experimental

« back to all changes in this revision

Viewing changes to application/library/Zend/Validate/Identical.php

  • Committer: Mustafa A. Hashmi
  • Date: 2008-12-04 13:32:21 UTC
  • Revision ID: mhashmi@zivios.org-20081204133221-0nd1trunwevijj38
Inclusion of new installation framework with ties to zend layout and dojo layout

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
<?php
 
2
/**
 
3
 * Zend Framework
 
4
 *
 
5
 * LICENSE
 
6
 *
 
7
 * This source file is subject to the new BSD license that is bundled
 
8
 * with this package in the file LICENSE.txt.
 
9
 * It is also available through the world-wide-web at this URL:
 
10
 * http://framework.zend.com/license/new-bsd
 
11
 * If you did not receive a copy of the license and are unable to
 
12
 * obtain it through the world-wide-web, please send an email
 
13
 * to license@zend.com so we can send you a copy immediately.
 
14
 *
 
15
 * @category   Zend
 
16
 * @package    Zend_Validate
 
17
 * @copyright  Copyright (c) 2005-2008 Zend Technologies USA Inc. (http://www.zend.com)
 
18
 * @license    http://framework.zend.com/license/new-bsd     New BSD License
 
19
 * @version    $Id: Identical.php 8118 2008-02-18 16:10:32Z matthew $
 
20
 */
 
21
 
 
22
/** Zend_Validate_Abstract */
 
23
require_once 'Zend/Validate/Abstract.php';
 
24
 
 
25
/**
 
26
 * @category   Zend
 
27
 * @package    Zend_Validate
 
28
 * @copyright  Copyright (c) 2005-2008 Zend Technologies USA Inc. (http://www.zend.com)
 
29
 * @license    http://framework.zend.com/license/new-bsd     New BSD License
 
30
 */
 
31
class Zend_Validate_Identical extends Zend_Validate_Abstract
 
32
{
 
33
    /**#@+
 
34
     * Error codes
 
35
     * @const string
 
36
     */
 
37
    const NOT_SAME      = 'notSame';
 
38
    const MISSING_TOKEN = 'missingToken';
 
39
    /**#@-*/
 
40
 
 
41
    /**
 
42
     * Error messages
 
43
     * @var array
 
44
     */
 
45
    protected $_messageTemplates = array(
 
46
        self::NOT_SAME      => 'Tokens do not match',
 
47
        self::MISSING_TOKEN => 'No token was provided to match against',
 
48
    );
 
49
 
 
50
    /**
 
51
     * Original token against which to validate
 
52
     * @var string
 
53
     */
 
54
    protected $_token;
 
55
 
 
56
    /**
 
57
     * Sets validator options
 
58
     *
 
59
     * @param  string $token
 
60
     * @return void
 
61
     */
 
62
    public function __construct($token = null)
 
63
    {
 
64
        if (null !== $token) {
 
65
            $this->setToken($token);
 
66
        }
 
67
    }
 
68
 
 
69
    /**
 
70
     * Set token against which to compare
 
71
     * 
 
72
     * @param  string $token 
 
73
     * @return Zend_Validate_Identical
 
74
     */
 
75
    public function setToken($token)
 
76
    {
 
77
        $this->_token = (string) $token;
 
78
        return $this;
 
79
    }
 
80
 
 
81
    /**
 
82
     * Retrieve token
 
83
     * 
 
84
     * @return string
 
85
     */
 
86
    public function getToken()
 
87
    {
 
88
        return $this->_token;
 
89
    }
 
90
 
 
91
    /**
 
92
     * Defined by Zend_Validate_Interface
 
93
     *
 
94
     * Returns true if and only if a token has been set and the provided value 
 
95
     * matches that token.
 
96
     *
 
97
     * @param  string $value
 
98
     * @return boolean
 
99
     */
 
100
    public function isValid($value)
 
101
    {
 
102
        $this->_setValue($value);
 
103
        $token = $this->getToken();
 
104
 
 
105
        if (empty($token)) {
 
106
            $this->_error(self::MISSING_TOKEN);
 
107
            return false;
 
108
        }
 
109
 
 
110
        if ($value !== $token)  {
 
111
            $this->_error(self::NOT_SAME);
 
112
            return false;
 
113
        }
 
114
 
 
115
        return true;
 
116
    }
 
117
}