Skip to content

Commit c77b833

Browse files
committed
refactor: Remove PutRemoteFile plugin, update develop packages
1 parent 12080e6 commit c77b833

File tree

10 files changed

+54
-126
lines changed

10 files changed

+54
-126
lines changed

.php_cs renamed to .php-cs-fixer.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<?php
2-
return PhpCsFixer\Config::create()
2+
return (new PhpCsFixer\Config())
33
->setRules([
44
'@PSR2' => true,
55
'binary_operator_spaces' => true,
@@ -34,7 +34,7 @@
3434
'unary_operator_spaces' => true,
3535
'visibility_required' => [
3636
'elements' => [
37-
'const',
37+
// 'const',
3838
'method',
3939
'property',
4040
],
@@ -45,4 +45,4 @@
4545
->exclude('vendor')
4646
->in([__DIR__.'/src/',__DIR__.'/tests/'])
4747
)
48-
;
48+
;

README-CN.md

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -67,8 +67,6 @@ $fp = fopen('/local/path/file.txt','r');
6767
Storage::disk('aliyun')->put('dir/path/file.txt', $fp);
6868
fclose($fp);
6969

70-
Storage::disk('aliyun')->putRemoteFile('dir/path/file.txt', 'http://example.com/file.txt');
71-
7270
Storage::disk('aliyun')->prepend('dir/path/file.txt', 'Prepend Text');
7371
Storage::disk('aliyun')->append('dir/path/file.txt', 'Append Text');
7472

@@ -114,6 +112,13 @@ Storage::disk('aliyun')->directories('dir/path');
114112
Storage::disk('aliyun')->allDirectories('dir/path');
115113
```
116114

115+
#### 使用 Plugin
116+
```php
117+
Storage::disk('aliyun')->appendContent('dir/path/news.txt', 'The first line paragraph.', 0);
118+
Storage::disk('aliyun')->appendContent('dir/path/news.txt', 'The second line paragraph.', 25);
119+
Storage::disk('aliyun')->appendContent('dir/path/news.txt', 'The last line paragraph.', 51);
120+
```
121+
117122
#### 使用 OssClient
118123
```php
119124
$adapter = Storage::disk('aliyun')->getAdapter();

README.md

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -67,8 +67,6 @@ $fp = fopen('/local/path/file.txt','r');
6767
Storage::disk('aliyun')->put('dir/path/file.txt', $fp);
6868
fclose($fp);
6969
70-
Storage::disk('aliyun')->putRemoteFile('dir/path/file.txt', 'http://example.com/file.txt');
71-
7270
Storage::disk('aliyun')->prepend('dir/path/file.txt', 'Prepend Text');
7371
Storage::disk('aliyun')->append('dir/path/file.txt', 'Append Text');
7472
@@ -114,6 +112,13 @@ Storage::disk('aliyun')->directories('dir/path');
114112
Storage::disk('aliyun')->allDirectories('dir/path');
115113
```
116114
115+
#### Use Plugin
116+
```php
117+
Storage::disk('aliyun')->appendContent('dir/path/news.txt', 'The first line paragraph.', 0);
118+
Storage::disk('aliyun')->appendContent('dir/path/news.txt', 'The second line paragraph.', 25);
119+
Storage::disk('aliyun')->appendContent('dir/path/news.txt', 'The last line paragraph.', 51);
120+
```
121+
117122
#### Use OssClient
118123
```php
119124
$adapter = Storage::disk('aliyun')->getAdapter();

composer.json

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,11 @@
1515
"alphasnow/aliyun-oss-flysystem": "^1.3"
1616
},
1717
"require-dev": {
18-
"mockery/mockery": "~1.0",
19-
"phpunit/phpunit": "~6.0",
20-
"friendsofphp/php-cs-fixer": "^2.16",
21-
"phpstan/phpstan": "^0.12.82",
22-
"orchestra/testbench": "^3.5.6"
18+
"mockery/mockery": "^1.3",
19+
"phpunit/phpunit": "^8.5",
20+
"friendsofphp/php-cs-fixer": "^3.2",
21+
"phpstan/phpstan": "^0.12.99",
22+
"orchestra/testbench": "^5.20"
2323
},
2424
"autoload": {
2525
"psr-4": {
@@ -35,16 +35,13 @@
3535
"laravel": {
3636
"providers": [
3737
"AlphaSnow\\AliyunOss\\ServiceProvider"
38-
],
39-
"aliases": {
40-
"AliyunOssClient": "AlphaSnow\\AliyunOss\\AliyunOssClient"
41-
}
38+
]
4239
}
4340
},
4441
"scripts": {
4542
"phpstan": "vendor/bin/phpstan analyse",
46-
"check-style": "vendor/bin/php-cs-fixer fix --using-cache=no --diff --config=.php_cs --dry-run --ansi",
47-
"fix-style": "vendor/bin/php-cs-fixer fix --using-cache=no --config=.php_cs --ansi",
43+
"check-style": "vendor/bin/php-cs-fixer fix --using-cache=no --diff --config=.php-cs-fixer.php --dry-run --ansi",
44+
"fix-style": "vendor/bin/php-cs-fixer fix --using-cache=no --config=.php-cs-fixer.php --ansi",
4845
"test": "vendor/bin/phpunit --colors=always --testdox"
4946
},
5047
"scripts-descriptions": {

src/Adapter.php

Lines changed: 2 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,10 @@
33
namespace AlphaSnow\AliyunOss;
44

55
use AlphaSnow\Flysystem\AliyunOss\AliyunOssAdapter as BaseAdapter;
6-
use League\Flysystem\Adapter\CanOverwriteFiles;
7-
use League\Flysystem\AdapterInterface;
86
use League\Flysystem\Config as FlysystemConfig;
97
use OSS\OssClient;
108

11-
class Adapter extends BaseAdapter implements CanOverwriteFiles
9+
class Adapter extends BaseAdapter
1210
{
1311
/**
1412
* @var Config
@@ -25,21 +23,6 @@ public function __construct(OssClient $ossClient, Config $ossConfig)
2523
parent::__construct($ossClient, $ossConfig->get('bucket'), ltrim($ossConfig->get('prefix', null), '/'), $ossConfig->get('options', []));
2624
}
2725

28-
/**
29-
* {@inheritdoc}
30-
*/
31-
public function getOptionsFromConfig(FlysystemConfig $config)
32-
{
33-
$options = parent::getOptionsFromConfig($config);
34-
35-
if ($visibility = $config->get('visibility')) {
36-
// Object ACL > Bucket ACL
37-
$options[OssClient::OSS_HEADERS][OssClient::OSS_OBJECT_ACL] = $visibility === AdapterInterface::VISIBILITY_PUBLIC ? OssClient::OSS_ACL_TYPE_PUBLIC_READ : OssClient::OSS_ACL_TYPE_PRIVATE;
38-
}
39-
40-
return $options;
41-
}
42-
4326
/**
4427
* Used by \Illuminate\Filesystem\FilesystemAdapter::url
4528
* Get the URL for the file at the given path.
@@ -68,13 +51,13 @@ public function getTemporaryUrl($path, $expiration = null, array $options = [])
6851
{
6952
$object = $this->applyPathPrefix($path);
7053
$clientOptions = $this->getOptionsFromConfig(new FlysystemConfig($options));
54+
7155
if (is_null($expiration)) {
7256
$expiration = new \DateTime($this->ossConfig->get('signature_expires'));
7357
}
7458
$timeout = $expiration->getTimestamp() - (new \DateTime('now'))->getTimestamp();
7559

7660
$url = $this->client->signUrl($this->bucket, $object, $timeout, OssClient::OSS_HTTP_GET, $clientOptions);
77-
7861
return $this->ossConfig->correctUrl($url);
7962
}
8063
}

src/Plugins/PutRemoteFile.php

Lines changed: 0 additions & 42 deletions
This file was deleted.

src/ServiceProvider.php

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
namespace AlphaSnow\AliyunOss;
44

55
use AlphaSnow\Flysystem\AliyunOss\Plugins\AppendContent;
6-
use AlphaSnow\AliyunOss\Plugins\PutRemoteFile;
76
use Illuminate\Support\ServiceProvider as BaseServiceProvider;
87
use League\Flysystem\Config as FlysystemConfig;
98
use League\Flysystem\Filesystem;
@@ -49,7 +48,6 @@ public function register()
4948
$adapter = $app->make('aliyun-oss.oss-adapter', $config);
5049

5150
$filesystem = new Filesystem($adapter, new FlysystemConfig(['disable_asserts' => true]));
52-
$filesystem->addPlugin(new PutRemoteFile());
5351
$filesystem->addPlugin(new AppendContent());
5452
return $filesystem;
5553
});

tests/ConfigTest.php

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,4 +43,30 @@ public function testGetOssEndpoint()
4343
$endpoint = $ossConfig->getOssEndpoint();
4444
$this->assertSame($config['internal'], $endpoint);
4545
}
46+
47+
public function testCorrectUrl()
48+
{
49+
$config = [
50+
'use_ssl' => false,
51+
'bucket' => 'bucket',
52+
'endpoint' => 'oss-cn-shanghai.aliyuncs.com',
53+
'internal' => 'oss-cn-shanghai-internal.aliyuncs.com',
54+
];
55+
$ossConfig = new Config($config);
56+
$internalUrl = 'http://bucket.oss-cn-shanghai-internal.aliyuncs.com/dir/path/file.txt';
57+
$correctUrl = $ossConfig->correctUrl($internalUrl);
58+
$this->assertSame('http://bucket.oss-cn-shanghai.aliyuncs.com/dir/path/file.txt', $correctUrl);
59+
60+
$config = [
61+
'use_ssl' => false,
62+
'bucket' => 'bucket',
63+
'endpoint' => 'oss-cn-shanghai.aliyuncs.com',
64+
'domain' => 'oss.my-domain.com',
65+
'use_domain_endpoint' => false,
66+
];
67+
$ossConfig = new Config($config);
68+
$endpointUrl = 'http://bucket.oss-cn-shanghai.aliyuncs.com/dir/path/file.txt';
69+
$correctUrl = $ossConfig->correctUrl($endpointUrl);
70+
$this->assertSame('http://oss.my-domain.com/dir/path/file.txt', $correctUrl);
71+
}
4672
}

tests/FilesystemPluginTest.php

Lines changed: 0 additions & 44 deletions
This file was deleted.

tests/FilesystemTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@
44

55
use AlphaSnow\AliyunOss\Config;
66
use Illuminate\Filesystem\FilesystemAdapter;
7-
use OSS\OssClient;
87
use Mockery\MockInterface;
8+
use OSS\OssClient;
99

1010
class FilesystemTest extends TestCase
1111
{

0 commit comments

Comments
 (0)