-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
1c03420
commit 8af27a8
Showing
4 changed files
with
67 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
<?php | ||
|
||
namespace Flavorly\LaravelHelpers\Helpers\Saloon; | ||
|
||
use GuzzleHttp\TransferStats; | ||
use Saloon\Http\PendingRequest; | ||
|
||
trait RecordsRequestAndResponses | ||
{ | ||
/** | ||
* Little debug help to see the request and response pairs to Ray | ||
*/ | ||
public function bootRecordsRequestAndResponses(PendingRequest $pendingRequest): void | ||
{ | ||
if (app()->hasDebugModeEnabled() && config('laravel-helpers.debug-requests', true)) { | ||
$this->middleware()->onRequest(new RequestRecorder); | ||
$this->middleware()->onResponse(new ResponseRecorder); | ||
$this->config()->set([ | ||
'on_stats' => function (TransferStats $stats) { | ||
// @codeCoverageIgnoreStart | ||
ray('[Guzzle Request ]', $stats->getRequest()); | ||
ray('[Guzzle Response ]', $stats->getResponse()); | ||
ray('[Guzzle Response Body ]', (string) $stats->getResponse()?->getBody()); | ||
// @codeCoverageIgnoreEnd | ||
}, | ||
]); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
<?php | ||
|
||
namespace Flavorly\LaravelHelpers\Helpers\Saloon; | ||
|
||
use Saloon\Contracts\RequestMiddleware; | ||
use Saloon\Http\PendingRequest; | ||
|
||
class RequestRecorder implements RequestMiddleware | ||
{ | ||
public function __invoke(PendingRequest $pendingRequest): void | ||
{ | ||
ray('Dispatching Request', $pendingRequest); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
<?php | ||
|
||
namespace Flavorly\LaravelHelpers\Helpers\Saloon; | ||
|
||
use Saloon\Contracts\ResponseMiddleware; | ||
use Saloon\Http\Response; | ||
|
||
class ResponseRecorder implements ResponseMiddleware | ||
{ | ||
public function __invoke(Response $response): void | ||
{ | ||
ray('Response Received', $response); | ||
} | ||
} |