-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
a9f30d0
commit 28ae47b
Showing
6 changed files
with
187 additions
and
66 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Phant\Client\Port; | ||
|
||
interface S3 | ||
{ | ||
public function setObject( | ||
string $bucket, | ||
string $key, | ||
string $body | ||
): void; | ||
|
||
public function getObject( | ||
string $bucket, | ||
string $key | ||
): string; | ||
|
||
public function deleteObject( | ||
string $bucket, | ||
string $key | ||
): void; | ||
} |
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 |
---|---|---|
@@ -0,0 +1,21 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Phant\Client\Port\S3; | ||
|
||
interface Object | ||
{ | ||
public function set( | ||
string $key, | ||
string $body | ||
): void; | ||
|
||
public function get( | ||
string $key | ||
): string; | ||
|
||
public function delete( | ||
string $key | ||
): void; | ||
} |
This file was deleted.
Oops, something went wrong.
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 |
---|---|---|
@@ -0,0 +1,74 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Phant\Client\Service; | ||
|
||
use Aws\S3\S3Client; | ||
use Phant\Error\NotFound; | ||
|
||
class S3 implements \Phant\Client\Port\S3 | ||
{ | ||
protected S3Client $S3Client; | ||
|
||
public function __construct( | ||
string $region, | ||
string $endpoint, | ||
string $accessKey, | ||
string $secretKey, | ||
string $version = '2006-03-01' | ||
) { | ||
$this->S3Client = new S3Client([ | ||
'region' => $region, | ||
'endpoint' => $endpoint, | ||
'credentials' => [ | ||
'key' => $accessKey, | ||
'secret' => $secretKey, | ||
], | ||
'version' => $version, | ||
'use_path_style_endpoint' => true | ||
]); | ||
} | ||
|
||
public function setObject( | ||
string $bucket, | ||
string $key, | ||
string $body | ||
): void { | ||
$this->S3Client->putObject([ | ||
'Bucket' => $bucket, | ||
'Key' => $key, | ||
'Body' => $body, | ||
]); | ||
} | ||
|
||
public function getObject( | ||
string $bucket, | ||
string $key | ||
): string { | ||
try { | ||
$object = $this->S3Client->getObject([ | ||
'Bucket' => $bucket, | ||
'Key' => $key, | ||
]); | ||
|
||
return $object['Body']->getContents(); | ||
} catch (\Exception $e) { | ||
throw new NotFound('Object : ' . $key); | ||
} | ||
} | ||
|
||
public function deleteObject( | ||
string $bucket, | ||
string $key | ||
): void { | ||
try { | ||
$this->S3Client->deleteObject([ | ||
'Bucket' => $bucket, | ||
'Key' => $key, | ||
]); | ||
} catch (\Exception $e) { | ||
throw new NotFound('Object : ' . $key); | ||
} | ||
} | ||
} |
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 |
---|---|---|
@@ -0,0 +1,45 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Phant\Client\Service\S3; | ||
|
||
use Phant\Client\Service\S3; | ||
|
||
class Object implements \Phant\Client\Port\S3\Object | ||
{ | ||
public function __construct( | ||
protected readonly S3 $client, | ||
protected readonly string $bucket | ||
) { | ||
} | ||
|
||
public function set( | ||
string $key, | ||
string $body | ||
): void { | ||
$this->client->setObject( | ||
$this->bucket, | ||
$key, | ||
$body, | ||
); | ||
} | ||
|
||
public function get( | ||
string $key | ||
): string { | ||
return $this->client->getObject( | ||
$this->bucket, | ||
$key, | ||
); | ||
} | ||
|
||
public function delete( | ||
string $key | ||
): void { | ||
$this->client->deleteObject( | ||
$this->bucket, | ||
$key, | ||
); | ||
} | ||
} |