Filesystem.php 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. <?php
  2. // +----------------------------------------------------------------------
  3. // | ThinkPHP [ WE CAN DO IT JUST THINK ]
  4. // +----------------------------------------------------------------------
  5. // | Copyright (c) 2006~2021 http://thinkphp.cn All rights reserved.
  6. // +----------------------------------------------------------------------
  7. // | Licensed ( http://www.apache.org/licenses/LICENSE-2.0 )
  8. // +----------------------------------------------------------------------
  9. // | Author: yunwuxin <448901948@qq.com>
  10. // +----------------------------------------------------------------------
  11. declare (strict_types = 1);
  12. namespace think;
  13. use InvalidArgumentException;
  14. use think\filesystem\Driver;
  15. use think\filesystem\driver\Local;
  16. use think\helper\Arr;
  17. /**
  18. * Class Filesystem
  19. * @package think
  20. * @mixin Driver
  21. * @mixin Local
  22. */
  23. class Filesystem extends Manager
  24. {
  25. protected $namespace = '\\think\\filesystem\\driver\\';
  26. /**
  27. * @param null|string $name
  28. * @return Driver
  29. */
  30. public function disk(string $name = null): Driver
  31. {
  32. return $this->driver($name);
  33. }
  34. protected function resolveType(string $name)
  35. {
  36. return $this->getDiskConfig($name, 'type', 'local');
  37. }
  38. protected function resolveConfig(string $name)
  39. {
  40. return $this->getDiskConfig($name);
  41. }
  42. /**
  43. * 获取缓存配置
  44. * @access public
  45. * @param null|string $name 名称
  46. * @param mixed $default 默认值
  47. * @return mixed
  48. */
  49. public function getConfig(string $name = null, $default = null)
  50. {
  51. if (!is_null($name)) {
  52. return $this->app->config->get('filesystem.' . $name, $default);
  53. }
  54. return $this->app->config->get('filesystem');
  55. }
  56. /**
  57. * 获取磁盘配置
  58. * @param string $disk
  59. * @param null $name
  60. * @param null $default
  61. * @return array
  62. */
  63. public function getDiskConfig($disk, $name = null, $default = null)
  64. {
  65. if ($config = $this->getConfig("disks.{$disk}")) {
  66. return Arr::get($config, $name, $default);
  67. }
  68. throw new InvalidArgumentException("Disk [$disk] not found.");
  69. }
  70. /**
  71. * 默认驱动
  72. * @return string|null
  73. */
  74. public function getDefaultDriver()
  75. {
  76. return $this->getConfig('default');
  77. }
  78. }