feat: command to read xml-dumps from bpn api by provided request id

This commit is contained in:
Björn Fromme
2026-01-08 14:23:22 +01:00
parent 97a5d7f9f1
commit e4a1a992be
+71
View File
@@ -0,0 +1,71 @@
<?php
declare(strict_types=1);
namespace App\Command;
use League\Flysystem\FilesystemException;
use League\Flysystem\FilesystemOperator;
use Symfony\Component\Console\Attribute\AsCommand;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\InputArgument;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Input\InputOption;
use Symfony\Component\Console\Output\OutputInterface;
use Symfony\Component\Console\Style\SymfonyStyle;
#[AsCommand(
name: 'app:bpn:read-dump',
description: 'Read XML request or response dump for a given request ID'
)]
class ReadXmlDumpCommand extends Command
{
public function __construct(
private readonly FilesystemOperator $xmlDump,
) {
parent::__construct();
}
protected function configure(): void
{
$this
->addArgument('requestId', InputArgument::REQUIRED, 'The request ID to look up')
->addOption('type', 't', InputOption::VALUE_REQUIRED, 'Dump type: request or response', 'request');
}
/**
* @see \Symfony\Component\Console\Command\Command::execute()
*/
protected function execute(InputInterface $input, OutputInterface $output): int
{
$io = new SymfonyStyle($input, $output);
$requestId = $input->getArgument('requestId');
$type = $input->getOption('type');
if (false === in_array($type, ['request', 'response'], true)) {
$io->error('Invalid type. Must be "request" or "response".');
return Command::FAILURE;
}
$filename = $requestId.'_'.$type.'.xml';
try {
if (false === $this->xmlDump->fileExists($filename)) {
$io->warning(sprintf('Dump file "%s" not found. It may have been cleaned up.', $filename));
return Command::FAILURE;
}
$content = $this->xmlDump->read($filename);
$output->writeln($content);
return Command::SUCCESS;
} catch (FilesystemException $e) {
$io->error(sprintf('Failed to read dump file: %s', $e->getMessage()));
return Command::FAILURE;
}
}
}