Skip to content

Commit

Permalink
refactor: Remove PutRemoteFile plugin, update develop packages
Browse files Browse the repository at this point in the history
  • Loading branch information
alphasnow committed Oct 12, 2021
1 parent 12080e6 commit c77b833
Show file tree
Hide file tree
Showing 10 changed files with 54 additions and 126 deletions.
6 changes: 3 additions & 3 deletions .php_cs → .php-cs-fixer.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<?php
return PhpCsFixer\Config::create()
return (new PhpCsFixer\Config())
->setRules([
'@PSR2' => true,
'binary_operator_spaces' => true,
Expand Down Expand Up @@ -34,7 +34,7 @@
'unary_operator_spaces' => true,
'visibility_required' => [
'elements' => [
'const',
// 'const',
'method',
'property',
],
Expand All @@ -45,4 +45,4 @@
->exclude('vendor')
->in([__DIR__.'/src/',__DIR__.'/tests/'])
)
;
;
9 changes: 7 additions & 2 deletions README-CN.md
Original file line number Diff line number Diff line change
Expand Up @@ -67,8 +67,6 @@ $fp = fopen('/local/path/file.txt','r');
Storage::disk('aliyun')->put('dir/path/file.txt', $fp);
fclose($fp);

Storage::disk('aliyun')->putRemoteFile('dir/path/file.txt', 'http://example.com/file.txt');

Storage::disk('aliyun')->prepend('dir/path/file.txt', 'Prepend Text');
Storage::disk('aliyun')->append('dir/path/file.txt', 'Append Text');

Expand Down Expand Up @@ -114,6 +112,13 @@ Storage::disk('aliyun')->directories('dir/path');
Storage::disk('aliyun')->allDirectories('dir/path');
```

#### 使用 Plugin
```php
Storage::disk('aliyun')->appendContent('dir/path/news.txt', 'The first line paragraph.', 0);
Storage::disk('aliyun')->appendContent('dir/path/news.txt', 'The second line paragraph.', 25);
Storage::disk('aliyun')->appendContent('dir/path/news.txt', 'The last line paragraph.', 51);
```

#### 使用 OssClient
```php
$adapter = Storage::disk('aliyun')->getAdapter();
Expand Down
9 changes: 7 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -67,8 +67,6 @@ $fp = fopen('/local/path/file.txt','r');
Storage::disk('aliyun')->put('dir/path/file.txt', $fp);
fclose($fp);
Storage::disk('aliyun')->putRemoteFile('dir/path/file.txt', 'http://example.com/file.txt');
Storage::disk('aliyun')->prepend('dir/path/file.txt', 'Prepend Text');
Storage::disk('aliyun')->append('dir/path/file.txt', 'Append Text');
Expand Down Expand Up @@ -114,6 +112,13 @@ Storage::disk('aliyun')->directories('dir/path');
Storage::disk('aliyun')->allDirectories('dir/path');
```
#### Use Plugin
```php
Storage::disk('aliyun')->appendContent('dir/path/news.txt', 'The first line paragraph.', 0);
Storage::disk('aliyun')->appendContent('dir/path/news.txt', 'The second line paragraph.', 25);
Storage::disk('aliyun')->appendContent('dir/path/news.txt', 'The last line paragraph.', 51);
```
#### Use OssClient
```php
$adapter = Storage::disk('aliyun')->getAdapter();
Expand Down
19 changes: 8 additions & 11 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,11 @@
"alphasnow/aliyun-oss-flysystem": "^1.3"
},
"require-dev": {
"mockery/mockery": "~1.0",
"phpunit/phpunit": "~6.0",
"friendsofphp/php-cs-fixer": "^2.16",
"phpstan/phpstan": "^0.12.82",
"orchestra/testbench": "^3.5.6"
"mockery/mockery": "^1.3",
"phpunit/phpunit": "^8.5",
"friendsofphp/php-cs-fixer": "^3.2",
"phpstan/phpstan": "^0.12.99",
"orchestra/testbench": "^5.20"
},
"autoload": {
"psr-4": {
Expand All @@ -35,16 +35,13 @@
"laravel": {
"providers": [
"AlphaSnow\\AliyunOss\\ServiceProvider"
],
"aliases": {
"AliyunOssClient": "AlphaSnow\\AliyunOss\\AliyunOssClient"
}
]
}
},
"scripts": {
"phpstan": "vendor/bin/phpstan analyse",
"check-style": "vendor/bin/php-cs-fixer fix --using-cache=no --diff --config=.php_cs --dry-run --ansi",
"fix-style": "vendor/bin/php-cs-fixer fix --using-cache=no --config=.php_cs --ansi",
"check-style": "vendor/bin/php-cs-fixer fix --using-cache=no --diff --config=.php-cs-fixer.php --dry-run --ansi",
"fix-style": "vendor/bin/php-cs-fixer fix --using-cache=no --config=.php-cs-fixer.php --ansi",
"test": "vendor/bin/phpunit --colors=always --testdox"
},
"scripts-descriptions": {
Expand Down
21 changes: 2 additions & 19 deletions src/Adapter.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,10 @@
namespace AlphaSnow\AliyunOss;

use AlphaSnow\Flysystem\AliyunOss\AliyunOssAdapter as BaseAdapter;
use League\Flysystem\Adapter\CanOverwriteFiles;
use League\Flysystem\AdapterInterface;
use League\Flysystem\Config as FlysystemConfig;
use OSS\OssClient;

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

/**
* {@inheritdoc}
*/
public function getOptionsFromConfig(FlysystemConfig $config)
{
$options = parent::getOptionsFromConfig($config);

if ($visibility = $config->get('visibility')) {
// Object ACL > Bucket ACL
$options[OssClient::OSS_HEADERS][OssClient::OSS_OBJECT_ACL] = $visibility === AdapterInterface::VISIBILITY_PUBLIC ? OssClient::OSS_ACL_TYPE_PUBLIC_READ : OssClient::OSS_ACL_TYPE_PRIVATE;
}

return $options;
}

/**
* Used by \Illuminate\Filesystem\FilesystemAdapter::url
* Get the URL for the file at the given path.
Expand Down Expand Up @@ -68,13 +51,13 @@ public function getTemporaryUrl($path, $expiration = null, array $options = [])
{
$object = $this->applyPathPrefix($path);
$clientOptions = $this->getOptionsFromConfig(new FlysystemConfig($options));

if (is_null($expiration)) {
$expiration = new \DateTime($this->ossConfig->get('signature_expires'));
}
$timeout = $expiration->getTimestamp() - (new \DateTime('now'))->getTimestamp();

$url = $this->client->signUrl($this->bucket, $object, $timeout, OssClient::OSS_HTTP_GET, $clientOptions);

return $this->ossConfig->correctUrl($url);
}
}
42 changes: 0 additions & 42 deletions src/Plugins/PutRemoteFile.php

This file was deleted.

2 changes: 0 additions & 2 deletions src/ServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
namespace AlphaSnow\AliyunOss;

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

$filesystem = new Filesystem($adapter, new FlysystemConfig(['disable_asserts' => true]));
$filesystem->addPlugin(new PutRemoteFile());
$filesystem->addPlugin(new AppendContent());
return $filesystem;
});
Expand Down
26 changes: 26 additions & 0 deletions tests/ConfigTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,4 +43,30 @@ public function testGetOssEndpoint()
$endpoint = $ossConfig->getOssEndpoint();
$this->assertSame($config['internal'], $endpoint);
}

public function testCorrectUrl()
{
$config = [
'use_ssl' => false,
'bucket' => 'bucket',
'endpoint' => 'oss-cn-shanghai.aliyuncs.com',
'internal' => 'oss-cn-shanghai-internal.aliyuncs.com',
];
$ossConfig = new Config($config);
$internalUrl = 'http://bucket.oss-cn-shanghai-internal.aliyuncs.com/dir/path/file.txt';
$correctUrl = $ossConfig->correctUrl($internalUrl);
$this->assertSame('http://bucket.oss-cn-shanghai.aliyuncs.com/dir/path/file.txt', $correctUrl);

$config = [
'use_ssl' => false,
'bucket' => 'bucket',
'endpoint' => 'oss-cn-shanghai.aliyuncs.com',
'domain' => 'oss.my-domain.com',
'use_domain_endpoint' => false,
];
$ossConfig = new Config($config);
$endpointUrl = 'http://bucket.oss-cn-shanghai.aliyuncs.com/dir/path/file.txt';
$correctUrl = $ossConfig->correctUrl($endpointUrl);
$this->assertSame('http://oss.my-domain.com/dir/path/file.txt', $correctUrl);
}
}
44 changes: 0 additions & 44 deletions tests/FilesystemPluginTest.php

This file was deleted.

2 changes: 1 addition & 1 deletion tests/FilesystemTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@

use AlphaSnow\AliyunOss\Config;
use Illuminate\Filesystem\FilesystemAdapter;
use OSS\OssClient;
use Mockery\MockInterface;
use OSS\OssClient;

class FilesystemTest extends TestCase
{
Expand Down

0 comments on commit c77b833

Please sign in to comment.