Created
November 12, 2019 19:05
-
-
Save gabfr/1f8a878d2b43a9d05b9278c9e50933c7 to your computer and use it in GitHub Desktop.
debug_guzzle_requests.php
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
<?php | |
trait ClientMockTrait | |
{ | |
// [...] | |
public function debugRequest(string $method, string $location, array $options, string $action = '') : void | |
{ | |
// data/logs/3rd_party_requests/request_{time}.log | |
$microtime = microtime(); | |
$requestFilePath = __DIR__ . "/../../../../data/logs/3rdparty_requests/request_{$microtime}.log"; | |
$fileContent = $method . $location . PHP_EOL . PHP_EOL . json_encode($options); | |
// data/logs/3rd_party_requests/request_response_{time}.log | |
file_put_contents($requestFilePath, $fileContent); | |
$response = parent::sendRequest($method, $location, $options, $action); | |
$responsePayload = $method . $location . PHP_EOL . PHP_EOL . json_encode([ | |
'headers' => $response->getHeaders(), | |
'body' => $response->getBody()->getContents(), | |
]); | |
$responseFilePath = __DIR__ . "/../../../../data/logs/3rdparty_requests/request_response_{$microtime}.log"; | |
file_put_contents($responseFilePath, $responsePayload); | |
} | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment