3 * Copyright (c) STMicroelectronics, 2007. All Rights Reserved.
5 * Originally written by Manuel VACELET, 2007.
7 * This file is a part of Codendi.
9 * Codendi is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 2 of the License, or
12 * (at your option) any later version.
14 * Codendi is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
19 * You should have received a copy of the GNU General Public License
20 * along with Codendi. If not, see <http://www.gnu.org/licenses/>.
23 require_once('common/valid/Valid.class.php');
26 * Check that value is a decimal integer greater or equal to zero.
31 function validate($value) {
32 $this->addRule(new Rule_Int());
33 $this->addRule(new Rule_GreaterOrEqual(0));
34 return parent::validate($value);
40 * Check that group_id variable is valid
44 function Valid_GroupId() {
45 parent::Valid('group_id');
46 //$this->setErrorMessage(_("Error - No group_id was chosen."));
49 function validate($value) {
50 $this->addRule(new Rule_Int());
51 $this->addRule(new Rule_GreaterThan(0));
52 return parent::validate($value);
57 * Check that 'pv' parameter is set to an acceptable value.
65 function validate($value) {
66 $this->addRule(new Rule_WhiteList(array(0,1,2)));
67 return parent::validate($value);
72 * Check that value is a string (should always be true).
76 function validate($value) {
77 $this->addRule(new Rule_String());
78 return parent::validate($value);
83 * Check that value is a string with neither carrige return nor null char.
87 function validate($value) {
88 $this->addRule(new Rule_NoCr());
89 return parent::validate($value);
94 * Wrapprt for 'WhiteList' rule
98 function Valid_WhiteList($key, $whitelist) {
100 $this->addRule(new Rule_WhiteList($whitelist));
105 * Check that value match Codendi user short name format.
107 * This rule doesn't check that user actually exists.
109 class Valid_UserNameFormat
110 extends Valid_String {
111 function validate($value) {
112 $this->addRule(new Rule_UserNameFormat());
113 return parent::validate($value);
119 * Check that submitted value is a simple string and a valid Codendi email.
122 extends Valid_String {
125 function Valid_Email($key=null, $separator=null) {
126 if(is_string($separator)) {
127 $this->separator = $separator;
129 $this->separator = null;
134 function validate($value) {
135 $this->addRule(new Rule_Email($this->separator));
136 return parent::validate($value);
141 * Check uploaded file validity.
147 * Is uploaded file empty or not.
149 * @param Array One entry of $_FILES
151 function isEmptyValue($file) {
152 if(!is_array($file)) {
154 } elseif(parent::isEmptyValue($file['name'])) {
162 * Check rules on given file.
164 * @param Array $_FILES superarray.
165 * @param String Index of file to check in $_FILES array.
168 function validate($files, $index) {
169 if(is_array($files) && isset($files[$index])) {
170 $this->addRule(new Rule_File());
171 return parent::validate($files[$index]);
172 } elseif($this->isRequired) {
183 * If $validator is an instance of a Validator, do nothing and returns it
184 * If $validator is a string and a validator exists (Valid_String for 'string', Valid_UInt for 'uint', ...) then creates an instance and returns it
187 /* public static */ function getInstance($validator, $key = null) {
188 if (is_a($validator, 'Valid')) {
190 } else if(is_string($validator) && class_exists('Valid_'.$validator)) {
191 $validator_classname = 'Valid_'.$validator;
192 $v = new $validator_classname($key);