Skip to content

Commit

Permalink
formatting
Browse files Browse the repository at this point in the history
  • Loading branch information
taylorotwell committed Aug 1, 2020
1 parent 21d17fe commit fba984b
Showing 1 changed file with 24 additions and 13 deletions.
37 changes: 24 additions & 13 deletions src/Illuminate/Http/Client/PendingRequest.php
Original file line number Diff line number Diff line change
Expand Up @@ -354,7 +354,7 @@ public function withoutVerifying()
}

/**
* Specify where the body of the response will be saved.
* Specify the path where the body of the response should be stored.
*
* @param $to string|resource
* @return $this
Expand Down Expand Up @@ -702,25 +702,36 @@ public function buildStubHandler()
$sink = $options['sink'] ?? null;

if ($sink) {
$response->then(function ($response) use ($sink) {
$body = $response->getBody()->getContents();

if (is_string($sink)) {
file_put_contents($sink, $body);

return;
}

fwrite($sink, $body);
rewind($sink);
});
$response->then($this->sinkStubHandler($sink));
}

return $response;
};
};
}

/**
* Get the sink stub handler callback.
*
* @param string $sink
* @return \Closure
*/
protected function sinkStubHandler($sink)
{
return function ($response) use ($sink) {
$body = $response->getBody()->getContents();

if (is_string($sink)) {
file_put_contents($sink, $body);

return;
}

fwrite($sink, $body);
rewind($sink);
};
}

/**
* Execute the "before sending" callbacks.
*
Expand Down

0 comments on commit fba984b

Please sign in to comment.