Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove CURLFile check #555

Merged
merged 1 commit into from
Nov 15, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 5 additions & 11 deletions lib/ApiRequestor.php
Original file line number Diff line number Diff line change
Expand Up @@ -333,12 +333,11 @@ private function _requestRaw($method, $url, $params, $headers)
}

$hasFile = false;
$hasCurlFile = class_exists('\CURLFile', false);
foreach ($params as $k => $v) {
if (is_resource($v)) {
$hasFile = true;
$params[$k] = self::_processResourceParam($v, $hasCurlFile);
} elseif ($hasCurlFile && $v instanceof \CURLFile) {
$params[$k] = self::_processResourceParam($v);
} elseif ($v instanceof \CURLFile) {
$hasFile = true;
}
}
Expand Down Expand Up @@ -368,12 +367,11 @@ private function _requestRaw($method, $url, $params, $headers)

/**
* @param resource $resource
* @param bool $hasCurlFile
*
* @return \CURLFile|string
* @throws Error\Api
*/
private function _processResourceParam($resource, $hasCurlFile)
private function _processResourceParam($resource)
{
if (get_resource_type($resource) !== 'stream') {
throw new Error\Api(
Expand All @@ -388,12 +386,8 @@ private function _processResourceParam($resource, $hasCurlFile)
);
}

if ($hasCurlFile) {
// We don't have the filename or mimetype, but the API doesn't care
return new \CURLFile($metaData['uri']);
} else {
return '@'.$metaData['uri'];
}
// We don't have the filename or mimetype, but the API doesn't care
return new \CURLFile($metaData['uri']);
}

/**
Expand Down
2 changes: 1 addition & 1 deletion lib/HttpClient/ClientInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ interface ClientInterface
* @param array $headers Headers to be used in the request (full strings, not KV pairs)
* @param array $params KV pairs for parameters. Can be nested for arrays and hashes
* @param boolean $hasFile Whether or not $params references a file (via an @ prefix or
* CurlFile)
* CURLFile)
*
* @throws \Stripe\Error\Api
* @throws \Stripe\Error\ApiConnection
Expand Down
9 changes: 2 additions & 7 deletions tests/Stripe/FileCreationTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,13 +44,8 @@ public function testIsCreatableWithFileHandle()
$this->assertInstanceOf("Stripe\\File", $resource);
}

public function testIsCreatableWithCurlFile()
public function testIsCreatableWithCURLFile()
{
if (!class_exists('\CurlFile', false)) {
// Older PHP versions don't support this
return;
}

$this->expectsRequest(
'post',
'/v1/files',
Expand All @@ -59,7 +54,7 @@ public function testIsCreatableWithCurlFile()
true,
Stripe::$apiUploadBase
);
$curlFile = new \CurlFile(dirname(__FILE__) . '/../data/test.png');
$curlFile = new \CURLFile(dirname(__FILE__) . '/../data/test.png');
$resource = File::create([
"purpose" => "dispute_evidence",
"file" => $curlFile,
Expand Down
5 changes: 0 additions & 5 deletions tests/Stripe/FileUploadCreationTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,11 +46,6 @@ public function testIsCreatableWithFileHandle()

public function testIsCreatableWithCurlFile()
{
if (!class_exists('\CurlFile', false)) {
// Older PHP versions don't support this
return;
}

$this->expectsRequest(
'post',
'/v1/files',
Expand Down