feat: command to read xml-dumps from bpn api by provided request id
This commit is contained in:
@@ -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;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user