PageRenderTime 52ms CodeModel.GetById 26ms RepoModel.GetById 0ms app.codeStats 0ms

/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
Possible License(s): LGPL-2.1, LGPL-3.0, BSD-3-Clause
  1. <?php
  2. require_once 'Flux/Config.php';
  3. require_once 'Flux/Error.php';
  4. /**
  5. * Objectifies a given object.
  6. */
  7. class Flux_DataObject {
  8. /**
  9. * Storage object.
  10. *
  11. * @access protected
  12. * @var array
  13. */
  14. protected $_data = array();
  15. /**
  16. *
  17. */
  18. protected $_dbConfig;
  19. /**
  20. *
  21. */
  22. protected $_encFrom;
  23. /**
  24. *
  25. */
  26. protected $_encTo;
  27. /**
  28. * Create new DataObject.
  29. *
  30. * @param StdClass $object
  31. * @param array $default Default values
  32. * @access public
  33. */
  34. public function __construct(array $data = null, $defaults = array())
  35. {
  36. if (array_key_exists('dbconfig', $defaults) && $defaults['dbconfig'] instanceOf Flux_Config) {
  37. $this->_dbConfig = $defaults['dbconfig'];
  38. unset($defaults['dbconfig']);
  39. }
  40. else {
  41. $tmpArr = array();
  42. $this->_dbConfig = new Flux_Config($tmpArr);
  43. }
  44. $this->_encFrom = $this->_dbConfig->getEncoding();
  45. $this->_encTo = $this->_encFrom ? $this->_dbConfig->get('Convert') : false;
  46. if (!is_null($data)) {
  47. $this->_data = $data;
  48. }
  49. foreach ($defaults as $prop => $value) {
  50. if (!isset($this->_data[$prop])) {
  51. $this->_data[$prop] = $value;
  52. }
  53. }
  54. if ($this->_encTo) {
  55. foreach ($this->_data as $prop => $value) {
  56. $this->_data[$prop] = iconv($this->_encFrom, $this->_encTo, $value);
  57. }
  58. }
  59. }
  60. public function __set($prop, $value)
  61. {
  62. $this->_data[$prop] = $value;
  63. return $value;
  64. }
  65. public function __get($prop)
  66. {
  67. if (isset($this->_data[$prop])) {
  68. return $this->_data[$prop];
  69. }
  70. else {
  71. return null;
  72. }
  73. }
  74. }
  75. ?>