新版订单消耗系统

Config.php 1.6KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. <?php
  2. class LtConfig
  3. {
  4. public $storeHandle;
  5. protected $conf;
  6. public function __construct()
  7. {
  8. if (!is_object($this->storeHandle))
  9. {
  10. $this->storeHandle = new LtStoreMemory;
  11. }
  12. }
  13. public function init()
  14. {
  15. //don't removeme, I am the placeholder
  16. }
  17. public function get($key)
  18. {
  19. $storedConfig = $this->storeHandle->get($key);
  20. if ($storedConfig instanceof LtConfigExpression)
  21. {
  22. $str = $storedConfig->__toString();
  23. if ($storedConfig->autoRetrived)
  24. {
  25. eval("\$value=$str;");
  26. return $value;
  27. }
  28. else
  29. {
  30. return $str;
  31. }
  32. }
  33. else
  34. {
  35. return $storedConfig;
  36. }
  37. }
  38. /**
  39. * 警告
  40. * 这里会包含两个用户定义的配置文件,为了不和配置文件里的变量名发生重名
  41. * 本方法不定义和使用变量名
  42. */
  43. public function loadConfigFile($configFile)
  44. {
  45. if (0 == $this->storeHandle->get(".config_total"))
  46. {
  47. if (null === $configFile || !is_file($configFile))
  48. {
  49. trigger_error("no config file specified or invalid config file");
  50. }
  51. $this->conf = include($configFile);
  52. if (!is_array($this->conf))
  53. {
  54. trigger_error("config file do NOT return array: $configFile");
  55. }
  56. elseif (!empty($this->conf))
  57. {
  58. if (0 == $this->storeHandle->get(".config_total"))
  59. {
  60. $this->storeHandle->add(".config_total", 0);
  61. }
  62. $this->addConfig($this->conf);
  63. }
  64. }
  65. }
  66. public function addConfig($configArray)
  67. {
  68. foreach($configArray as $key => $value)
  69. {
  70. if (!$this->storeHandle->update($key, $value))
  71. {
  72. if ($this->storeHandle->add($key, $value))
  73. {
  74. $this->storeHandle->update(".config_total", $this->storeHandle->get(".config_total") + 1, 0);
  75. }
  76. }
  77. }
  78. }
  79. }