Skip to content

Commit

Permalink
#87 Fixed CURLFile object serialization for profiling.
Browse files Browse the repository at this point in the history
  • Loading branch information
linslin committed Feb 2, 2021
1 parent ff03c8c commit bfc674f
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 3 deletions.
32 changes: 30 additions & 2 deletions Curl.php
Original file line number Diff line number Diff line change
Expand Up @@ -633,7 +633,7 @@ protected function _httpRequest($method, $raw = false)
//setup error reporting and profiling
if (defined('YII_DEBUG') && YII_DEBUG) {
Yii::debug('Start sending cURL-Request: '.$this->getUrl().'\n', __METHOD__);
Yii::beginProfile($method.' '.$this->_baseUrl.'#'.md5(serialize($this->getOption(CURLOPT_POSTFIELDS))), __METHOD__);
Yii::beginProfile($method.' '.$this->_baseUrl.'#'.md5(serialize($this->_getDebugData())), __METHOD__);
}

/**
Expand Down Expand Up @@ -679,7 +679,7 @@ protected function _httpRequest($method, $raw = false)
//end yii debug profile
if (defined('YII_DEBUG') && YII_DEBUG) {
Yii::debug('End cURL-Request: '.$this->response, __METHOD__);
Yii::endProfile($method.' '.$this->getUrl().'#'.md5(serialize($this->getOption(CURLOPT_POSTFIELDS))), __METHOD__);
Yii::endProfile($method.' '.$this->getUrl().'#'.md5(serialize($this->_getDebugData())), __METHOD__);
}

//check responseCode and return data/status
Expand Down Expand Up @@ -766,4 +766,32 @@ protected function _extractCurlHeaders ($response)

return $headers;
}


/**
* Collects debug data for serialize
* @return array|bool|mixed
*/
private function _getDebugData () {

$data = [];

if (is_array($this->getOption(CURLOPT_POSTFIELDS))) {
foreach ($this->getOption(CURLOPT_POSTFIELDS) as $key => $debugItem) {
if (is_array($debugItem)) {
$data[$key] = $debugItem;
} else if ($debugItem instanceof \CURLFile) {
$data[$key] = [
'name' => $debugItem->name,
'mime' => $debugItem->mime,
'postname' => $debugItem->postname,
];
} // more to come?
}
} else {
$data = $this->getOption(CURLOPT_POSTFIELDS);
}

return $data;
}
}
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ Installation
The preferred way to install this extension is through [composer](http://getcomposer.org/download/).

```bash
php composer.phar require --prefer-dist linslin/yii2-curl "*"
composer require --prefer-dist linslin/yii2-curl "*"
```


Expand Down Expand Up @@ -183,6 +183,7 @@ Testing

- Run codeception tests with `vendor/bin/codecept run` in repository root dir.
On windows run `vendor\bin\codecept.bat run`.
On windows with clover report run `vendor\bin\codecept.bat run --coverage-xml ./../../build/logs/clover.xml`.


Changelog
Expand Down

0 comments on commit bfc674f

Please sign in to comment.