[HttpClient] In StreamWrapper::createResource
use the more efficient Response::toStream
method if safe and available
This commit is contained in:
parent
e9f0cfe9db
commit
e2c2397f1e
@ -49,6 +49,14 @@ class StreamWrapper
|
||||
*/
|
||||
public static function createResource(ResponseInterface $response, HttpClientInterface $client = null)
|
||||
{
|
||||
if (null === $client && \is_callable([$response, 'toStream']) && isset(class_uses($response)[ResponseTrait::class])) {
|
||||
$stack = debug_backtrace(DEBUG_BACKTRACE_PROVIDE_OBJECT | DEBUG_BACKTRACE_IGNORE_ARGS, 2);
|
||||
|
||||
if ($response !== ($stack[1]['object'] ?? null)) {
|
||||
return $response->toStream(false);
|
||||
}
|
||||
}
|
||||
|
||||
if (null === $client && !method_exists($response, 'stream')) {
|
||||
throw new \InvalidArgumentException(sprintf('Providing a client to "%s()" is required when the response doesn\'t have any "stream()" method.', __CLASS__));
|
||||
}
|
||||
|
Reference in New Issue
Block a user