feat: integrate with easy admin bundle

This commit is contained in:
Björn Fromme
2026-03-16 12:02:27 +01:00
parent bdcd54687d
commit 136e2d68a2
10 changed files with 256 additions and 115 deletions
-107
View File
@@ -1,107 +0,0 @@
<?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;
}
try {
$files = $this->findMatchingFiles($requestId, $type);
if (0 === count($files)) {
$io->warning(sprintf('No dump files found for request ID "%s". They may have been cleaned up.', $requestId));
return Command::FAILURE;
}
foreach ($files as $filename) {
if (count($files) > 1) {
$io->section($filename);
}
$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;
}
}
/**
* Finds dump files matching the given request ID and type.
*
* Supports both exact matches (e.g., "abc123_1") and base ID matches (e.g., "abc123")
* which will return all files with counter suffixes.
*
* @return string[]
*
* @throws FilesystemException
*/
private function findMatchingFiles(string $requestId, string $type): array
{
$exactMatch = $requestId.'_'.$type.'.xml';
if ($this->xmlDump->fileExists($exactMatch)) {
return [$exactMatch];
}
$pattern = '/^'.preg_quote($requestId, '/').'_\d+_'.$type.'\.xml$/';
$matches = [];
foreach ($this->xmlDump->listContents('.') as $item) {
if ($item->isFile() && 1 === preg_match($pattern, $item->path())) {
$matches[] = $item->path();
}
}
sort($matches);
return $matches;
}
}