示例#1
0
文件: ec2.php 项目: fruux/ec2dns
 /**
  * Returns the region constants defined in the \Aws\Common\Enum\Region class
  * for endpoint urls
  *
  * @param string $url
  * @return constant
  */
 private function getRegionByUrl($url)
 {
     $url = strtolower(parse_url($url, \PHP_URL_HOST));
     $regions = ['ec2.us-east-1.amazonaws.com' => 'us-east-1', 'ec2.us-west-1.amazonaws.com' => 'us-west-1', 'ec2.us-west-2.amazonaws.com' => 'us-west-2', 'ec2.eu-west-1.amazonaws.com' => 'eu-west-1', 'ec2.eu-central-1.amazonaws.com' => 'eu-central-1', 'ec2.ap-northeast-1.amazonaws.com' => 'ap-northeast-1', 'ec2.ap-southeast-1.amazonaws.com' => 'ap-southeast-1', 'ec2.ap-southeast-2.amazonaws.com' => 'ap-southeast-2', 'ec2.sa-east-1.amazonaws.com' => 'sa-east-1', 'ec2.cn-north-1.amazonaws.com.cn' => 'cn-north-1', 'ec2.us-gov-west-1.amazonaws.com' => 'us-gov-west-1'];
     if (!isset($regions[$url])) {
         throw new \InvalidArgumentException('The supplied region is unknown. Check your EC2_URL environment variable.');
     }
     if (!in_array($regions[$url], \Aws\Common\Enum\Region::values())) {
         throw new \InvalidArgumentException('The supplied region is known, but not supported by your version of aws/aws-sdk-php.');
     }
     return $regions[strtolower($url)];
 }
 public function get_region($region)
 {
     $region = str_replace('-', '_', strtoupper($region));
     $regions = Region::values();
     return isset($regions[$region]) ? $regions[$region] : false;
 }