-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #3 from NiR-/fix/resolve-aws-sdk-v2
Add support for aws-sdk-php v2
- Loading branch information
Showing
11 changed files
with
68 additions
and
16 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,6 +4,26 @@ | |
|
||
use Gaufrette\FilesystemInterface; | ||
|
||
/** | ||
* Filesystem decorator providing resolve() method to resolve an object path into URI. | ||
* | ||
* Example: | ||
* $client = // AwsS3 client instantiation | ||
* $decorated = new Filesystem(new AwsS3($client, 'my_bucket', ['directory' => 'root/dir'])); | ||
* $filesystem = new ResolvableFilesystem( | ||
* $decorated, | ||
* new AwsS3PresignedUrlResolver($client, 'my_bucket', 'root/dir') | ||
* ); | ||
* | ||
* try { | ||
* // should return something like "https://eu-west-1.blabla.aws.com/my_bucket/root/dir/foo/bar.png?token | ||
* var_dump($filesystem->resolve('foo/bar.png')); | ||
* } catch (ResolverException $e) { | ||
* | ||
* } | ||
* | ||
* @author Albin Kerouanton <[email protected]> | ||
*/ | ||
class ResolvableFilesystem implements FilesystemInterface | ||
{ | ||
/** @var FilesystemInterface */ | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,6 +8,8 @@ | |
/** | ||
* Resolves object paths into time-limited URLs, namely presigned URLs. | ||
* | ||
* @author Albin Kerouanton <[email protected]> | ||
* | ||
* @see http://docs.aws.amazon.com/AmazonS3/latest/dev/ShareObjectPreSignedURL.html | ||
*/ | ||
class AwsS3PresignedUrlResolver implements ResolverInterface | ||
|
@@ -43,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), | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,7 +6,9 @@ | |
use Gaufrette\Extras\Resolvable\ResolverInterface; | ||
|
||
/** | ||
* Resolves objects' path into public URLs. | ||
* Resolves path of public objects into URLs. | ||
* | ||
* @author Albin Kerouanton <[email protected]> | ||
*/ | ||
class AwsS3PublicUrlResolver implements ResolverInterface | ||
{ | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,6 +6,8 @@ | |
|
||
/** | ||
* Resolves object path by prepending a static prefix. | ||
* | ||
* @author Albin Kerouanton <[email protected]> | ||
*/ | ||
class StaticUrlResolver implements ResolverInterface | ||
{ | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,6 +2,11 @@ | |
|
||
namespace Gaufrette\Extras\Resolvable; | ||
|
||
/** | ||
* Base exception thrown by resolvers if they fail to resolve an object path into URI. | ||
* | ||
* @author Albin Kerouanton <[email protected]> | ||
*/ | ||
class ResolverException extends \Exception | ||
{ | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,6 +2,11 @@ | |
|
||
namespace Gaufrette\Extras\Resolvable; | ||
|
||
/** | ||
* Resolves an object path into an URI. | ||
* | ||
* @author Albin Kerouanton <[email protected]> | ||
*/ | ||
interface ResolverInterface | ||
{ | ||
/** | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,6 +2,11 @@ | |
|
||
namespace Gaufrette\Extras\Resolvable; | ||
|
||
/** | ||
* Exception thrown by the filesystem when resolution fail. | ||
* | ||
* @author Albin Kerouanton <[email protected]> | ||
*/ | ||
class UnresolvableObjectException extends \Exception | ||
{ | ||
/** | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters