|
Moodle
2.2.1
http://www.collinsharper.com
|
00001 <?php 00023 require_once 'Zend/Validate/Abstract.php'; 00024 00031 class Zend_Validate_Identical extends Zend_Validate_Abstract 00032 { 00037 const NOT_SAME = 'notSame'; 00038 const MISSING_TOKEN = 'missingToken'; 00039 00044 protected $_messageTemplates = array( 00045 self::NOT_SAME => "The two given tokens do not match", 00046 self::MISSING_TOKEN => 'No token was provided to match against', 00047 ); 00048 00052 protected $_messageVariables = array( 00053 'token' => '_tokenString' 00054 ); 00055 00060 protected $_tokenString; 00061 protected $_token; 00062 protected $_strict = true; 00063 00070 public function __construct($token = null) 00071 { 00072 if ($token instanceof Zend_Config) { 00073 $token = $token->toArray(); 00074 } 00075 00076 if (is_array($token) && array_key_exists('token', $token)) { 00077 if (array_key_exists('strict', $token)) { 00078 $this->setStrict($token['strict']); 00079 } 00080 00081 $this->setToken($token['token']); 00082 } else if (null !== $token) { 00083 $this->setToken($token); 00084 } 00085 } 00086 00092 public function getToken() 00093 { 00094 return $this->_token; 00095 } 00096 00103 public function setToken($token) 00104 { 00105 $this->_tokenString = (string) $token; 00106 $this->_token = $token; 00107 return $this; 00108 } 00109 00115 public function getStrict() 00116 { 00117 return $this->_strict; 00118 } 00119 00125 public function setStrict($strict) 00126 { 00127 $this->_strict = (boolean) $strict; 00128 return $this; 00129 } 00130 00141 public function isValid($value, $context = null) 00142 { 00143 $this->_setValue((string) $value); 00144 00145 if (($context !== null) && isset($context) && array_key_exists($this->getToken(), $context)) { 00146 $token = $context[$this->getToken()]; 00147 } else { 00148 $token = $this->getToken(); 00149 } 00150 00151 if ($token === null) { 00152 $this->_error(self::MISSING_TOKEN); 00153 return false; 00154 } 00155 00156 $strict = $this->getStrict(); 00157 if (($strict && ($value !== $token)) || (!$strict && ($value != $token))) { 00158 $this->_error(self::NOT_SAME); 00159 return false; 00160 } 00161 00162 return true; 00163 } 00164 }