Printer.php 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. <?php
  2. /**
  3. * Created by PhpStorm.
  4. * User: dengfenglai <136327134@qq.com>
  5. * Date: 2019/11/23 3:47 PM
  6. */
  7. namespace crmeb\services\printer;
  8. use crmeb\basic\BaseManager;
  9. use think\facade\Config;
  10. use think\Container;
  11. /**
  12. * Class Printer
  13. * @package crmeb\services\auth
  14. * @mixin \crmeb\services\printer\storage\YiLianYun
  15. */
  16. class Printer extends BaseManager
  17. {
  18. /**
  19. * 空间名
  20. * @var string
  21. */
  22. protected $namespace = '\\crmeb\\services\\printer\\storage\\';
  23. /**
  24. * @var object
  25. */
  26. protected $handleAccessToken;
  27. /**
  28. * 默认驱动
  29. * @return mixed
  30. */
  31. protected function getDefaultDriver()
  32. {
  33. return Config::get('printer.default', 'yi_lian_yun');
  34. }
  35. /**
  36. * 获取类的实例
  37. * @param $class
  38. * @return mixed|void
  39. */
  40. protected function invokeClass($class)
  41. {
  42. if (!class_exists($class)) {
  43. throw new \RuntimeException('class not exists: ' . $class);
  44. }
  45. $this->getConfigFile();
  46. if (!$this->config) {
  47. $this->config = Config::get($this->configFile . '.stores.' . $this->name, []);
  48. }
  49. if (!$this->handleAccessToken) {
  50. $this->handleAccessToken = new AccessToken($this->config, $this->name, $this->configFile);
  51. }
  52. $handle = Container::getInstance()->invokeClass($class, [$this->name, $this->handleAccessToken, $this->configFile]);
  53. $this->config = [];
  54. return $handle;
  55. }
  56. }