added class data to store $request->data

This commit is contained in:
jelhan 2013-10-26 20:50:05 +02:00
parent c8efaf5617
commit 6c68869454
4 changed files with 73 additions and 8 deletions

View file

@ -1,4 +1,5 @@
<?php
require_once "classes/class.request.php";
require_once "classes/class.datahandler.php";
@ -23,7 +24,7 @@ if (isset($_REQUEST['action'])) {
$request = new Request();
$request->id = (isset($_POST['id'])) ? (string) $_POST['id'] : '';
$request->version = (isset($_POST['version'])) ? (string) $_POST['version'] : '';
$request->data = (string) $_POST['data'];
$request->data = (string) $_POST["data"];
$datahandler = new DataHandler($request);
echo json_encode($datahandler->_set());

41
classes/class.data.php Normal file
View file

@ -0,0 +1,41 @@
<?php
class Data {
protected $container;
public function __construct() {
$this->container = new stdClass();
$this->container->head = new stdClass();
$this->container->data = '';
$this->container->user = array();
}
public function __get($name) {
if (!isset($name)) return false;
return $this->container->$name;
}
public function __set($name, $value) {
switch ($name) {
case 'head':
if (is_object($value)) $this->container->head = $value;
break;
case 'data':
if ($this->is_encrypted($value)) $this->container->data = $value;
break;
case 'user':
if (is_array($value)) $this->container->user = $value;
break;
}
}
/*
* should check if data is encrypted
*/
protected function is_encrypted($data) {
return true;
}
}
?>

View file

@ -165,8 +165,6 @@ class DataHandler {
}
}
$data = json_decode($data);
if (!$this->writeDatum('head', json_encode($data->head))) return false;
if (!$this->writeDatum('data', $data->data)) return false;

View file

@ -1,9 +1,34 @@
<?php
require_once "class.data.php";
class Request {
public $id;
public $version;
public $data;
protected $container;
public function __construct() {
$this->container = new stdClass();
$this->container->id = '';
$this->container->version = '';
$this->container->data = new Data();
}
public function __get($name) {
return $this->container->$name;
}
public function __set($name, $value) {
switch ($name) {
case 'data':
$data = json_decode($value);
foreach ($data as $p => $v) {
$this->container->data->$p = $v;
}
break;
default:
$this->container->$name = (string) $value;
}
}
}
?>