mirror of
https://github.com/SociallyDev/Spaces-API.git
synced 2025-08-20 13:23:47 -07:00
spaces.php
This commit is contained in:
parent
7755490b81
commit
eefa32741e
845 changed files with 50409 additions and 0 deletions
51
aws/Aws/Endpoint/PatternEndpointProvider.php
Normal file
51
aws/Aws/Endpoint/PatternEndpointProvider.php
Normal file
|
@ -0,0 +1,51 @@
|
|||
<?php
|
||||
namespace Aws\Endpoint;
|
||||
|
||||
/**
|
||||
* Provides endpoints based on an endpoint pattern configuration array.
|
||||
*/
|
||||
class PatternEndpointProvider
|
||||
{
|
||||
/** @var array */
|
||||
private $patterns;
|
||||
|
||||
/**
|
||||
* @param array $patterns Hash of endpoint patterns mapping to endpoint
|
||||
* configurations.
|
||||
*/
|
||||
public function __construct(array $patterns)
|
||||
{
|
||||
$this->patterns = $patterns;
|
||||
}
|
||||
|
||||
public function __invoke(array $args = [])
|
||||
{
|
||||
$service = isset($args['service']) ? $args['service'] : '';
|
||||
$region = isset($args['region']) ? $args['region'] : '';
|
||||
$keys = ["{$region}/{$service}", "{$region}/*", "*/{$service}", "*/*"];
|
||||
|
||||
foreach ($keys as $key) {
|
||||
if (isset($this->patterns[$key])) {
|
||||
return $this->expand(
|
||||
$this->patterns[$key],
|
||||
isset($args['scheme']) ? $args['scheme'] : 'https',
|
||||
$service,
|
||||
$region
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
private function expand(array $config, $scheme, $service, $region)
|
||||
{
|
||||
$config['endpoint'] = $scheme . '://'
|
||||
. strtr($config['endpoint'], [
|
||||
'{service}' => $service,
|
||||
'{region}' => $region
|
||||
]);
|
||||
|
||||
return $config;
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue