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 <[email protected]> |
||
10 | // +---------------------------------------------------------------------- |
||
11 | declare (strict_types = 1); |
||
12 | |||
13 | namespace think; |
||
14 | |||
15 | use InvalidArgumentException; |
||
16 | use think\filesystem\Driver; |
||
17 | use think\filesystem\driver\Local; |
||
18 | use think\helper\Arr; |
||
19 | |||
20 | /** |
||
21 | * Class Filesystem |
||
22 | * @package think |
||
23 | * @mixin Driver |
||
24 | * @mixin Local |
||
25 | */ |
||
26 | class Filesystem extends Manager |
||
27 | { |
||
28 | protected $namespace = '\\think\\filesystem\\driver\\'; |
||
29 | |||
30 | /** |
||
31 | * @param null|string $name |
||
32 | * @return Driver |
||
33 | */ |
||
34 | 6 | public function disk(string $name = null): Driver |
|
35 | { |
||
36 | 6 | return $this->driver($name); |
|
37 | } |
||
38 | |||
39 | 9 | protected function resolveType(string $name) |
|
40 | { |
||
41 | 9 | return $this->getDiskConfig($name, 'type', 'local'); |
|
42 | } |
||
43 | |||
44 | 9 | protected function resolveConfig(string $name) |
|
45 | { |
||
46 | 9 | return $this->getDiskConfig($name); |
|
47 | } |
||
48 | |||
49 | /** |
||
50 | * 获取缓存配置 |
||
51 | * @access public |
||
52 | * @param null|string $name 名称 |
||
53 | * @param mixed $default 默认值 |
||
54 | * @return mixed |
||
55 | */ |
||
56 | 9 | public function getConfig(string $name = null, $default = null) |
|
57 | { |
||
58 | 9 | if (!is_null($name)) { |
|
59 | 9 | return $this->app->config->get('filesystem.' . $name, $default); |
|
60 | } |
||
61 | |||
62 | return $this->app->config->get('filesystem'); |
||
63 | } |
||
64 | |||
65 | /** |
||
66 | * 获取磁盘配置 |
||
67 | * @param string $disk |
||
68 | * @param null $name |
||
0 ignored issues
–
show
Documentation
Bug
introduced
by
![]() |
|||
69 | * @param null $default |
||
0 ignored issues
–
show
|
|||
70 | * @return array |
||
71 | */ |
||
72 | 9 | public function getDiskConfig($disk, $name = null, $default = null) |
|
73 | { |
||
74 | 9 | if ($config = $this->getConfig("disks.{$disk}")) { |
|
75 | 9 | return Arr::get($config, $name, $default); |
|
76 | } |
||
77 | |||
78 | throw new InvalidArgumentException("Disk [$disk] not found."); |
||
79 | } |
||
80 | |||
81 | /** |
||
82 | * 默认驱动 |
||
83 | * @return string|null |
||
84 | */ |
||
85 | 9 | public function getDefaultDriver() |
|
86 | { |
||
87 | 9 | return $this->getConfig('default'); |
|
88 | } |
||
89 | } |
||
90 |