Region.php 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. <?php
  2. /**
  3. * Zend Framework
  4. *
  5. * LICENSE
  6. *
  7. * This source file is subject to the new BSD license that is bundled
  8. * with this package in the file LICENSE.txt.
  9. * It is also available through the world-wide-web at this URL:
  10. * http://framework.zend.com/license/new-bsd
  11. * If you did not receive a copy of the license and are unable to
  12. * obtain it through the world-wide-web, please send an email
  13. * to license@zend.com so we can send you a copy immediately.
  14. *
  15. * @category Zend
  16. * @package Zend_Service_Amazon
  17. * @subpackage Ec2
  18. * @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
  19. * @license http://framework.zend.com/license/new-bsd New BSD License
  20. * @version $Id$
  21. */
  22. /**
  23. * @see Zend_Service_Amazon_Ec2_Abstract
  24. */
  25. require_once 'Zend/Service/Amazon/Ec2/Abstract.php';
  26. /**
  27. * An Amazon EC2 interface to query which Regions your account has access to.
  28. *
  29. * @category Zend
  30. * @package Zend_Service_Amazon
  31. * @subpackage Ec2
  32. * @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
  33. * @license http://framework.zend.com/license/new-bsd New BSD License
  34. */
  35. class Zend_Service_Amazon_Ec2_Region extends Zend_Service_Amazon_Ec2_Abstract
  36. {
  37. /**
  38. * Describes availability zones that are currently available to the account
  39. * and their states.
  40. *
  41. * @param string|array $region Name of an region.
  42. * @return array An array that contains all the return items. Keys: regionName and regionUrl.
  43. */
  44. public function describe($region = null)
  45. {
  46. $params = array();
  47. $params['Action'] = 'DescribeRegions';
  48. if(is_array($region) && !empty($region)) {
  49. foreach($region as $k=>$name) {
  50. $params['Region.' . ($k+1)] = $name;
  51. }
  52. } elseif($region) {
  53. $params['Region.1'] = $region;
  54. }
  55. $response = $this->sendRequest($params);
  56. $xpath = $response->getXPath();
  57. $nodes = $xpath->query('//ec2:item');
  58. $return = array();
  59. foreach ($nodes as $k => $node) {
  60. $item = array();
  61. $item['regionName'] = $xpath->evaluate('string(ec2:regionName/text())', $node);
  62. $item['regionUrl'] = $xpath->evaluate('string(ec2:regionUrl/text())', $node);
  63. $return[] = $item;
  64. unset($item);
  65. }
  66. return $return;
  67. }
  68. }