noalyss Version-9
Public Member Functions | Private Attributes
HttpInput Class Reference

manage the http input (get , post, request) and extract from an array More...

+ Collaboration diagram for HttpInput:

Public Member Functions

 __toString ()
 
 _construct ()
 
 check_type ($p_name, $p_type)
 Check the type of the value. More...
 
 extract ( $p_name, $p_type="string", $p_default="")
 Retrieve from $p_array,. More...
 
 extract_variable ($p_string)
 Extract variable name from an exception message. More...
 
 get ($p_name, $p_type="string", $p_default="")
 Retrieve from $_GET. More...
 
 get_array ()
 
 get_empty ()
 
 get_value ($p_name, $p_type="string", $p_default="")
 Retrieve from $this->array the variable. More...
 
 post ($p_name, $p_type="string", $p_default="")
 Retrieve from $_POST. More...
 
 request ($p_name, $p_type="string", $p_default="")
 Retrieve from $_REQUEST. More...
 
 set_array ($array)
 
 set_empty ($empty)
 $empty replace the empty value More...
 

Private Attributes

 $array
 
 $empty
 if empty that replace by $empty More...
 

Detailed Description

manage the http input (get , post, request) and extract from an array

Examples
ajax_manage_table_sql.php.

Definition at line 37 of file http_input.class.php.

Member Function Documentation

◆ __toString()

HttpInput::__toString ( )

Definition at line 48 of file http_input.class.php.

48 : string
49 {
50 return "http_input".var_export($this,true);
51 }

◆ _construct()

HttpInput::_construct ( )

Definition at line 43 of file http_input.class.php.

44 {
45 $this->array=null;
46 $this->empty="";
47 }

◆ check_type()

HttpInput::check_type (   $p_name,
  $p_type 
)

Check the type of the value.

Parameters
$p_namename of the variable
$p_typetype of the variable (number,string,text,date,array)
Exceptions
Exceptionif the variable doesn't exist or type incorrect
Todo:
Add regex:pattern

Definition at line 84 of file http_input.class.php.

85 {
86 try
87 {
88 // no check on string
89 if ($p_type=="string" || $p_type=="text")
90 {
91 return;
92 }
93 // Check if number
94 else if ($p_type=="number")
95 {
96 if (trim($this->array[$p_name]) == "")
97 {
98 $this->array[$p_name]=$this->empty;
99 }
100
101 if ( isNumber($this->array[$p_name])==0 )
102 {
103 throw new Exception(_("Type invalide")."[ $p_name ] = {$this->array[$p_name]}"
105 }
106 $this->array[$p_name]=h($this->array[$p_name]);
107 }
108 // Check if date dd.mm.yyyy
109 else if ($p_type=="date")
110 {
111 if (trim($this->array[$p_name]) == "" )
112 {
113 $this->array[$p_name]=$this->empty;
114 }
115 if (isDate($this->array[$p_name]) <> $this->array[$p_name])
116 {
117 throw new Exception(_("Type invalide")."[ $p_name ] = {$this->array[$p_name]}"
119 }
120 $this->array[$p_name]=h($this->array[$p_name]);
121 }
122 else if ($p_type=="raw") {
123 /* NoOperation*/
124 }
125 else if ($p_type=="array")
126 {
127 if ( empty($this->array[$p_name]) )
128 {
129 $this->array[$p_name]=$this->empty;
130 }
131 if (!is_array($this->array[$p_name]) ) {
132 throw new Exception(_("Type invalide")."[ $p_name ] = {$this->array[$p_name]}"
134 }
135 if (is_string($this->array )) {
136 $this->array[$p_name]=h($this->array[$p_name]);
137 }
138 }else {
139 throw new Exception(_("Unknown type"));
140 }
141 }
142 catch (Exception $ex)
143 {
144 throw $ex;
145 }
146 }
isNumber($p_int)
Definition: ac_common.php:215
isDate($p_date)
Definition: ac_common.php:236
h( $row[ 'oa_description'])
$ex
Definition: balance.inc.php:45
$empty
if empty that replace by $empty
const EXC_PARAM_TYPE
Definition: constant.php:344

References $empty, $ex, $p_type, EXC_PARAM_TYPE, h, isDate(), and isNumber().

Referenced by get_value().

+ Here is the call graph for this function:

◆ extract()

HttpInput::extract (   $p_name,
  $p_type = "string",
  $p_default = "" 
)

Retrieve from $p_array,.

Parameters
$p_namename of the variable
$p_typetype of the variable , opt. default string
$p_defaultdefault value is variable is not set
Exceptions
Exceptionif invalid

Definition at line 268 of file http_input.class.php.

269 {
270 try
271 {
272 if ( $this->array === null ) {
273 throw new Exception( _("HTTP266:array not set")) ;
274 }
275 if (func_num_args()==1)
276 return $this->get_value($p_name);
277 if (func_num_args()==2)
278 return $this->get_value($p_name, $p_type);
279 if (func_num_args()==3)
280 return $this->get_value($p_name, $p_type, $p_default);
281 }
282 catch (Exception $exc)
283 {
284 throw $exc;
285 }
286 }
get_value($p_name, $p_type="string", $p_default="")
Retrieve from $this->array the variable.

References $p_type, and get_value().

+ Here is the call graph for this function:

◆ extract_variable()

HttpInput::extract_variable (   $p_string)

Extract variable name from an exception message.

If an exception is thrown then thanks this function it is possible to know what variable triggers the exception

Parameters
type$p_string
Returns
string like "[variable]"

Definition at line 295 of file http_input.class.php.

296 {
297 if (preg_match("/\[.*\]/", $p_string, $found)==1)
298 {
299 return $found[0];
300 }
301 }

◆ get()

HttpInput::get (   $p_name,
  $p_type = "string",
  $p_default = "" 
)

Retrieve from $_GET.

Parameters
$p_namename of the variable
$p_typetype of the variable , opt. default string
$p_defaultdefault value is variable is not set
Exceptions
Exceptionif invalid

Definition at line 195 of file http_input.class.php.

196 {
197 try
198 {
199 $this->array=$_GET;
200 if (func_num_args()==1)
201 return $this->get_value($p_name);
202 if (func_num_args()==2)
203 return $this->get_value($p_name, $p_type);
204 if (func_num_args()==3)
205 return $this->get_value($p_name, $p_type, $p_default);
206 }
207 catch (Exception $exc)
208 {
209 throw $exc;
210 }
211 }
$_GET['qcode']

References $_GET, $p_type, and get_value().

+ Here is the call graph for this function:

◆ get_array()

HttpInput::get_array ( )

Definition at line 52 of file http_input.class.php.

53 {
54 return $this->array;
55 }

References $array.

◆ get_empty()

HttpInput::get_empty ( )

Definition at line 57 of file http_input.class.php.

58 {
59 return $this->empty;
60 }

References $empty.

◆ get_value()

HttpInput::get_value (   $p_name,
  $p_type = "string",
  $p_default = "" 
)

Retrieve from $this->array the variable.

Parameters
$p_namename of the variable
$p_typetype of the variable (number,string or text,date('dd.mm.yyyy'),array)
$p_defaultdefault value is variable
Exceptions
Exceptionif invalid
See also
check_type

Definition at line 156 of file http_input.class.php.

157 {
158 try
159 {
160 if (func_num_args()==3)
161 {
162 if (array_key_exists($p_name,$this->array) )
163 {
164 $this->check_type($p_name, $p_type);
165 if ($p_type != 'raw' && is_string($this->array[$p_name]) ) return preg_replace("/</","< ", $this->array[$p_name]);
166 return $this->array[$p_name];
167 }
168 else
169 {
170 return $p_default;
171 }
172 }
173 if (!array_key_exists($p_name,$this->array))
174 {
175 throw new Exception(_('Paramètre invalide')."[$p_name]",
177 }
178 $this->check_type($p_name, $p_type);
179 if ( is_string($this->array[$p_name]) ) return preg_replace("/</","< ", $this->array[$p_name]);
180 return $this->array[$p_name];
181 }
182 catch (Exception $e)
183 {
184 throw $e;
185 }
186 }
check_type($p_name, $p_type)
Check the type of the value.
const EXC_PARAM_VALUE
Definition: constant.php:343

References $e, $p_type, check_type(), and EXC_PARAM_VALUE.

Referenced by extract(), get(), post(), and request().

+ Here is the call graph for this function:

◆ post()

HttpInput::post (   $p_name,
  $p_type = "string",
  $p_default = "" 
)

Retrieve from $_POST.

Parameters
string$p_namename of the variable
$p_typetype of the variable , opt. default string
$p_defaultdefault value is variable is not set
Exceptions
Exceptionif invalid

Definition at line 220 of file http_input.class.php.

221 {
222 try
223 {
224 $this->array=$_POST;
225 if (func_num_args()==1)
226 return $this->get_value($p_name);
227 if (func_num_args()==2)
228 return $this->get_value($p_name, $p_type);
229 if (func_num_args()==3)
230 return $this->get_value($p_name, $p_type, $p_default);
231 }
232 catch (Exception $exc)
233 {
234 throw $exc;
235 }
236 }
$_POST['ac']
Definition: do.php:310

References $_POST, $p_type, and get_value().

+ Here is the call graph for this function:

◆ request()

HttpInput::request (   $p_name,
  $p_type = "string",
  $p_default = "" 
)

Retrieve from $_REQUEST.

Parameters
$p_namestring name of the variable
$p_typestring type of the variable , opt. default string
$p_defaultstring default value is variable is not set
Exceptions
Exceptionif invalid

Definition at line 244 of file http_input.class.php.

245 {
246 try
247 {
248 $this->array=$_REQUEST;
249 if (func_num_args()==1)
250 return $this->get_value($p_name);
251 if (func_num_args()==2)
252 return $this->get_value($p_name, $p_type);
253 if (func_num_args()==3)
254 return $this->get_value($p_name, $p_type, $p_default);
255 }
256 catch (Exception $exc)
257 {
258 throw $exc;
259 }
260 }
$_REQUEST['ac']

References $_REQUEST, $p_type, and get_value().

+ Here is the call graph for this function:

◆ set_array()

HttpInput::set_array (   $array)

Definition at line 62 of file http_input.class.php.

63 {
64 $this->array=$array;
65 return $this;
66 }

References $array.

◆ set_empty()

HttpInput::set_empty (   $empty)

$empty replace the empty value

Definition at line 71 of file http_input.class.php.

72 {
73 $this->empty=$empty;
74 return $this;
75 }

References $empty.

Field Documentation

◆ $array

HttpInput::$array
private

Definition at line 40 of file http_input.class.php.

Referenced by get_array(), and set_array().

◆ $empty

HttpInput::$empty
private

if empty that replace by $empty

Definition at line 41 of file http_input.class.php.

Referenced by check_type(), get_empty(), and set_empty().


The documentation for this class was generated from the following file: