added class data to store $request->data
This commit is contained in:
parent
c8efaf5617
commit
6c68869454
4 changed files with 73 additions and 8 deletions
3
api.php
3
api.php
|
@ -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
41
classes/class.data.php
Normal 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;
|
||||
}
|
||||
}
|
||||
?>
|
|
@ -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;
|
||||
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
}
|
||||
}
|
||||
?>
|
||||
|
|
Loading…
Reference in a new issue