Skip to content

Commit

Permalink
Merge pull request #555 from stripe/ob-curlfile
Browse files Browse the repository at this point in the history
Remove CURLFile check
  • Loading branch information
ob-stripe authored Nov 15, 2018
2 parents 51b43c3 + 6364a35 commit e85f197
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 24 deletions.
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

0 comments on commit e85f197

Please sign in to comment.