1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace AlphaSnow\AliyunOss; |
4
|
|
|
|
5
|
|
|
use Illuminate\Support\ServiceProvider as BaseServiceProvider; |
6
|
|
|
use Aliyun\Flysystem\AliyunOss\Plugins\PutFile; |
7
|
|
|
use League\Flysystem\Config; |
8
|
|
|
use League\Flysystem\Filesystem; |
9
|
|
|
use OSS\OssClient; |
10
|
|
|
|
11
|
|
|
/** |
12
|
|
|
* Class ServiceProvider |
13
|
|
|
* @package AlphaSnow\AliyunOss |
14
|
|
|
*/ |
15
|
|
|
class ServiceProvider extends BaseServiceProvider |
16
|
|
|
{ |
17
|
|
|
public function boot() |
18
|
|
|
{ |
19
|
|
|
$this->mergeConfigFrom( |
20
|
|
|
__DIR__.'/config/config.php', |
21
|
|
|
'filesystems.disks.aliyun' |
22
|
|
|
); |
23
|
|
|
|
24
|
|
|
$this->app->make('filesystem') |
25
|
|
|
->extend('aliyun', function ($app, array $config) { |
26
|
|
|
$client = $app->make('aliyun-oss.oss-client', $config); |
27
|
|
|
$adapter = new AliyunOssAdapter($client, $config); |
28
|
|
|
$filesystem = new Filesystem($adapter, new Config(['disable_asserts' => true])); |
29
|
|
|
$filesystem->addPlugin(new PutFile()); |
30
|
|
|
return $filesystem; |
31
|
|
|
}); |
32
|
|
|
} |
33
|
|
|
|
34
|
|
|
public function register() |
35
|
|
|
{ |
36
|
|
|
$this->app->bind('aliyun-oss.oss-client', function ($app, array $config) { |
37
|
|
|
return $app->make(OssClient::class, [ |
38
|
|
|
'accessKeyId' => $config['accessId'], |
39
|
|
|
'accessKeySecret' => $config['accessKey'], |
40
|
|
|
'endpoint' => $config['endpoint'], |
41
|
|
|
'isCName' => $config['isCname'], |
42
|
|
|
'securityToken' => $config['securityToken'] |
43
|
|
|
]); |
44
|
|
|
}); |
45
|
|
|
|
46
|
|
|
$this->app->singleton('aliyun-oss.client', function ($app) { |
47
|
|
|
$config = $app->get('config')->get('filesystems.disks.aliyun'); |
48
|
|
|
return $app->make('aliyun-oss.oss-client', $config); |
49
|
|
|
}); |
50
|
|
|
} |
51
|
|
|
} |
52
|
|
|
|