AliyuncsFilesystem.php 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  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 AliyuncsFilesystem 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 $endpoint;
  25. /**
  26. * @var bool
  27. */
  28. public $isCName = false;
  29. /**
  30. * @var string
  31. */
  32. public $bucket;
  33. /**
  34. * @var array
  35. */
  36. public $options = [];
  37. /**
  38. * @inheritdoc
  39. */
  40. public function init()
  41. {
  42. if ($this->access === null) {
  43. throw new InvalidConfigException('The "access" property must be set.');
  44. }
  45. if ($this->secret === null) {
  46. throw new InvalidConfigException('The "secret" property must be set.');
  47. }
  48. if ($this->endpoint === null) {
  49. throw new InvalidConfigException('The "endpoint" property must be set.');
  50. }
  51. if ($this->bucket === null) {
  52. throw new InvalidConfigException('The "bucket" property must be set.');
  53. }
  54. parent::init();
  55. }
  56. /**
  57. * @return AliyuncsAdapter
  58. */
  59. protected function prepareAdapter()
  60. {
  61. return new AliyuncsAdapter(
  62. $this->access,
  63. $this->secret,
  64. $this->endpoint,
  65. $this->isCName,
  66. $this->bucket
  67. );
  68. }
  69. }