gixx/worstpractice-aws-s3-adapter

A simple adapter for the AWS S3 Client

1.0.1 2021-03-23 12:18 UTC

This package is auto-updated.

Last update: 2024-11-07 00:27:52 UTC


README

A simple adapter for the AWS S3 Client

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

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