StorageComponent.php 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. <?php
  2. /**
  3. * 重庆赤晓店信息科技有限公司
  4. * https://www.chixiaodian.com
  5. * Copyright (c) 2023 赤店商城 All rights reserved.
  6. */
  7. namespace app\librarys\storage\components;
  8. use app\librarys\storage\UploadFile;
  9. use app\librarys\storage\drivers\Local;
  10. use app\librarys\storage\drivers\BaseDriver;
  11. class StorageComponent extends \yii\base\Component
  12. {
  13. private $driver = null;
  14. protected $basePath;
  15. public function getDriver()
  16. {
  17. if ($this->driver === null) {
  18. $this->setDriver([
  19. 'class' => Local::class,
  20. ]);
  21. }
  22. return $this->driver;
  23. }
  24. public function setDriver($value)
  25. {
  26. if (is_array($value)) {
  27. $this->driver = \Yii::createObject($value);
  28. } else {
  29. $this->driver = $value;
  30. }
  31. }
  32. public function getBasePath()
  33. {
  34. return $this->basePath;
  35. }
  36. public function setBasePath($value)
  37. {
  38. $this->basePath = $value;
  39. }
  40. public function getUploadedFile($name)
  41. {
  42. if (substr($name, -1) === 's' || $name === 'xlsx'|| $name === 'crt' || $name === 'apk' || $name === 'pfx' || $name === 'cer' || $name === 'pem') {
  43. return UploadFile::getInstancesByStorage($name, $this->getDriver(), $this->basePath);
  44. }
  45. return UploadFile::getInstanceByStorage($name, $this->getDriver(), $this->basePath);
  46. }
  47. }