Skip to content

Commit d69714f

Browse files
authored
[php] Fix file uploads by backporting #21458 (#21632)
* [php] Backport #21458 to php client Fixes #21485 Credits to @jozefbriss * [php] Fix deprecation warning when running integration tests OpenAPI\Client\FakeHttpClient::setResponse(): Implicitly marking parameter $response as nullable is deprecated, the explicit nullable type must be used instead --------- Co-authored-by: simonhammes <[email protected]>
1 parent 7d3913f commit d69714f

File tree

4 files changed

+16
-4
lines changed

4 files changed

+16
-4
lines changed

modules/openapi-generator/src/main/resources/php/FormDataProcessor.mustache

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,11 @@ class FormDataProcessor
113113
$currentName .= $currentSuffix;
114114
}
115115

116-
$result[$currentName] = ObjectSerializer::toString($val);
116+
if (is_resource($val)) {
117+
$result[$currentName] = $val;
118+
} else {
119+
$result[$currentName] = ObjectSerializer::toString($val);
120+
}
117121
}
118122

119123
$currentName = $start;

samples/client/petstore/php/OpenAPIClient-php/lib/FormDataProcessor.php

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,11 @@ public static function flatten(array $source, string $start = ''): array
121121
$currentName .= $currentSuffix;
122122
}
123123

124-
$result[$currentName] = ObjectSerializer::toString($val);
124+
if (is_resource($val)) {
125+
$result[$currentName] = $val;
126+
} else {
127+
$result[$currentName] = ObjectSerializer::toString($val);
128+
}
125129
}
126130

127131
$currentName = $start;

samples/client/petstore/php/OpenAPIClient-php/tests/FakeHttpClient.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ public function getLastRequest()
2727
/**
2828
* @param null|ResponseInterface $response
2929
*/
30-
public function setResponse(ResponseInterface $response = null)
30+
public function setResponse(?ResponseInterface $response = null)
3131
{
3232
$this->response = $response;
3333
}

samples/client/petstore/php/psr-18/lib/FormDataProcessor.php

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,11 @@ public static function flatten(array $source, string $start = ''): array
121121
$currentName .= $currentSuffix;
122122
}
123123

124-
$result[$currentName] = ObjectSerializer::toString($val);
124+
if (is_resource($val)) {
125+
$result[$currentName] = $val;
126+
} else {
127+
$result[$currentName] = ObjectSerializer::toString($val);
128+
}
125129
}
126130

127131
$currentName = $start;

0 commit comments

Comments
 (0)