BaseStorage.php 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  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 qiniu\basic;
  12. /**
  13. * 容器基类
  14. * Class BaseStorage
  15. * @package crmeb\basic
  16. */
  17. abstract class BaseStorage
  18. {
  19. /**
  20. * 错误信息
  21. * @var string
  22. */
  23. protected $error;
  24. /**
  25. * 设置错误信息
  26. * @param string|null $error
  27. * @return bool
  28. */
  29. protected function setError(?string $error = null)
  30. {
  31. $this->error = $error ?: '未知错误';
  32. return false;
  33. }
  34. /**
  35. * 获取错误信息
  36. * @return string
  37. */
  38. public function getError()
  39. {
  40. $error = $this->error;
  41. $this->error = null;
  42. return $error;
  43. }
  44. /**
  45. * 驱动名称
  46. * @var string
  47. */
  48. protected $name;
  49. /**
  50. * 驱动配置文件名
  51. * @var string
  52. */
  53. protected $configFile;
  54. /**
  55. * BaseStorage constructor.
  56. * @param string $name 驱动名
  57. * @param string $configFile 驱动配置名
  58. * @param array $config 其他配置
  59. */
  60. public function __construct(string $name, array $config = [], string $configFile = null)
  61. {
  62. $this->name = $name;
  63. $this->configFile = $configFile;
  64. $this->initialize($config);
  65. }
  66. /**
  67. * 初始化
  68. * @param array $config
  69. * @return mixed
  70. */
  71. abstract protected function initialize(array $config);
  72. }