diff --git a/src/Command/ReadXmlDumpCommand.php b/src/Command/ReadXmlDumpCommand.php new file mode 100644 index 0000000..b22c0be --- /dev/null +++ b/src/Command/ReadXmlDumpCommand.php @@ -0,0 +1,71 @@ +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; + } + } +}