v2: Updates

* Simplifies & beautifies everything
* Introduces a new Class system.
* Errors are defaulted to AWS's handler.
* New function names & more efficient handling.
* Should fix a majority of the errors.

Please read the README for more!
This commit is contained in:
Devang Srivastava 2020-09-28 15:32:51 +05:30
commit e6d7753dc8
1095 changed files with 45088 additions and 2911 deletions

View file

@ -1,6 +1,9 @@
<?php
namespace Aws\S3;
use Aws\Arn\Exception\InvalidArnException;
use Aws\Arn\S3\AccessPointArn;
use Aws\Arn\ArnParser;
use GuzzleHttp\Psr7;
use Psr\Http\Message\UriInterface;
@ -31,10 +34,24 @@ class S3UriParser
* @param string|UriInterface $uri
*
* @return array
* @throws \InvalidArgumentException
* @throws \InvalidArgumentException|InvalidArnException
*/
public function parse($uri)
{
// Attempt to parse host component of uri as an ARN
$components = $this->parseS3UrlComponents($uri);
if (!empty($components)) {
if (ArnParser::isArn($components['host'])) {
$arn = new AccessPointArn($components['host']);
return [
'bucket' => $components['host'],
'key' => $components['path'],
'path_style' => false,
'region' => $arn->getRegion()
];
}
}
$url = Psr7\uri_for($uri);
if ($url->getScheme() == $this->streamWrapperScheme) {
@ -61,6 +78,19 @@ class S3UriParser
return $result;
}
private function parseS3UrlComponents($uri)
{
preg_match("/^([a-zA-Z0-9]*):\/\/([a-zA-Z0-9:-]*)\/(.*)/", $uri, $components);
if (empty($components)) {
return [];
}
return [
'scheme' => $components[1],
'host' => $components[2],
'path' => $components[3],
];
}
private function parseStreamWrapper(UriInterface $url)
{
$result = self::$defaultResult;