EndpointConfig.php 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. <?php
  2. /*
  3. * Licensed to the Apache Software Foundation (ASF) under one
  4. * or more contributor license agreements. See the NOTICE file
  5. * distributed with this work for additional information
  6. * regarding copyright ownership. The ASF licenses this file
  7. * to you under the Apache License, Version 2.0 (the
  8. * "License"); you may not use this file except in compliance
  9. * with the License. You may obtain a copy of the License at
  10. *
  11. * http://www.apache.org/licenses/LICENSE-2.0
  12. *
  13. * Unless required by applicable law or agreed to in writing,
  14. * software distributed under the License is distributed on an
  15. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  16. * KIND, either express or implied. See the License for the
  17. * specific language governing permissions and limitations
  18. * under the License.
  19. */
  20. $endpoint_filename = dirname(__FILE__) . DIRECTORY_SEPARATOR . "endpoints.xml";
  21. $xml = simplexml_load_string(file_get_contents($endpoint_filename));
  22. $json = json_encode($xml);
  23. $json_array = json_decode($json, TRUE);
  24. $endpoints = array();
  25. foreach ($json_array["Endpoint"] as $json_endpoint) {
  26. # pre-process RegionId & Product
  27. if (!array_key_exists("RegionId", $json_endpoint["RegionIds"])) {
  28. $region_ids = array();
  29. } else {
  30. $json_region_ids = $json_endpoint['RegionIds']['RegionId'];
  31. if (!is_array($json_region_ids)) {
  32. $region_ids = array($json_region_ids);
  33. } else {
  34. $region_ids = $json_region_ids;
  35. }
  36. }
  37. if (!array_key_exists("Product", $json_endpoint["Products"])) {
  38. $products = array();
  39. } else {
  40. $json_products = $json_endpoint["Products"]["Product"];
  41. if (array() === $json_products or !is_array($json_products)) {
  42. $products = array();
  43. } else if (array_keys($json_products) !== range(0, count($json_products) - 1)) {
  44. # array is not sequential
  45. $products = array($json_products);
  46. } else {
  47. $products = $json_products;
  48. }
  49. }
  50. $product_domains = array();
  51. foreach ($products as $product) {
  52. $product_domain = new ProductDomain($product['ProductName'], $product['DomainName']);
  53. array_push($product_domains, $product_domain);
  54. }
  55. $endpoint = new Endpoint($region_ids[0], $region_ids, $product_domains);
  56. array_push($endpoints, $endpoint);
  57. }
  58. EndpointProvider::setEndpoints($endpoints);