Skip to content

Commit

Permalink
Add support for aws-sdk-php v2
Browse files Browse the repository at this point in the history
  • Loading branch information
Albin Kerouanton committed Jun 2, 2017
1 parent fc28c27 commit 16a3b63
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 14 deletions.
1 change: 1 addition & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ php:

before_script:
- composer self-update && composer install --prefer-source --no-interaction
- if [[ ${TRAVIS_PHP_VERSION:0:1} == "5" ]]; then composer update --prefer-lowest && composer update knplabs/gaufrette; fi

script:
- php bin/phpspec run -fpretty --verbose
Expand Down
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
"require-dev": {
"phpspec/phpspec": "^3.4",
"phpunit/phpunit": "~5.5",
"aws/aws-sdk-php": "~3"
"aws/aws-sdk-php": "~2.4|~3"
},
"license": "MIT",
"authors": [
Expand Down
12 changes: 0 additions & 12 deletions spec/Resolvable/Resolver/AwsS3PresignedUrlResolverSpec.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,16 +26,4 @@ function it_is_a_resolver()
{
$this->shouldImplement(ResolverInterface::class);
}

function it_resolves_object_path_into_presigned_url(
$client,
CommandInterface $command,
RequestInterface $presignedRequest
) {
$client->getCommand('GetObject', ['Bucket' => 'bucket', 'Key' => 'base/dir/foo.png'])->willReturn($command);
$client->createPresignedRequest($command, Argument::type(\DateTime::class))->willReturn($presignedRequest);
$presignedRequest->getUri()->willReturn('https://amazon');

$this->resolve('/foo.png')->shouldReturn('https://amazon');
}
}
12 changes: 11 additions & 1 deletion src/Resolvable/Resolver/AwsS3PresignedUrlResolver.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,10 +45,20 @@ public function __construct(S3Client $service, $bucket, $baseDir, \DateTimeInter
*
* @param string $path
*
* @return (string) \Psr\Http\Message\UriInterface
* @return string
*/
public function resolve($path)
{
// For AWS SDK v2
if ($this->service instanceof \Aws\Common\Client\AbstractClient) {
return $this->service->getObjectUrl(
$this->bucket,
$this->computePath($path),
$this->expiresAt
);
}

// For AWS SDK v3
$command = $this->service->getCommand('GetObject', [
'Bucket' => $this->bucket,
'Key' => $this->computePath($path),
Expand Down
12 changes: 12 additions & 0 deletions tests/Resolvable/Resolver/AwsS3SetUpTearDownTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,18 @@ public function setUp()
}

$this->bucket = uniqid(getenv('AWS_BUCKET'));

// For AWS SDK v2
if (class_exists('Aws\Common\Client\AbstractClient')) {
return $this->client = S3Client::factory([
'region' => $region ? $region : 'eu-west-1',
'version' => '2006-03-01',
'key' => $key,
'secret' => $secret,
]);
}

// For AWS SDK v3
$this->client = new S3Client([
'region' => $region ? $region : 'eu-west-1',
'version' => 'latest',
Expand Down

0 comments on commit 16a3b63

Please sign in to comment.