mirror of
https://github.com/php-curl-class/php-curl-class.git
synced 2026-08-30 12:14:36 +00:00
Make Curl::totalTime a deferred property
This commit is contained in:
+17
-2
@@ -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
|
||||
*
|
||||
|
||||
@@ -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));
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user