gixx/worstpractice-aws-s3-adapter

AWS S3 客户端的一个简单适配器

1.0.1 2021-03-23 12:18 UTC

This package is auto-updated.

Last update: 2024-09-06 23:57:40 UTC


README

AWS S3 客户端的一个简单适配器

PHP Version Build Status Scrutinizer Code Quality Code Coverage Packagist Package Packagist Downloads

安装

要将此包添加到您的项目中,只需通过 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