/lib/Flux/DataObject.php
https://github.com/chokoleytdesignoper/fluxcp_choko · PHP · 86 lines · 50 code · 11 blank · 25 comment · 8 complexity · fb89260d94365f75b8e93bfe9bd8b54f MD5 · raw file
- <?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;
- }
- }
- }
- ?>