feat: optional logging of bpn requests/responses for debugging
This commit is contained in:
@@ -45,6 +45,7 @@ APP_BASE_URI=https://myep-team.ddev.site
|
|||||||
APP_BPN_USER=
|
APP_BPN_USER=
|
||||||
APP_BPN_PASSWORD=
|
APP_BPN_PASSWORD=
|
||||||
APP_BPN_ENDPOINT=
|
APP_BPN_ENDPOINT=
|
||||||
|
APP_BPN_DEBUG=false
|
||||||
|
|
||||||
# This hotel code will be assigned to admin users together with ROLE_HOTEL_MANAGER
|
# This hotel code will be assigned to admin users together with ROLE_HOTEL_MANAGER
|
||||||
# in dev and staging environments for testing purposes
|
# in dev and staging environments for testing purposes
|
||||||
|
|||||||
@@ -1,8 +1,4 @@
|
|||||||
parameters:
|
parameters:
|
||||||
bpn_url: '%env(APP_BPN_ENDPOINT)%'
|
|
||||||
bpn_username: '%env(APP_BPN_USER)%'
|
|
||||||
bpn_password: '%env(APP_BPN_PASSWORD)%'
|
|
||||||
|
|
||||||
bpn_crm_id_admin: '%env(int:APP_BPN_CRM_ID_ADMIN)%'
|
bpn_crm_id_admin: '%env(int:APP_BPN_CRM_ID_ADMIN)%'
|
||||||
bpn_crm_id_manager: '%env(int:APP_BPN_CRM_ID_MANAGER)%'
|
bpn_crm_id_manager: '%env(int:APP_BPN_CRM_ID_MANAGER)%'
|
||||||
bpn_crm_id_teamer: '%env(int:APP_BPN_CRM_ID_TEAMER)%'
|
bpn_crm_id_teamer: '%env(int:APP_BPN_CRM_ID_TEAMER)%'
|
||||||
@@ -42,9 +38,10 @@ services:
|
|||||||
arguments:
|
arguments:
|
||||||
$logger: '@monolog.logger.bpn'
|
$logger: '@monolog.logger.bpn'
|
||||||
$options:
|
$options:
|
||||||
bpn_username: '%bpn_username%'
|
bpn_username: '%env(APP_BPN_USER)%'
|
||||||
bpn_password: '%bpn_password%'
|
bpn_password: '%env(APP_BPN_PASSWORD)%'
|
||||||
bpn_url: '%bpn_url%'
|
bpn_url: '%env(APP_BPN_ENDPOINT)%'
|
||||||
|
debug: '%env(bool:APP_BPN_DEBUG)%'
|
||||||
|
|
||||||
App\BusProNet\ResponseParser:
|
App\BusProNet\ResponseParser:
|
||||||
arguments:
|
arguments:
|
||||||
|
|||||||
@@ -10,6 +10,7 @@ use App\Entity\User;
|
|||||||
use Psr\Log\LoggerInterface;
|
use Psr\Log\LoggerInterface;
|
||||||
use Symfony\Component\OptionsResolver\OptionsResolver;
|
use Symfony\Component\OptionsResolver\OptionsResolver;
|
||||||
use Symfony\Component\Serializer\SerializerInterface;
|
use Symfony\Component\Serializer\SerializerInterface;
|
||||||
|
use Symfony\Component\Uid\Uuid;
|
||||||
use Symfony\Contracts\HttpClient\HttpClientInterface;
|
use Symfony\Contracts\HttpClient\HttpClientInterface;
|
||||||
|
|
||||||
class ApiClient
|
class ApiClient
|
||||||
@@ -134,11 +135,20 @@ class ApiClient
|
|||||||
*/
|
*/
|
||||||
private function sendRequest(string $type, array $data): mixed
|
private function sendRequest(string $type, array $data): mixed
|
||||||
{
|
{
|
||||||
|
$requestId = (string) Uuid::v4();
|
||||||
|
|
||||||
$body = $this
|
$body = $this
|
||||||
->serializer
|
->serializer
|
||||||
->serialize($data, 'xml')
|
->serialize($data, 'xml')
|
||||||
;
|
;
|
||||||
|
|
||||||
|
if (true === $this->config['debug']) {
|
||||||
|
$this->logger->info('Request sent', [
|
||||||
|
'id' => $requestId,
|
||||||
|
'request' => $body,
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
$response = $this->httpClient->request('GET', $this->config['bpn_url'], [
|
$response = $this->httpClient->request('GET', $this->config['bpn_url'], [
|
||||||
'query' => [
|
'query' => [
|
||||||
@@ -148,6 +158,13 @@ class ApiClient
|
|||||||
|
|
||||||
$xml = $response->getContent();
|
$xml = $response->getContent();
|
||||||
|
|
||||||
|
if (true === $this->config['debug']) {
|
||||||
|
$this->logger->info('Response received', [
|
||||||
|
'id' => $requestId,
|
||||||
|
'response' => $xml,
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
|
||||||
return $this->responseParser->parseXmlString($type, $xml);
|
return $this->responseParser->parseXmlString($type, $xml);
|
||||||
} catch (\Throwable $e) {
|
} catch (\Throwable $e) {
|
||||||
}
|
}
|
||||||
@@ -167,6 +184,9 @@ class ApiClient
|
|||||||
{
|
{
|
||||||
$optionsResolver = new OptionsResolver();
|
$optionsResolver = new OptionsResolver();
|
||||||
$optionsResolver->setRequired(['bpn_url', 'bpn_username', 'bpn_password']);
|
$optionsResolver->setRequired(['bpn_url', 'bpn_username', 'bpn_password']);
|
||||||
|
$optionsResolver->setDefaults([
|
||||||
|
'debug' => false,
|
||||||
|
]);
|
||||||
|
|
||||||
return $optionsResolver->resolve($options);
|
return $optionsResolver->resolve($options);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user