Serve.php 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. <?php
  2. // +----------------------------------------------------------------------
  3. // | CRMEB [ CRMEB赋能开发者,助力企业发展 ]
  4. // +----------------------------------------------------------------------
  5. // | Copyright (c) 2016~2020 https://www.crmeb.com All rights reserved.
  6. // +----------------------------------------------------------------------
  7. // | Licensed CRMEB并不是自由软件,未经许可不能去掉CRMEB相关版权
  8. // +----------------------------------------------------------------------
  9. // | Author: CRMEB Team <admin@crmeb.com>
  10. // +----------------------------------------------------------------------
  11. namespace crmeb\services\serve;
  12. use crmeb\basic\BaseManager;
  13. use crmeb\services\AccessTokenServeService;
  14. use crmeb\services\serve\storage\Crmeb;
  15. use think\facade\Config;
  16. use think\Container;
  17. /**
  18. * Class Serve
  19. * @package crmeb\services\serve
  20. * @mixin Crmeb
  21. */
  22. class Serve extends BaseManager
  23. {
  24. /**
  25. * 空间名
  26. * @var string
  27. */
  28. protected $namespace = '\\crmeb\\services\\serve\\storage\\';
  29. /**
  30. * 默认驱动
  31. * @return mixed
  32. */
  33. protected function getDefaultDriver()
  34. {
  35. return Config::get('serve.default', 'crmeb');
  36. }
  37. /**
  38. * 获取类的实例
  39. * @param $class
  40. * @return mixed|void
  41. */
  42. protected function invokeClass($class)
  43. {
  44. if (!class_exists($class)) {
  45. throw new \RuntimeException('class not exists: ' . $class);
  46. }
  47. $this->getConfigFile();
  48. if (!$this->config) {
  49. $this->config = Config::get($this->configFile . '.stores.' . $this->name, []);
  50. }
  51. $handleAccessToken = new AccessTokenServeService($this->config['account'] ?? '', $this->config['secret'] ?? '');
  52. $handle = Container::getInstance()->invokeClass($class, [$this->name, $handleAccessToken, $this->configFile]);
  53. $this->config = [];
  54. return $handle;
  55. }
  56. }