-
Notifications
You must be signed in to change notification settings - Fork 204
/
DataObject.php
86 lines (75 loc) · 1.49 KB
/
DataObject.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
<?php
require_once 'Flux/Config.php';
require_once 'Flux/Error.php';
/**
* Objectifies a given object.
*/
class Flux_DataObject {
/**
* Storage object.
*
* @access protected
* @var array
*/
protected $_data = array();
/**
*
*/
protected $_dbConfig;
/**
*
*/
protected $_encFrom;
/**
*
*/
protected $_encTo;
/**
* Create new DataObject.
*
* @param StdClass $object
* @param array $default Default values
* @access public
*/
public function __construct(array $data = null, $defaults = array())
{
if (array_key_exists('dbconfig', $defaults) && $defaults['dbconfig'] instanceOf Flux_Config) {
$this->_dbConfig = $defaults['dbconfig'];
unset($defaults['dbconfig']);
}
else {
$tmpArr = array();
$this->_dbConfig = new Flux_Config($tmpArr);
}
$this->_encFrom = $this->_dbConfig->getEncoding();
$this->_encTo = $this->_encFrom ? $this->_dbConfig->get('Convert') : false;
if (!is_null($data)) {
$this->_data = $data;
}
foreach ($defaults as $prop => $value) {
if (!isset($this->_data[$prop])) {
$this->_data[$prop] = $value;
}
}
if ($this->_encTo) {
foreach ($this->_data as $prop => $value) {
$this->_data[$prop] = iconv($this->_encFrom, $this->_encTo, $value);
}
}
}
public function __set($prop, $value)
{
$this->_data[$prop] = $value;
return $value;
}
public function __get($prop)
{
if (isset($this->_data[$prop])) {
return $this->_data[$prop];
}
else {
return null;
}
}
}
?>