gixx / worstpractice-aws-s3-adapter
A simple adapter for the AWS S3 Client
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
A simple adapter for the AWS S3 Client
Installation
To add this package to your project, just get it via composer:
composer require gixx/worstpractice-aws-s3-adapter
Usage
<?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');
Testing
The package contains a simple Docker setup to be able to run tests. For this you need only run the following:
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
The following tests will run:
- PHP lint
- PHP Mess Detector
- PHP-CS-Fixer
- PHP Code Sniffer
- PHP Unit
- PHPStan