Der gesamte FinTS-Dialog (gesendete und empfangene Meldungen) wird je Durchlauf in bank_protokolle gespeichert, im Erfolgs- wie im Fehlerfall. Im Zahlungsverkehr öffnet der Status das Protokoll der Überweisung als modalen Dialog; unter Online-Banking › Protokoll gibt es das Gesamtprotokoll mit Filter nach Bank, Datum und Freitext. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
63 lines
1.7 KiB
PHP
63 lines
1.7 KiB
PHP
<?php
|
||
|
||
declare(strict_types=1);
|
||
|
||
namespace Finanzmanager\Services;
|
||
|
||
use Psr\Log\AbstractLogger;
|
||
use Stringable;
|
||
|
||
/**
|
||
* Schneidet den FinTS-Dialog für das Übermittlungsprotokoll mit.
|
||
*
|
||
* Die Bibliothek meldet jede gesendete (`>`) und empfangene (`<`) Nachricht an
|
||
* ihren Logger – unabhängig davon, ob das Debug-Log an ist. Dieser Logger
|
||
* sammelt alles im Speicher und reicht es zusätzlich an das Debug-Log weiter.
|
||
* Was ankommt, hat die Bibliothek bereits von PIN und Benutzerkennung befreit
|
||
* (`SanitizingLogger`).
|
||
*/
|
||
class BankProtokollLogger extends AbstractLogger
|
||
{
|
||
/** @var list<string> */
|
||
private array $zeilen = [];
|
||
|
||
private DebugLogAdapter $debug;
|
||
|
||
public function __construct()
|
||
{
|
||
$this->debug = new DebugLogAdapter();
|
||
}
|
||
|
||
/**
|
||
* @param mixed $level
|
||
* @param array<string,mixed> $context
|
||
*/
|
||
public function log($level, string|Stringable $message, array $context = []): void
|
||
{
|
||
$this->debug->log($level, $message, $context);
|
||
|
||
$this->vermerke('[' . (is_scalar($level) ? (string)$level : 'info') . '] ' . (string)$message);
|
||
}
|
||
|
||
/** Eine eigene Zeile (etwa ein Schritt der Anwendung) ins Protokoll. */
|
||
public function vermerke(string $zeile): void
|
||
{
|
||
$this->zeilen[] = date('Y-m-d H:i:s') . ' ' . self::alsUtf8($zeile);
|
||
}
|
||
|
||
public function text(): string
|
||
{
|
||
return implode("\n", $this->zeilen);
|
||
}
|
||
|
||
/**
|
||
* Die Wire-Nachrichten kommen in ISO-8859-1; die Datenbank nimmt nur
|
||
* gültiges UTF-8.
|
||
*/
|
||
private static function alsUtf8(string $text): string
|
||
{
|
||
return mb_check_encoding($text, 'UTF-8')
|
||
? $text
|
||
: mb_convert_encoding($text, 'UTF-8', 'ISO-8859-1');
|
||
}
|
||
}
|