QiniuFilesystem.php 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. <?php
  2. /**
  3. * Created by PhpStorm.
  4. * User: NODELOG
  5. * Date: 2016/12/11
  6. * Time: 下午11:48
  7. */
  8. namespace common\modules\attachment\components\flysystem;
  9. use creocoder\flysystem\Filesystem;
  10. use yii\base\InvalidConfigException;
  11. class QiniuFilesystem extends Filesystem
  12. {
  13. /**
  14. * @var string
  15. */
  16. public $access;
  17. /**
  18. * @var string
  19. */
  20. public $secret;
  21. /**
  22. * @var string
  23. */
  24. public $bucket;
  25. public $domain;
  26. /**
  27. * @var array
  28. */
  29. public $options = [];
  30. /**
  31. * @inheritdoc
  32. */
  33. public function init()
  34. {
  35. if ($this->access === null) {
  36. throw new InvalidConfigException('The "access" property must be set.');
  37. }
  38. if ($this->secret === null) {
  39. throw new InvalidConfigException('The "secret" property must be set.');
  40. }
  41. if ($this->bucket === null) {
  42. throw new InvalidConfigException('The "bucket" property must be set.');
  43. }
  44. parent::init();
  45. }
  46. /**
  47. * @return QiniuAdapter
  48. */
  49. protected function prepareAdapter()
  50. {
  51. return new QiniuAdapter(
  52. $this->access,
  53. $this->secret,
  54. $this->bucket,
  55. $this->domain
  56. );
  57. }
  58. }