Parcourir la source

Fix ZF-12318. Support Rackspace ServiceNet

git-svn-id: http://framework.zend.com/svn/framework/standard/branches/release-1.12@25011 44c647ce-9c0f-0410-b52a-842ac1e357ba
rob il y a 13 ans
Parent
commit
cc68f29c82

+ 35 - 0
documentation/manual/en/module_specs/Zend_Service_Rackspace.xml

@@ -174,6 +174,41 @@
                 </listitem>
             </varlistentry>
             
+            <varlistentry id="zend.service.rackspace.files.methods.set-service-net">
+                <term>
+                    <methodsynopsis>
+                        <methodname>setServiceNet</methodname>
+                        <methodparam>
+                            <funcparams>boolean $useServiceNet = true</funcparams>
+                        </methodparam>                        
+                    </methodsynopsis>
+                </term>
+                
+                <listitem>
+                    <para>
+                        Use the Rackspace 'ServiceNet' internal network.
+                    </para>
+                </listitem>
+            </varlistentry>
+
+            <varlistentry id="zend.service.rackspace.files.methods.get-service-net">
+                <term>
+                    <methodsynopsis>
+                        <methodname>getServiceNet</methodname>
+                        <methodparam>
+                            <funcparams/>
+                        </methodparam>                        
+                    </methodsynopsis>
+                </term>
+                
+                <listitem>
+                    <para>
+                        Are we using the Rackspace 'ServiceNet' internal network?
+                        Returns a boolean.
+                    </para>
+                </listitem>
+            </varlistentry>
+
             <varlistentry id="zend.service.rackspace.files.methods.get-auth-url">
                 <term>
                     <methodsynopsis>

+ 36 - 1
library/Zend/Service/Rackspace/Abstract.php

@@ -96,6 +96,12 @@ abstract class Zend_Service_Rackspace_Abstract
      */
     protected $managementUrl;
     /**
+     * Do we use ServiceNet?
+     * 
+     * @var boolean
+     */
+    protected $useServiceNet = false;
+    /**
      * Constructor
      *
      * You must pass the account and the Rackspace authentication key.
@@ -231,6 +237,31 @@ abstract class Zend_Service_Rackspace_Abstract
             throw new Zend_Service_Rackspace_Exception("The authentication URL is not valid");
         }
     }
+    
+    /**
+     * Sets whether to use ServiceNet
+     * 
+     * ServiceNet is Rackspace's internal network. Bandwidth on ServiceNet is
+     * not charged.
+     * 
+     * @param boolean $useServiceNet
+     */
+    public function setServiceNet($useServiceNet = true)
+    {
+        $this->useServiceNet = $useServiceNet;
+        return $this;
+    }
+
+    /**
+     * Get whether we're using ServiceNet
+     * 
+     * @return boolean
+     */
+    public function getServiceNet()
+    {
+        return $this->useServiceNet;
+    }
+
     /**
      * Get the authentication token
      *
@@ -332,9 +363,13 @@ abstract class Zend_Service_Rackspace_Abstract
         $result = $this->httpCall($this->authUrl.'/'.self::VERSION,'GET', $headers);
         if ($result->getStatus()==204) {
             $this->token = $result->getHeader(self::AUTHTOKEN);
-            $this->storageUrl = $result->getHeader(self::STORAGE_URL);
             $this->cdnUrl = $result->getHeader(self::CDNM_URL);
             $this->managementUrl = $result->getHeader(self::MANAGEMENT_URL);
+            $storageUrl = $result->getHeader(self::STORAGE_URL);
+            if ($this->useServiceNet) {
+                $storageUrl = preg_replace('|(.*)://([^/]*)(.*)|', '$1://snet-$2$3', $storageUrl);
+            }
+            $this->storageUrl = $storageUrl;
             return true;
         }
         $this->errorMsg = $result->getBody();