<?php
/*
* Copyright (c) SAFAROFF Creative Agency
* Coded: Agshin Y. Khaligov & Ismayilzadeh Zulfugar
*/
class Request {
function __construct(){
//This is construct of class
}
function __destruct(){
//This is destruct of class
}
function __get($name){
$ret_val = false;
$splitted_name = preg_split('/__/', $name);
if(count($splitted_name)>1){
$request_type = $splitted_name[0];
$variable = $splitted_name[1];
switch($request_type){
case 'POST':{
if(isset($_POST[$variable])){
if(!empty($_POST[$variable]))
$ret_val = $_POST[$variable];
}
break;
}
case 'GET':{
if(isset($_GET[$variable])){
if(!empty($_GET[$variable]))
$ret_val = $_GET[$variable];
}
break;
}
case 'FILES':{
if(isset($_FILES[$variable])){
if(!empty($_FILES[$variable])){
$ret_val = $_FILES[$variable];
}
}
break;
}
}
}
else{
if(isset($_POST[$name])){
if(!empty($_POST[$name])){
$ret_val = $_POST[$name];
}
}
elseif(isset($_GET[$name])){
if(!empty($_GET[$name])){
$ret_val = $_GET[$name];
}
}
elseif(isset($_FILES[$variable])){
if(!empty($_FILES[$variable])){
$ret_val = $_FILES[$variable];
}
}
}
return $this->filter($ret_val);
}
function __call($method, $args){
// This function is for filtering request array with regular expression.
switch($method){
CASE 'POST':{
if(isset($_POST)){
if(!empty($_POST)){
$ret_array = array();
foreach($_POST as $index=>$val){
if(preg_match($args[0], $index)){
$ret_array[$index] = $val;
}
}
}
}
break;
}
CASE 'GET':{
if(isset($_GET)){
if(!empty($_GET)){
$ret_array = array();
foreach($_GET as $index=>$val){
if(preg_match($args[0], $index)){
$ret_array[$index] = $val;
}
}
}
}
break;
}
CASE 'REQUEST':{
// Find the request type
if(isset($_POST)){
if(!empty($_POST)){
$ret_array = $this->POST($args[0]);
}
}
elseif(isset($_GET)){
if(!empty($_GET)){
$ret_array = $this->GET($args[0]);
}
}
break;
}
}
return $ret_array;
}
function filter($data){
/*
* TODO: Find the best way of filtering data
*/
if(is_array($data)){
foreach($data as $key=>$val)
$data[$key] = $this->filter($val);
}
else{
$data = trim($data);
if(get_magic_quotes_gpc()){
$data = stripslashes($data);
}
$data = mysql_real_escape_string($data);
}
return $data;
}
}
?>