web/lib/Zend/Service/Amazon/Sqs.php
changeset 807 877f952ae2bd
parent 207 621fa6caec0c
child 1230 68c69c656a2c
--- a/web/lib/Zend/Service/Amazon/Sqs.php	Thu Mar 21 17:31:31 2013 +0100
+++ b/web/lib/Zend/Service/Amazon/Sqs.php	Thu Mar 21 19:50:53 2013 +0100
@@ -15,9 +15,9 @@
  * @category   Zend
  * @package    Zend_Service
  * @subpackage Amazon_Sqs
- * @copyright  Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
+ * @copyright  Copyright (c) 2005-2012 Zend Technologies USA Inc. (http://www.zend.com)
  * @license    http://framework.zend.com/license/new-bsd     New BSD License
- * @version    $Id: Sqs.php 22984 2010-09-21 02:52:48Z matthew $
+ * @version    $Id: Sqs.php 25024 2012-07-30 15:08:15Z rob $
  */
 
 /**
@@ -36,7 +36,7 @@
  * @category   Zend
  * @package    Zend_Service
  * @subpackage Amazon_Sqs
- * @copyright  Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
+ * @copyright  Copyright (c) 2005-2012 Zend Technologies USA Inc. (http://www.zend.com)
  * @license    http://framework.zend.com/license/new-bsd     New BSD License
  * @see        http://aws.amazon.com/sqs/ Amazon Simple Queue Service
  */
@@ -67,9 +67,17 @@
      */
     protected $_sqsSignatureMethod = 'HmacSHA256';
 
+    protected $_sqsEndpoints = array('us-east-1' => 'sqs.us-east-1.amazonaws.com',
+                                     'us-west-1' => 'sqs.us-west-1.amazonaws.com',
+                                     'eu-west-1' => 'sqs.eu-west-1.amazonaws.com',
+                                     'ap-southeast-1' => 'sqs.ap-southeast-1.amazonaws.com',
+                                     'ap-northeast-1' => 'sqs.ap-northeast-1.amazonaws.com');
     /**
      * Constructor
      *
+     * The default region is us-east-1. Use the region to set it to one of the regions that is build-in into ZF.
+     * To add a new AWS region use the setEndpoint() method.
+     *
      * @param string $accessKey
      * @param string $secretKey
      * @param string $region
@@ -77,9 +85,78 @@
     public function __construct($accessKey = null, $secretKey = null, $region = null)
     {
         parent::__construct($accessKey, $secretKey, $region);
+        
+        if (null !== $region) {
+            $this->_setEndpoint($region);
+        }
     }
 
     /**
+     * Set SQS endpoint
+     *
+     * Checks and sets endpoint if region exists in $_sqsEndpoints. If a new SQS region is added by amazon,
+     * please use the setEndpoint function to set it.
+     *
+     * @param  string  $region region
+     * @throws Zend_Service_Amazon_Sqs_Exception
+     */
+    protected function _setEndpoint($region)
+    {
+        if (array_key_exists($region, $this->_sqsEndpoints)) {
+            $this->_sqsEndpoint = $this->_sqsEndpoints[$region];
+        } else {
+            throw new Zend_Service_Amazon_Sqs_Exception('Invalid SQS region specified.');
+        }
+    }
+    
+    /**
+     * Set SQS endpoint
+     *
+     * You can set SQS to on of the build-in regions. If the region does not exsist it will be added.
+     *
+     * @param  string  $region region
+     * @throws Zend_Service_Amazon_Sqs_Exception
+     */
+    public function setEndpoint($region)
+    {
+        if (!empty($region)) {
+            if (array_key_exists($region, $this->_sqsEndpoints)) {
+                $this->_sqsEndpoint = $this->_sqsEndpoints[$region];
+            } else {
+                $this->_sqsEndpoints[$region] = "sqs.$region.amazonaws.com";
+                $this->_sqsEndpoint = $this->_sqsEndpoints[$region];
+            }
+        } else {
+            throw new Zend_Service_Amazon_Sqs_Exception('Empty region specified.');
+        }
+    }
+
+    /**
+     * Get the SQS endpoint
+     * 
+     * @return string 
+     */
+    public function getEndpoint()
+    {
+        return $this->_sqsEndpoint;
+    }
+
+    /**
+     * Get possible SQS endpoints
+     *
+     * Since there is not an SQS webserive to get all possible endpoints, a hardcoded list is available.
+     * For the actual region list please check:
+     * http://docs.amazonwebservices.com/AWSSimpleQueueService/2009-02-01/APIReference/index.html?QueueServiceWsdlArticle.html
+     *
+     * @param  string  $region region
+     * @return array
+     */
+    public function getEndpoints()
+    {
+        return $this->_sqsEndpoints;
+    }
+    
+    /**
      * Create a new queue
      *
      * Visibility timeout is how long a message is left in the queue "invisible"
@@ -288,7 +365,7 @@
 
         $result = $this->_makeRequest($queue_url, 'DeleteMessage', $params);
 
-        if (isset($result->Error->Code) 
+        if (isset($result->Error->Code)
             && !empty($result->Error->Code)
         ) {
             return false;
@@ -319,7 +396,7 @@
             require_once 'Zend/Service/Amazon/Sqs/Exception.php';
             throw new Zend_Service_Amazon_Sqs_Exception($result->Error->Code);
         }
-        
+
         if(count($result->GetQueueAttributesResult->Attribute) > 1) {
             $attr_result = array();
             foreach($result->GetQueueAttributesResult->Attribute as $attribute) {