refactor: split buspro ApiClient into domain clients

This commit is contained in:
fromme committed 2026-10-02 13:55:30 +02:00
1 parent 0a55544ca8
commit b755a6f43e
52 files changed
+805 -695

No files matched your search

+11 -10
View File
@@ -5,6 +5,7 @@ namespace App\BusProNet\Transport;
use App\BusProNet\Exception\ApiClientException;
use App\BusProNet\Exception\ImmediateConnectionCloseException;
use App\BusProNet\Exception\ResponseParserException;
use App\BusProNet\MessageType;
use App\BusProNet\XmlParser\ApiResponseParser;
use App\Service\XmlDumpWriter;
use Psr\Log\LoggerInterface;
@@ -42,7 +43,7 @@ class XmlChannel
*
* @throws ApiClientException
*/
public function request(string $type, array $fields = [], array $parserArgs = [], bool $debug = false): mixed
public function request(MessageType $type, array $fields = [], array $parserArgs = [], bool $debug = false): mixed
{
$data = $this->envelope($type, $fields);
@@ -50,10 +51,10 @@ class XmlChannel
$requestId = $this->requestIds->next();
$dump = $debug || true === $this->config['debug'];
$xml = $this->exchange($requestId, $this->serializeXml($data), $type, 'Sending request to BPN API', $dump);
$xml = $this->exchange($requestId, $this->serializeXml($data), $type->value, 'Sending request to BPN API', $dump);
return $this->parseResponse($type, $xml, $parserArgs, $requestId);
}, $type);
}, $type->value);
}
/**
@@ -63,7 +64,7 @@ class XmlChannel
*
* @throws ApiClientException
*/
public function requestRaw(string $type, array $fields = []): string
public function requestRaw(MessageType $type, array $fields = []): string
{
$data = $this->envelope($type, $fields);
@@ -71,7 +72,7 @@ class XmlChannel
$requestId = $this->requestIds->next();
$body = $this->serializeXml($data);
return $this->exchange($requestId, $body, $type, 'Sending raw request to BPN API', true === $this->config['debug']);
return $this->exchange($requestId, $body, $type->value, 'Sending raw request to BPN API', true === $this->config['debug']);
});
}
@@ -93,12 +94,12 @@ class XmlChannel
*
* @return array<string, mixed>
*/
private function envelope(string $type, array $fields): array
private function envelope(MessageType $type, array $fields): array
{
return [
'user' => $this->config['bpn_username'],
'key' => $this->createKey($type),
'satz' => ['@typ' => $type],
'key' => $this->createKey($type->value),
'satz' => ['@typ' => $type->value],
...$fields,
];
}
@@ -205,7 +206,7 @@ class XmlChannel
*
* @throws ApiClientException
*/
private function parseResponse(string $type, string $xml, array $parserArgs, string $requestId, bool $dumpOnFailure = true): mixed
private function parseResponse(MessageType $type, string $xml, array $parserArgs, string $requestId, bool $dumpOnFailure = true): mixed
{
try {
return $this->responseParser->parseXmlString($type, $xml, $parserArgs);
@@ -218,7 +219,7 @@ class XmlChannel
$this->logger->error('Unable to parse response received from API', [
'request_id' => $requestId,
'type' => $type,
'type' => $type->value,
'response_length' => strlen($xml),
'error_message' => $e->getMessage(),
]);