const STATUS_WRITE_ERROR = 'write-error';
const STATUS_DL_ERROR = 'dl-error';
+ /**
+ * @var CRM_Utils_HttpClient
+ */
+ protected static $singleton;
+
+ public static function singleton() {
+ if (!self::$singleton) {
+ self::$singleton = new CRM_Utils_HttpClient();
+ }
+ return self::$singleton;
+ }
+
/**
* Download the remote zipfile.
*
* @param string $localFile path at which to store the .zip file
* @return STATUS_OK|STATUS_WRITE_ERROR|STATUS_DL_ERROR
*/
- public static function fetch($remoteFile, $localFile) {
+ public function fetch($remoteFile, $localFile) {
require_once 'CA/Config/Curl.php';
$caConfig = CA_Config_Curl::probe(array(
'verify_peer' => (bool) CRM_Core_BAO_Setting::getItem(CRM_Core_BAO_Setting::SYSTEM_PREFERENCES_NAME, 'verifySSL', NULL, TRUE)
*/
protected $tmpFile;
+ /**
+ * @var CRM_Utils_HttpClient
+ */
+ protected $client;
+
public function setUp() {
parent::setUp();
'verifySSL' => TRUE,
));
$this->assertAPISuccess($result);
+ $this->client = new CRM_Utils_HttpClient();
}
public function tearDown() {
}
function testFetchHttp() {
- $result = CRM_Utils_HttpClient::fetch(self::VALID_HTTP_URL, $this->tmpFile);
+ $result = $this->client->fetch(self::VALID_HTTP_URL, $this->tmpFile);
$this->assertEquals(CRM_Utils_HttpClient::STATUS_OK, $result);
$this->assertRegExp(self::VALID_HTTP_REGEX, file_get_contents($this->tmpFile));
}
function testFetchHttps_valid() {
- $result = CRM_Utils_HttpClient::fetch(self::VALID_HTTPS_URL, $this->tmpFile);
+ $result = $this->client->fetch(self::VALID_HTTPS_URL, $this->tmpFile);
$this->assertEquals(CRM_Utils_HttpClient::STATUS_OK, $result);
$this->assertRegExp(self::VALID_HTTPS_REGEX, file_get_contents($this->tmpFile));
}
function testFetchHttps_invalid_verify() {
- $result = CRM_Utils_HttpClient::fetch(self::SELF_SIGNED_HTTPS_URL, $this->tmpFile);
+ $result = $this->client->fetch(self::SELF_SIGNED_HTTPS_URL, $this->tmpFile);
$this->assertEquals(CRM_Utils_HttpClient::STATUS_DL_ERROR, $result);
$this->assertEquals('', file_get_contents($this->tmpFile));
}
));
$this->assertAPISuccess($result);
- $result = CRM_Utils_HttpClient::fetch(self::SELF_SIGNED_HTTPS_URL, $this->tmpFile);
+ $result = $this->client->fetch(self::SELF_SIGNED_HTTPS_URL, $this->tmpFile);
$this->assertEquals(CRM_Utils_HttpClient::STATUS_OK, $result);
$this->assertRegExp(self::SELF_SIGNED_HTTPS_REGEX, file_get_contents($this->tmpFile));
}
function testFetchHttp_badOutFile() {
- $result = CRM_Utils_HttpClient::fetch(self::VALID_HTTP_URL, '/ba/d/path/too/utput');
+ $result = $this->client->fetch(self::VALID_HTTP_URL, '/ba/d/path/too/utput');
$this->assertEquals(CRM_Utils_HttpClient::STATUS_WRITE_ERROR, $result);
}