对cURL库的1-1类映射,以便可以进行模拟/存根化

v1.0 2016-03-04 11:26 UTC

This package is auto-updated.

Last update: 2024-09-23 09:52:56 UTC


README

对cURL库的1-1类映射,以便可以进行模拟/存根化

有时,你只想使用cURL而不是像guzzle这样的抽象类。这是一个简单的cURL包装器,这样你就可以做到这一点,并且仍然可以编写有意义的测试。

用法

class SomeClassThatUsesCurl {


   protected $curl;

   public function __construct(WillWashburn\Curl $curl) {
   
       $this->curl = $curl;
   
   }
   
   public function someMethodThatMakesARequest() {
   
       // Use curl like normal but also be able to test!
       $ch = $this->curl->curl_init($url);
       $this->curl->curl_setopt($ch, CURLOPT_HEADER, true);
   
   }


}

安装

使用composer

composer require willwashburn/curl

或者,将"willwashburn/curl": "1.0"添加到你的composer.json中