Explorar el Código

Added streaming data support. The API is identical to that used by Zend_Gdata_HttpClient adding support specifically for Youtube uploads. Please refer to GData reference material (OAuth docs to be updated). Implements ZF-9410

git-svn-id: http://framework.zend.com/svn/framework/standard/trunk@22036 44c647ce-9c0f-0410-b52a-842ac1e357ba
padraic hace 15 años
padre
commit
ee70eb079d
Se han modificado 1 ficheros con 105 adiciones y 0 borrados
  1. 105 0
      library/Zend/Oauth/Client.php

+ 105 - 0
library/Zend/Oauth/Client.php

@@ -56,6 +56,14 @@ class Zend_Oauth_Client extends Zend_Http_Client
     protected $_config = null;
 
     /**
+     * True if this request is being made with data supplied by
+     * a stream object instead of a raw encoded string.
+     *
+     * @var bool
+     */
+    protected $_streamingRequest = null;
+
+    /**
      * Constructor; creates a new HTTP Client instance which itself is
      * just a typical Zend_Http_Client subclass with some OAuth icing to
      * assist in automating OAuth parameter generation, addition and
@@ -79,6 +87,103 @@ class Zend_Oauth_Client extends Zend_Http_Client
     }
 
     /**
+     * Return the current connection adapter
+     *
+     * @return Zend_Http_Client_Adapter_Interface|string $adapter
+     */
+    public function getAdapter()
+    {
+        return $this->adapter;
+    }
+    
+   /**
+     * Load the connection adapter
+     *
+     * @param Zend_Http_Client_Adapter_Interface $adapter
+     * @return void
+     */
+    public function setAdapter($adapter)
+    {
+        if ($adapter == null) {
+            $this->adapter = $adapter;
+        } else {
+              parent::setAdapter($adapter);
+        }
+    }
+
+    /**
+     * Set the streamingRequest variable which controls whether we are
+     * sending the raw (already encoded) POST data from a stream source.
+     *
+     * @param boolean $value The value to set.
+     * @return void
+     */
+    public function setStreamingRequest($value)
+    {
+        $this->_streamingRequest = $value;
+    }
+
+    /**
+     * Check whether the client is set to perform streaming requests.
+     *
+     * @return boolean True if yes, false otherwise.
+     */
+    public function getStreamingRequest()
+    {
+        if ($this->_streamingRequest) {
+            return true;
+        } else {
+            return false;
+        }
+    }
+
+    /**
+     * Prepare the request body (for POST and PUT requests)
+     *
+     * @return string
+     * @throws Zend_Http_Client_Exception
+     */
+    protected function _prepareBody()
+    {
+        if($this->_streamingRequest) {
+            $this->setHeaders(self::CONTENT_LENGTH,
+                $this->raw_post_data->getTotalSize());
+            return $this->raw_post_data;
+        }
+        else {
+            return parent::_prepareBody();
+        }
+    }
+
+    /**
+     * Clear all custom parameters we set.
+     *
+     * @return Zend_Http_Client
+     */
+    public function resetParameters($clearAll = false)
+    {
+        $this->_streamingRequest = false;
+        return parent::resetParameters($clearAll);
+    }
+
+    /**
+     * Set the raw (already encoded) POST data from a stream source.
+     *
+     * This is used to support POSTing from open file handles without
+     * caching the entire body into memory. It is a wrapper around
+     * Zend_Http_Client::setRawData().
+     *
+     * @param string $data The request data
+     * @param string $enctype The encoding type
+     * @return Zend_Http_Client
+     */
+    public function setRawDataStream($data, $enctype = null)
+    {
+        $this->_streamingRequest = true;
+        return $this->setRawData($data, $enctype);
+    }
+
+    /**
      * Same as Zend_Http_Client::setMethod() except it also creates an
      * Oauth specific reference to the method type.
      * Might be defunct and removed in a later iteration.