-
Notifications
You must be signed in to change notification settings - Fork 0
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add S3Key implementation to construct S3 paths #21
Merged
Merged
Changes from 5 commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
562d699
Add S3Key implementation to construct S3 paths
thekid bdd3511
Add a variety of tests for S3 URL encoding
thekid 39f1e6d
Support S3Key instances in ServiceEndpoint::sign()
thekid 2cefe55
Extract handling S3 keys, which do not double-encode the path component
thekid 904156c
Restore PHP 7.0 compatibility
thekid 55b068e
Reinstate comment
thekid dc69c5b
QA: Reduce diff [skip ci]
thekid c9d8f27
QA: Remove unused import
thekid File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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,41 @@ | ||
<?php namespace com\amazon\aws; | ||
|
||
use lang\Value; | ||
|
||
/** | ||
* S3 Keys help construct paths from components | ||
* | ||
* @test com.amazon.aws.unittest.S3KeyTest | ||
*/ | ||
class S3Key implements Value { | ||
private $path; | ||
|
||
/** Creates a new S3 key from given components */ | ||
public function __construct(string... $components) { | ||
$this->path= ltrim(implode('/', $components), '/'); | ||
} | ||
|
||
/** Returns the path */ | ||
public function path(string $base= ''): string { | ||
return rtrim($base, '/').'/'.$this->path; | ||
} | ||
|
||
/** @return string */ | ||
public function __toString() { return '/'.$this->path; } | ||
|
||
/** @return string */ | ||
public function hashCode() { return 'S3'.md5($this->path); } | ||
|
||
/** @return string */ | ||
public function toString() { return nameof($this).'(/'.$this->path.')'; } | ||
|
||
/** | ||
* Comparison | ||
* | ||
* @param var $value | ||
* @return int | ||
*/ | ||
public function compareTo($value) { | ||
return $value instanceof self ? $this->path <=> $value->path : 1; | ||
} | ||
} |
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
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,46 @@ | ||
<?php namespace com\amazon\aws\unittest; | ||
|
||
use com\amazon\aws\S3Key; | ||
use test\{Assert, Test, Values}; | ||
|
||
class S3KeyTest { | ||
|
||
#[Test] | ||
public function empty() { | ||
Assert::equals('/', (new S3Key())->path()); | ||
} | ||
|
||
#[Test] | ||
public function single() { | ||
Assert::equals('/test', (new S3Key('test'))->path()); | ||
} | ||
|
||
#[Test] | ||
public function composed() { | ||
Assert::equals('/target/test', (new S3Key('target', 'test'))->path()); | ||
} | ||
|
||
#[Test, Values(['/base', '/base/'])] | ||
public function based($base) { | ||
Assert::equals('/base/test', (new S3Key('test'))->path($base)); | ||
} | ||
|
||
#[Test] | ||
public function string_cast() { | ||
Assert::equals('/test', (string)new S3Key('test')); | ||
} | ||
|
||
#[Test] | ||
public function string_representation() { | ||
Assert::equals('com.amazon.aws.S3Key(/target/test)', (new S3Key('target', 'test'))->toString()); | ||
} | ||
|
||
#[Test] | ||
public function comparison() { | ||
$fixture= new S3Key('b-test'); | ||
|
||
Assert::equals(0, $fixture->compareTo(new S3Key('b-test'))); | ||
Assert::equals(1, $fixture->compareTo(new S3Key('a-test'))); | ||
Assert::equals(-1, $fixture->compareTo(new S3Key('c-test'))); | ||
} | ||
} |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
With PHP 8.0+, we could use
string|S3Key
here, see https://wiki.php.net/rfc/union_types_v2