3 * Copyright (c) Xerox Corporation, Codendi Team, 2001-2009. All rights reserved
5 * This file is a part of Codendi.
7 * Codendi is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 2 of the License, or
10 * (at your option) any later version.
12 * Codendi is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with Codendi. If not, see <http://www.gnu.org/licenses/>.
21 /* abstract */ class Codendi_Request {
26 var $_validated_input;
32 var $_last_access_to_input;
42 function Codendi_Request($params) {
43 $this->params = $params;
44 $this->_validated_input = array();
45 $this->_last_access_to_input = array();
50 * Get the value of $variable in $this->params (user submitted values).
52 * @param string $variable Name of the parameter to get.
53 * @return mixed If the variable exist, the value is returned (string)
54 * otherwise return false;
56 function get($variable) {
58 return $this->_get($variable, $this->params);
62 * Add a param and/or set its value
65 function set($name, $value) {
66 $this->params[$name] = $value;
71 * Get the value of $variable in $array.
74 * @param string $variable Name of the parameter to get.
75 * @param array $array Name of the parameter to get.
77 function _get($variable, $array) {
78 if ($this->_exist($variable, $array)) {
79 return $array[$variable];
86 * Check if $variable exists in user submitted parameters.
88 * @param string $variable Name of the parameter.
91 function exist($variable) {
92 return $this->_exist($variable, $this->params);
96 * Check if $variable exists in $array.
99 * @param string $variable Name of the parameter.
102 function _exist($variable, $array) {
103 return isset($array[$variable]);
106 * Apply validator on submitted user value.
108 * @param Valid Validator to apply
111 function valid(&$validator) {
112 $this->_validated_input[$validator->getKey()] = true;
114 return $validator->validate($this->get($validator->getKey()));
118 * Apply validator on all values of a submitted user array.
120 * @param Valid Validator to apply
123 function validArray(&$validator) {
124 $this->_validated_input[$validator->getKey()] = true;
126 $array = $this->get($validator->getKey());
127 if (is_array($array)) {
128 if (count($array)>0) {
129 foreach ($array as $key => $v) {
130 if (!$validator->validate($v)) {
135 $isValid = $validator->validate(null);
143 * Apply validator on submitted user value and return the value if valid
144 * Else return default value
145 * @param string $variable Name of the parameter to get.
146 * @param mixed $validator Name of the validator (string, uint, email) or an instance of a validator
147 * @param mixed $default_value Value return if the validator is not valid. Optional, default is null.
149 function getValidated($variable, $validator = 'string', $default_value = null) {
151 if ($v = ValidFactory::getInstance($validator, $variable)) {
152 $is_valid = $this->valid($v);
154 trigger_error('Validator '. $validator .' is not found', E_USER_ERROR);
156 return $is_valid ? $this->get($variable) : $default_value;*/
157 return $this->get($variable);