Skip to content

Commit

Permalink
refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
taylorotwell committed Oct 30, 2023
1 parent e822c1d commit 88ce284
Showing 1 changed file with 21 additions and 12 deletions.
33 changes: 21 additions & 12 deletions src/Illuminate/Http/Client/PendingRequest.php
Original file line number Diff line number Diff line change
Expand Up @@ -1036,20 +1036,10 @@ protected function sendRequest(string $method, string $url, array $options = [])
$this->transferStats = $transferStats;
};

$mergedOptions = $this->mergeOptions([
$mergedOptions = $this->normalizeRequestOptions($this->mergeOptions([
'laravel_data' => $laravelData,
'on_stats' => $onStats,
], $options);

$mergedOptions = array_map(function($mergedOption) {
if ( is_array( $mergedOption ) ) {
array_walk_recursive($mergedOption, function (&$value) {
$value = $value instanceof Stringable ? $value->toString() : $value;
});
}

return $mergedOption instanceof Stringable ? $mergedOption->toString() : $mergedOption;
}, $mergedOptions);
], $options));

return $this->buildClient()->$clientMethod($method, $url, $mergedOptions);
}
Expand Down Expand Up @@ -1089,6 +1079,25 @@ protected function parseRequestData($method, $url, array $options)
return is_array($laravelData) ? $laravelData : [];
}

/**
* Normalize the given request options.
*
* @param array $options
* @return array
*/
protected function normalizeRequestOptions(array $options)
{
foreach ($options as $key => $value) {
$options[$key] = match (true) {
is_array($value) => $this->normalizeRequestOptions($value),
$value instanceof Stringable => $value->toString(),
default => $value,
};
}

return $options;
}

/**
* Populate the given response with additional data.
*
Expand Down

0 comments on commit 88ce284

Please sign in to comment.