gixx / worstpractice-aws-s3-adapter
AWS S3 客户端的一个简单适配器
1.0.1
2021-03-23 12:18 UTC
Requires
- php: >=8.0
- aws/aws-sdk-php: ^3.175
Requires (Dev)
- friendsofphp/php-cs-fixer: v2.18.4
- phpmd/phpmd: 2.9.1
- phpstan/phpstan: 0.12.82
- phpunit/phpunit: 9.3.11
- roave/security-advisories: dev-master
- squizlabs/php_codesniffer: 3.5.8
- symplify/easy-coding-standard: 9.2.1
- symplify/phpstan-extensions: 9.2.1
- thecodingmachine/phpstan-strict-rules: v0.12.1
README
AWS S3 客户端的一个简单适配器
安装
要将此包添加到您的项目中,只需通过 composer 获取它
composer require gixx/worstpractice-aws-s3-adapter
使用方法
<?php defined('S3_ACCESS_KEY') || define('S3_ACCESS_KEY', '<MyAccessKey>'); defined('S3_SECRET_KEY') || define('S3_SECRET_KEY', '<MySecretKey>'); require_once('vendor/autoload.php'); use Aws\Credentials\Credentials; use Aws\S3\S3Client; use WorstPractice\Component\Aws\S3\Adapter; $credentials = new Credentials( S3_ACCESS_KEY, S3_SECRET_KEY ); $s3Client = new S3Client([ 'credentials' => $credentials, 'region' => 'eu-central-1', 'version' => '2006-03-01', ]); $s3Adapter = new Adapter($s3Client); $s3Adapter->setBucket('my-bucket'); // The result will be the "key" (kind of absolute path + filename) of the file in the S3 bucket or NULL when no file // found on the given "path". $latestFileInFolder = $s3Adapter->getLastUploadedKeyByPrefix('folder/subfolder');
测试
该包包含一个简单的 Docker 设置,以便能够运行测试。为此,您只需运行以下命令
docker-compose up -d
docker exec -it worstpractice-aws-s3-adapter php -d memory_limit=-1 composer.phar install
docker exec -it worstpractice-aws-s3-adapter php composer.phar check
以下测试将运行
- PHP 检查
- PHP 错误检测器
- PHP-CS-Fixer
- PHP 代码检查器
- PHP 单元测试
- PHPStan