Kaynağa Gözat

ZF-7040 - Add Method to cURL Adapter that allows to retrieve the current cUrl Handle

git-svn-id: http://framework.zend.com/svn/framework/standard/trunk@16500 44c647ce-9c0f-0410-b52a-842ac1e357ba
beberlei 16 yıl önce
ebeveyn
işleme
eb25ff852d

+ 3 - 2
documentation/manual/en/module_specs/Zend_Http_Client-Adapters.xml

@@ -16,7 +16,7 @@
             class, and with the same interface.
             class, and with the same interface.
         </para>
         </para>
         <para>
         <para>
-            Currently, the Zend_Http_Client class provides three built-in
+            Currently, the Zend_Http_Client class provides four built-in
             connection adapters:
             connection adapters:
             <itemizedlist>
             <itemizedlist>
                 <listitem>
                 <listitem>
@@ -425,7 +425,8 @@ $client = new Zend_Http_Client($uri, $config);
             the Socket Adapter. You can change the cURL options by either specifying
             the Socket Adapter. You can change the cURL options by either specifying
             the 'curloptions' key in the constructor of the adapter or by calling
             the 'curloptions' key in the constructor of the adapter or by calling
             <code>setCurlOption($name, $value)</code>. The <code>$name</code> key
             <code>setCurlOption($name, $value)</code>. The <code>$name</code> key
-            corresponds to the CURL_* constants of the cURL extension.
+            corresponds to the CURL_* constants of the cURL extension. You can
+            get access to the Curl handle by calling <code>$adapter->getHandle();</code>
         </para>
         </para>
 
 
         <example id="zend.http.client.adapters.curl.example-2">
         <example id="zend.http.client.adapters.curl.example-2">

+ 10 - 0
library/Zend/Http/Client/Adapter/Curl.php

@@ -389,4 +389,14 @@ class Zend_Http_Client_Adapter_Curl implements Zend_Http_Client_Adapter_Interfac
         $this->_curl         = null;
         $this->_curl         = null;
         $this->_connected_to = array(null, null);
         $this->_connected_to = array(null, null);
     }
     }
+
+    /**
+     * Get cUrl Handle
+     *
+     * @return resource
+     */
+    public function getHandle()
+    {
+        return $this->_curl;
+    }
 }
 }

+ 33 - 0
tests/Zend/Http/Client/CurlTest.php

@@ -163,6 +163,39 @@ class Zend_Http_Client_CurlTest extends Zend_Http_Client_SocketTest
         $adapter = new Zend_Http_Client_Adapter_Curl();
         $adapter = new Zend_Http_Client_Adapter_Curl();
         $adapter->write("GET", "someUri");
         $adapter->write("GET", "someUri");
     }
     }
+
+    public function testSetConfigIsNotArray()
+    {
+        $this->setExpectedException("Zend_Http_Client_Adapter_Exception");
+
+        $adapter = new Zend_Http_Client_Adapter_Curl();
+        $adapter->setConfig("foo");
+    }
+
+    public function testSetCurlOptions()
+    {
+        $adapter = new Zend_Http_Client_Adapter_Curl();
+
+        $adapter->setCurlOption('foo', 'bar')
+                ->setCurlOption('bar', 'baz');
+
+        $this->assertEquals(
+            array('curloptions' => array('foo' => 'bar', 'bar' => 'baz')),
+            $this->readAttribute($adapter, '_config')
+        );
+    }
+
+    /**
+     * @group ZF-7040
+     */
+    public function testGetCurlHandle()
+    {
+        $adapter = new Zend_Http_Client_Adapter_Curl();
+        $adapter->setConfig(array('timeout' => 2, 'maxredirects' => 1));
+        $adapter->connect("http://framework.zend.com");
+
+        $this->assertTrue(is_resource($adapter->getHandle()));
+    }
 }
 }
 
 
 if (PHPUnit_MAIN_METHOD == 'Zend_Http_Client_CurlTest::main') {
 if (PHPUnit_MAIN_METHOD == 'Zend_Http_Client_CurlTest::main') {