Make Curl::totalTime a deferred property

This commit is contained in:
Zach Borboa
2016-07-11 00:17:11 -07:00
parent 975dfa3b89
commit b24b575e58
2 changed files with 24 additions and 2 deletions
+17 -2
View File
@@ -56,7 +56,6 @@ class Curl
public $httpStatusCode = 0;
public $httpErrorMessage = null;
public $totalTime = 0;
public $baseUrl = null;
public $url = null;
public $effectiveUrl = null;
@@ -82,6 +81,10 @@ class Curl
private $xmlDecoder = null;
private $xmlPattern = '~^(?:text/|application/(?:atom\+|rss\+)?)xml~i';
private static $deferredProperties = array(
'totalTime',
);
/**
* Construct
*
@@ -348,7 +351,6 @@ class Curl
$this->curlErrorMessage = curl_error($this->curl);
$this->curlError = !($this->curlErrorCode === 0);
$this->httpStatusCode = curl_getinfo($this->curl, CURLINFO_HTTP_CODE);
$this->totalTime = curl_getinfo($this->curl, CURLINFO_TOTAL_TIME);
$this->httpError = in_array(floor($this->httpStatusCode / 100), array(4, 5));
$this->error = $this->curlError || $this->httpError;
$this->errorCode = $this->error ? ($this->curlError ? $this->curlErrorCode : $this->httpStatusCode) : 0;
@@ -953,6 +955,19 @@ class Curl
$this->close();
}
public function __get($name)
{
$return = null;
if (in_array($name, self::$deferredProperties) && is_callable(array($this, $getter = '__get_' . $name))) {
$return = $this->$name = $this->$getter();
}
return $return;
}
private function __get_totalTime() {
return curl_getinfo($this->curl, CURLINFO_TOTAL_TIME);
}
/**
* Build Url
*
+7
View File
@@ -2650,4 +2650,11 @@ class CurlTest extends PHPUnit_Framework_TestCase
$test->server('xml_with_cdata_response', 'POST', $data);
$this->assertTrue(strpos($test->curl->response->saveXML(), '<![CDATA[') === false);
}
public function testTotalTime()
{
$test = new Test();
$test->server('request_method', 'GET');
$this->assertTrue(is_float($test->curl->totalTime));
}
}