mirror of
https://github.com/SociallyDev/Spaces-API.git
synced 2025-08-20 21:33:43 -07:00
spaces.php
This commit is contained in:
parent
7755490b81
commit
eefa32741e
845 changed files with 50409 additions and 0 deletions
77
aws/Aws/Endpoint/PartitionEndpointProvider.php
Normal file
77
aws/Aws/Endpoint/PartitionEndpointProvider.php
Normal file
|
@ -0,0 +1,77 @@
|
|||
<?php
|
||||
namespace Aws\Endpoint;
|
||||
|
||||
class PartitionEndpointProvider
|
||||
{
|
||||
/** @var Partition[] */
|
||||
private $partitions;
|
||||
/** @var string */
|
||||
private $defaultPartition;
|
||||
|
||||
public function __construct(array $partitions, $defaultPartition = 'aws')
|
||||
{
|
||||
$this->partitions = array_map(function (array $definition) {
|
||||
return new Partition($definition);
|
||||
}, array_values($partitions));
|
||||
$this->defaultPartition = $defaultPartition;
|
||||
}
|
||||
|
||||
public function __invoke(array $args = [])
|
||||
{
|
||||
$partition = $this->getPartition(
|
||||
isset($args['region']) ? $args['region'] : '',
|
||||
isset($args['service']) ? $args['service'] : ''
|
||||
);
|
||||
|
||||
return $partition($args);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the partition containing the provided region or the default
|
||||
* partition if no match is found.
|
||||
*
|
||||
* @param string $region
|
||||
* @param string $service
|
||||
*
|
||||
* @return Partition
|
||||
*/
|
||||
public function getPartition($region, $service)
|
||||
{
|
||||
foreach ($this->partitions as $partition) {
|
||||
if ($partition->isRegionMatch($region, $service)) {
|
||||
return $partition;
|
||||
}
|
||||
}
|
||||
|
||||
return $this->getPartitionByName($this->defaultPartition);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the partition with the provided name or null if no partition with
|
||||
* the provided name can be found.
|
||||
*
|
||||
* @param string $name
|
||||
*
|
||||
* @return Partition|null
|
||||
*/
|
||||
public function getPartitionByName($name)
|
||||
{
|
||||
foreach ($this->partitions as $partition) {
|
||||
if ($name === $partition->getName()) {
|
||||
return $partition;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates and returns the default SDK partition provider.
|
||||
*
|
||||
* @return PartitionEndpointProvider
|
||||
*/
|
||||
public static function defaultProvider()
|
||||
{
|
||||
$data = \Aws\load_compiled_json(dirname(__FILE__) . '/../data/endpoints.json');
|
||||
|
||||
return new self($data['partitions']);
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue