Rename callbacks

This commit is contained in:
Zach Borboa
2018-01-25 20:29:55 -08:00
parent aa74a1cea4
commit 50927dd294
3 changed files with 39 additions and 39 deletions
+2 -2
View File
@@ -29,8 +29,8 @@ $migrations = array(
'response_headers' => 'responseHeaders',
'raw_response_headers' => 'rawResponseHeaders',
'raw_response' => 'rawResponse',
'before_send_function' => 'beforeSendFunction',
'download_complete_function' => 'downloadCompleteFunction',
'before_send_function' => 'beforeSendCallback',
'download_complete_function' => 'downloadCompleteCallback',
);
$directory = new RecursiveDirectoryIterator($cwd);
+18 -18
View File
@@ -33,11 +33,11 @@ class Curl
public $response = null;
public $rawResponse = null;
public $beforeSendFunction = null;
public $downloadCompleteFunction = null;
public $successFunction = null;
public $errorFunction = null;
public $completeFunction = null;
public $beforeSendCallback = null;
public $downloadCompleteCallback = null;
public $successCallback = null;
public $errorCallback = null;
public $completeCallback = null;
public $fileHandle = null;
public $attempts = 0;
@@ -136,7 +136,7 @@ class Curl
*/
public function beforeSend($callback)
{
$this->beforeSendFunction = $callback;
$this->beforeSendCallback = $callback;
}
/**
@@ -230,7 +230,7 @@ class Curl
*/
public function complete($callback)
{
$this->completeFunction = $callback;
$this->completeCallback = $callback;
}
/**
@@ -281,7 +281,7 @@ class Curl
public function download($url, $mixed_filename)
{
if (is_callable($mixed_filename)) {
$this->downloadCompleteFunction = $mixed_filename;
$this->downloadCompleteCallback = $mixed_filename;
$this->fileHandle = tmpfile();
} else {
$filename = $mixed_filename;
@@ -303,7 +303,7 @@ class Curl
$this->fileHandle = fopen($download_filename, $mode);
// Move the downloaded temporary file to the destination save path.
$this->downloadCompleteFunction = function ($instance, $fh) use ($download_filename, $filename) {
$this->downloadCompleteCallback = function ($instance, $fh) use ($download_filename, $filename) {
// Close the open file handle before renaming the file.
if (is_resource($fh)) {
fclose($fh);
@@ -327,7 +327,7 @@ class Curl
*/
public function error($callback)
{
$this->errorFunction = $callback;
$this->errorCallback = $callback;
}
/**
@@ -344,7 +344,7 @@ class Curl
if ($ch === null) {
$this->responseCookies = array();
$this->call($this->beforeSendFunction);
$this->call($this->beforeSendCallback);
$this->rawResponse = curl_exec($this->curl);
$this->curlErrorCode = curl_errno($this->curl);
$this->curlErrorMessage = curl_error($this->curl);
@@ -416,12 +416,12 @@ class Curl
public function execDone()
{
if ($this->error) {
$this->call($this->errorFunction);
$this->call($this->errorCallback);
} else {
$this->call($this->successFunction);
$this->call($this->successCallback);
}
$this->call($this->completeFunction);
$this->call($this->completeCallback);
// Close open file handles and reset the curl instance.
if (!($this->fileHandle === null)) {
@@ -1145,7 +1145,7 @@ class Curl
*/
public function success($callback)
{
$this->successFunction = $callback;
$this->successCallback = $callback;
}
/**
@@ -1321,10 +1321,10 @@ class Curl
*/
private function downloadComplete($fh)
{
if (!$this->error && $this->downloadCompleteFunction) {
if (!$this->error && $this->downloadCompleteCallback) {
rewind($fh);
$this->call($this->downloadCompleteFunction, $fh);
$this->downloadCompleteFunction = null;
$this->call($this->downloadCompleteCallback, $fh);
$this->downloadCompleteCallback = null;
}
if (is_resource($fh)) {
+19 -19
View File
@@ -13,10 +13,10 @@ class MultiCurl
private $concurrency = 25;
private $nextCurlId = 0;
private $beforeSendFunction = null;
private $successFunction = null;
private $errorFunction = null;
private $completeFunction = null;
private $beforeSendCallback = null;
private $successCallback = null;
private $errorCallback = null;
private $completeCallback = null;
private $retry = null;
@@ -82,11 +82,11 @@ class MultiCurl
// Use tmpfile() or php://temp to avoid "Too many open files" error.
if (is_callable($mixed_filename)) {
$callback = $mixed_filename;
$curl->downloadCompleteFunction = $callback;
$curl->downloadCompleteCallback = $callback;
$curl->fileHandle = tmpfile();
} else {
$filename = $mixed_filename;
$curl->downloadCompleteFunction = function ($instance, $fh) use ($filename) {
$curl->downloadCompleteCallback = function ($instance, $fh) use ($filename) {
file_put_contents($filename, stream_get_contents($fh));
};
$curl->fileHandle = fopen('php://temp', 'wb');
@@ -312,7 +312,7 @@ class MultiCurl
*/
public function beforeSend($callback)
{
$this->beforeSendFunction = $callback;
$this->beforeSendCallback = $callback;
}
/**
@@ -339,7 +339,7 @@ class MultiCurl
*/
public function complete($callback)
{
$this->completeFunction = $callback;
$this->completeCallback = $callback;
}
/**
@@ -350,7 +350,7 @@ class MultiCurl
*/
public function error($callback)
{
$this->errorFunction = $callback;
$this->errorCallback = $callback;
}
/**
@@ -725,7 +725,7 @@ class MultiCurl
*/
public function success($callback)
{
$this->successFunction = $callback;
$this->successCallback = $callback;
}
/**
@@ -807,17 +807,17 @@ class MultiCurl
private function initHandle($curl)
{
// Set callbacks if not already individually set.
if ($curl->beforeSendFunction === null) {
$curl->beforeSend($this->beforeSendFunction);
if ($curl->beforeSendCallback === null) {
$curl->beforeSend($this->beforeSendCallback);
}
if ($curl->successFunction === null) {
$curl->success($this->successFunction);
if ($curl->successCallback === null) {
$curl->success($this->successCallback);
}
if ($curl->errorFunction === null) {
$curl->error($this->errorFunction);
if ($curl->errorCallback === null) {
$curl->error($this->errorCallback);
}
if ($curl->completeFunction === null) {
$curl->complete($this->completeFunction);
if ($curl->completeCallback === null) {
$curl->complete($this->completeCallback);
}
$curl->setOpts($this->options);
@@ -837,6 +837,6 @@ class MultiCurl
}
$this->activeCurls[$curl->id] = $curl;
$curl->call($curl->beforeSendFunction);
$curl->call($curl->beforeSendCallback);
}
}