Store.php 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. <?php
  2. /**
  3. * FecShop file.
  4. * @link http://www.fecshop.com/
  5. * @copyright Copyright (c) 2016 FecShop Software LLC
  6. * @license http://www.fecshop.com/license/
  7. */
  8. namespace common\local\local_components;
  9. use Yii;
  10. use yii\base\BootstrapInterface;
  11. use yii\base\Component;
  12. /**
  13. * @author Terry Zhao <2358269014@qq.com>
  14. * @since 1.0
  15. */
  16. class Store extends Component implements BootstrapInterface
  17. {
  18. public $appName;
  19. public $_base_config;
  20. protected $_modelName = '\fecshop\models\mysqldb\StoreBaseConfig';
  21. protected $_model;
  22. //
  23. public $serviceMongodbName = 'mongodb';
  24. public $serviceMysqldbName = 'mysqldb';
  25. //
  26. public $enable = 1;
  27. public $disable = 2;
  28. // 初始化的bootstrap
  29. public function bootstrap($app)
  30. {
  31. $this->initBaseConfig();
  32. if ($this->appName == 'appadmin') {
  33. Yii::$service->admin->bootstrap($app);
  34. } else {
  35. Yii::$service->store->bootstrap($app);
  36. }
  37. }
  38. // 得到配置值
  39. /**
  40. * @param $key | string, 配置的主Key
  41. * @param $subKey | string, 配置的子key
  42. */
  43. public function get($key, $subKey = '')
  44. {
  45. $this->initBaseConfig();
  46. if (!$subKey) {
  47. return isset($this->_base_config[$key]) ? $this->_base_config[$key] : null;
  48. }
  49. return isset($this->_base_config[$key][$subKey]) ? $this->_base_config[$key][$subKey] : null;
  50. }
  51. public function initBaseConfig()
  52. {
  53. if (!$this->_base_config) {
  54. $this->_base_config = Yii::$service->storeBaseConfig->getAllConfig();
  55. }
  56. }
  57. }