新版订单消耗系统

Lotus.php 3.7KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158
  1. <?php
  2. class Lotus
  3. {
  4. /**
  5. * Lotus Option array
  6. *
  7. * @var array array(
  8. * "proj_dir" =>
  9. * "app_name" =>
  10. * "autoload_dir" =>
  11. * );
  12. */
  13. public $option;
  14. public $devMode = true;
  15. public $defaultStoreDir;
  16. protected $proj_dir;
  17. protected $app_dir;
  18. protected $data_dir;
  19. protected $lotusRuntimeDir;
  20. protected $coreCacheHandle;
  21. public function __construct()
  22. {
  23. $this->lotusRuntimeDir = dirname(__FILE__) . DIRECTORY_SEPARATOR;
  24. }
  25. public function init()
  26. {
  27. $underMVC = false;
  28. if (isset($this->option["proj_dir"]) && !empty($this->option["proj_dir"]))
  29. {
  30. $this->proj_dir = rtrim($this->option["proj_dir"], '\\/') . '/';
  31. if (isset($this->option["app_name"]) && !empty($this->option["app_name"]))
  32. {
  33. $this->app_dir = $this->proj_dir . "app/" . $this->option["app_name"] . "/";
  34. $this->data_dir = $this->proj_dir . "data/" . $this->option["app_name"] . "/";
  35. $underMVC = true;
  36. }
  37. else
  38. {
  39. trigger_error("Lotus option [app_name] is missing.");
  40. }
  41. }
  42. /**
  43. * Load core component
  44. */
  45. require_once $this->lotusRuntimeDir . "Store.php";
  46. require_once $this->lotusRuntimeDir . "StoreMemory.php";
  47. require_once $this->lotusRuntimeDir . "StoreFile.php";
  48. if ($this->defaultStoreDir)
  49. {
  50. if ($defaultStoreDir = realpath($this->defaultStoreDir))
  51. {
  52. LtStoreFile::$defaultStoreDir = $defaultStoreDir;
  53. }
  54. else
  55. {
  56. trigger_error("invalid [default store dir]: " . $this->defaultStoreDir);
  57. }
  58. }
  59. if (!$this->devMode)
  60. {
  61. /**
  62. * accelerate LtAutoloader, LtConfig
  63. */
  64. $this->coreCacheHandle = new LtStoreFile;
  65. $prefix = sprintf("%u", crc32(serialize($this->app_dir)));
  66. $this->coreCacheHandle->prefix = 'Lotus-' . $prefix;
  67. $this->coreCacheHandle->useSerialize = true;
  68. $this->coreCacheHandle->init();
  69. }
  70. /**
  71. * Init Autoloader, do this before init all other lotusphp component.
  72. */
  73. $this->prepareAutoloader();
  74. /**
  75. * init Config
  76. */
  77. $this->prepareConfig();
  78. /**
  79. * Run dispatcher when under MVC mode
  80. */
  81. if ($underMVC)
  82. {
  83. $this->runMVC();
  84. }
  85. }
  86. /**
  87. * Autoload all lotus components and user-defined libraries;
  88. */
  89. protected function prepareAutoloader()
  90. {
  91. require_once $this->lotusRuntimeDir . "Autoloader/Autoloader.php";
  92. $autoloader = new LtAutoloader;
  93. $autoloader->autoloadPath[] = $this->lotusRuntimeDir;
  94. if (isset($this->option["autoload_dir"]))
  95. {
  96. $autoloader->autoloadPath[] = $this->option["autoload_dir"];
  97. }
  98. if ($this->proj_dir)
  99. {
  100. is_dir($this->proj_dir . 'lib') && $autoloader->autoloadPath[] = $this->proj_dir . 'lib';
  101. is_dir($this->app_dir . 'action') && $autoloader->autoloadPath[] = $this->app_dir . 'action';
  102. is_dir($this->app_dir . 'lib') && $autoloader->autoloadPath[] = $this->app_dir . 'lib';
  103. }
  104. if (!$this->devMode)
  105. {
  106. $autoloader->storeHandle = $this->coreCacheHandle;
  107. }
  108. $autoloader->init();
  109. }
  110. protected function prepareConfig()
  111. {
  112. $this->configHandle = LtObjectUtil::singleton('LtConfig');
  113. if (!$this->devMode)
  114. {
  115. $configFile = 'conf/conf.php';
  116. $this->configHandle->storeHandle = $this->coreCacheHandle;
  117. }
  118. else
  119. {
  120. $configFile = 'conf/conf_dev.php';
  121. }
  122. $this->configHandle->init();
  123. if ($this->app_dir && is_file($this->app_dir . $configFile))
  124. {
  125. $this->configHandle->loadConfigFile($this->app_dir . $configFile);
  126. }
  127. }
  128. protected function runMVC()
  129. {
  130. $router = LtObjectUtil::singleton('LtRouter');
  131. $router->init();
  132. $dispatcher = LtObjectUtil::singleton('LtDispatcher');
  133. $dispatcher->viewDir = $this->app_dir . 'view/';
  134. $dispatcher->viewTplDir = $this->data_dir . 'templateView/';
  135. if (!$this->devMode)
  136. {
  137. $dispatcher->viewTplAutoCompile = false;
  138. }
  139. else
  140. {
  141. $dispatcher->viewTplAutoCompile = true;
  142. }
  143. $dispatcher->dispatchAction($router->module, $router->action);
  144. }
  145. }