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

 _construct ()
 
 check_type ($p_name, $p_type)
 Check the type of the value. More...
 
 extract ($p_array, $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

◆ _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,date,array)
Exceptions
Exceptionif the variable doesn't exist or type incorrect
Todo:
Add regex:pattern

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

81  {
82  try
83  {
84  // no check on string
85  if ($p_type=="string")
86  {
87  return;
88  }
89  // Check if number
90  else if ($p_type=="number")
91  {
92  if (trim($this->array[$p_name]) == "")
93  {
94  $this->array[$p_name]=$this->empty;
95  }
96 
97  if ( isNumber($this->array[$p_name])==0 )
98  {
99  throw new Exception(_("Type invalide")."[ $p_name ] = {$this->array[$p_name]}"
100  , EXC_PARAM_TYPE);
101  }
102  $this->array[$p_name]=h($this->array[$p_name]);
103  }
104  // Check if date dd.mm.yyyy
105  else if ($p_type=="date")
106  {
107  if (trim($this->array[$p_name]) == "" )
108  {
109  $this->array[$p_name]=$this->empty;
110  }
111  if (isDate($this->array[$p_name]) <> $this->array[$p_name])
112  {
113  throw new Exception(_("Type invalide")."[ $p_name ] = {$this->array[$p_name]}"
114  , EXC_PARAM_TYPE);
115  }
116  $this->array[$p_name]=h($this->array[$p_name]);
117  }
118  else if ($p_type=="array")
119  {
120  if ( empty($this->array[$p_name]) )
121  {
122  $this->array[$p_name]=$this->empty;
123  }
124  if (!is_array($this->array[$p_name]) ) {
125  throw new Exception(_("Type invalide")."[ $p_name ] = {$this->array[$p_name]}"
126  , EXC_PARAM_TYPE);
127  }
128  if (is_string($this->array )) {
129  $this->array[$p_name]=h($this->array[$p_name]);
130  }
131  }else {
132  throw new Exception(_("Unknown type"));
133  }
134  }
135  catch (Exception $ex)
136  {
137  throw $ex;
138  }
139  }

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_array,
  $p_name,
  $p_type = "string",
  $p_default = "" 
)

Retrieve from $p_array.

Parameters
$p_arraysource
$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 262 of file http_input.class.php.

263  {
264  try
265  {
266  $this->array=$p_array;
267  if (func_num_args()==2)
268  return $this->get_value($p_name);
269  if (func_num_args()==3)
270  return $this->get_value($p_name, $p_type);
271  if (func_num_args()==4)
272  return $this->get_value($p_name, $p_type, $p_default);
273  }
274  catch (Exception $exc)
275  {
276  throw $exc;
277  }
278  }

References $p_array, $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 287 of file http_input.class.php.

288  {
289  if (preg_match("/\[.*\]/", $p_string, $found)==1)
290  {
291  return $found[0];
292  }
293  }

◆ 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 188 of file http_input.class.php.

189  {
190  try
191  {
192  $this->array=$_GET;
193  if (func_num_args()==1)
194  return $this->get_value($p_name);
195  if (func_num_args()==2)
196  return $this->get_value($p_name, $p_type);
197  if (func_num_args()==3)
198  return $this->get_value($p_name, $p_type, $p_default);
199  }
200  catch (Exception $exc)
201  {
202  throw $exc;
203  }
204  }

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

+ Here is the call graph for this function:

◆ get_array()

HttpInput::get_array ( )

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

49  {
50  return $this->array;
51  }

References $array.

◆ get_empty()

HttpInput::get_empty ( )

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

54  {
55  return $this->empty;
56  }

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,date('dd.mm.yyyy'),array)
$p_defaultdefault value is variable
Exceptions
Exceptionif invalid
See also
check_type

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

150  {
151  try
152  {
153  if (func_num_args()==3)
154  {
155  if (array_key_exists($p_name,$this->array) )
156  {
157  $this->check_type($p_name, $p_type);
158  if ( is_string($this->array[$p_name]) ) return preg_replace("/</","< ", $this->array[$p_name]);
159  return $this->array[$p_name];
160  }
161  else
162  {
163  return $p_default;
164  }
165  }
166  if (!array_key_exists($p_name,$this->array))
167  {
168  throw new Exception(_('Paramètre invalide')."[$p_name]",
170  }
171  $this->check_type($p_name, $p_type);
172  if ( is_string($this->array[$p_name]) ) return preg_replace("/</","< ", $this->array[$p_name]);
173  return $this->array[$p_name];
174  }
175  catch (Exception $e)
176  {
177  throw $e;
178  }
179  }

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 213 of file http_input.class.php.

214  {
215  try
216  {
217  $this->array=$_POST;
218  if (func_num_args()==1)
219  return $this->get_value($p_name);
220  if (func_num_args()==2)
221  return $this->get_value($p_name, $p_type);
222  if (func_num_args()==3)
223  return $this->get_value($p_name, $p_type, $p_default);
224  }
225  catch (Exception $exc)
226  {
227  throw $exc;
228  }
229  }

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_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 237 of file http_input.class.php.

238  {
239  try
240  {
241  $this->array=$_REQUEST;
242  if (func_num_args()==1)
243  return $this->get_value($p_name);
244  if (func_num_args()==2)
245  return $this->get_value($p_name, $p_type);
246  if (func_num_args()==3)
247  return $this->get_value($p_name, $p_type, $p_default);
248  }
249  catch (Exception $exc)
250  {
251  throw $exc;
252  }
253  }

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

+ Here is the call graph for this function:

◆ set_array()

HttpInput::set_array (   $array)

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

59  {
60  $this->array=$array;
61  return $this;
62  }

References $array.

◆ set_empty()

HttpInput::set_empty (   $empty)

$empty replace the empty value

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

68  {
69  $this->empty=$empty;
70  return $this;
71  }

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:
$ex
$ex
Definition: balance.inc.php:45
h
h( $row[ 'oa_description'])
Definition: ajax_anc_detail_operation.php:46
$e
$e
Definition: result_cat_card_summary.php:26
HttpInput\$empty
$empty
if empty that replace by $empty
Definition: http_input.class.php:41
$_POST
$_POST['ac']
Definition: do.php:365
$p_type
$p_type
Definition: export_balance_age_csv.php:45
$_GET
$_GET['qcode']
Definition: category_followup.inc.php:53
EXC_PARAM_VALUE
const EXC_PARAM_VALUE
Definition: constant.php:337
isDate
isDate($p_date)
Definition: ac_common.php:239
HttpInput\get_value
get_value($p_name, $p_type="string", $p_default="")
Retrieve from $this->array the variable.
Definition: http_input.class.php:149
HttpInput\$array
$array
Definition: http_input.class.php:40
isNumber
isNumber($p_int)
Definition: ac_common.php:218
HttpInput\check_type
check_type($p_name, $p_type)
Check the type of the value.
Definition: http_input.class.php:80
$_REQUEST
$_REQUEST['ac']
Definition: ajax_search_action.php:26
EXC_PARAM_TYPE
const EXC_PARAM_TYPE
Definition: constant.php:338
$p_array
$p_array
Definition: ajax_view_mod_stock.php:33