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
parent ad0726e41e
commit e6d7753dc8
1095 changed files with 45088 additions and 2911 deletions

View file

@ -2,7 +2,8 @@
namespace Aws\S3;
use Aws\CommandInterface;
use Aws\S3\Exception\S3Exception;
use Aws\Endpoint\EndpointProvider;
use Aws\Endpoint\PartitionEndpointProvider;
use Psr\Http\Message\RequestInterface;
/**
@ -39,27 +40,31 @@ class S3EndpointMiddleware
/** @var string */
private $region;
/** @var callable */
private $endpointProvider;
/** @var callable */
private $nextHandler;
/**
* Create a middleware wrapper function
*
* @param string $region
* @param EndpointProvider $endpointProvider
* @param array $options
*
* @return callable
*/
public static function wrap($region, array $options)
public static function wrap($region, $endpointProvider, array $options)
{
return function (callable $handler) use ($region, $options) {
return new self($handler, $region, $options);
return function (callable $handler) use ($region, $endpointProvider, $options) {
return new self($handler, $region, $options, $endpointProvider);
};
}
public function __construct(
callable $nextHandler,
$region,
array $options
array $options,
$endpointProvider = null
) {
$this->pathStyleByDefault = isset($options['path_style'])
? (bool) $options['path_style'] : false;
@ -68,6 +73,9 @@ class S3EndpointMiddleware
$this->accelerateByDefault = isset($options['accelerate'])
? (bool) $options['accelerate'] : false;
$this->region = (string) $region;
$this->endpointProvider = is_null($endpointProvider)
? PartitionEndpointProvider::defaultProvider()
: $endpointProvider;
$this->nextHandler = $nextHandler;
}
@ -111,7 +119,8 @@ class S3EndpointMiddleware
&& (
$request->getUri()->getScheme() === 'http'
|| strpos($command['Bucket'], '.') === false
);
)
&& filter_var($request->getUri()->getHost(), FILTER_VALIDATE_IP) === false;
}
private function endpointPatternDecider(
@ -131,17 +140,23 @@ class S3EndpointMiddleware
return $this->canAccelerate($command)
? self::ACCELERATE_DUALSTACK
: self::DUALSTACK;
} elseif ($accelerate && $this->canAccelerate($command)) {
}
if ($accelerate && $this->canAccelerate($command)) {
return self::ACCELERATE;
} elseif ($dualStack) {
}
if ($dualStack) {
return self::DUALSTACK;
} elseif (!$pathStyle
}
if (!$pathStyle
&& self::isRequestHostStyleCompatible($command, $request)
) {
return self::HOST_STYLE;
} else {
return self::PATH_STYLE;
}
return self::PATH_STYLE;
}
private function canAccelerate(CommandInterface $command)
@ -183,9 +198,9 @@ class S3EndpointMiddleware
RequestInterface $request
) {
$request = $request->withUri(
$request->getUri()
->withHost($this->getDualStackHost())
$request->getUri()->withHost($this->getDualStackHost())
);
if (empty($command['@use_path_style_endpoint'])
&& !$this->pathStyleByDefault
&& self::isRequestHostStyleCompatible($command, $request)
@ -197,7 +212,10 @@ class S3EndpointMiddleware
private function getDualStackHost()
{
return "s3.dualstack.{$this->region}.amazonaws.com";
$dnsSuffix = $this->endpointProvider
->getPartition($this->region, 's3')
->getDnsSuffix();
return "s3.dualstack.{$this->region}.{$dnsSuffix}";
}
private function applyAccelerateEndpoint(
@ -218,7 +236,10 @@ class S3EndpointMiddleware
private function getAccelerateHost(CommandInterface $command, $pattern)
{
return "{$command['Bucket']}.{$pattern}.amazonaws.com";
$dnsSuffix = $this->endpointProvider
->getPartition($this->region, 's3')
->getDnsSuffix();
return "{$command['Bucket']}.{$pattern}.{$dnsSuffix}";
}
private function getBucketlessPath($path, CommandInterface $command)