Skip to content

Commit b4d1412

Browse files
committed
Add json format to the dump command
1 parent cb4093e commit b4d1412

File tree

1 file changed

+17
-1
lines changed

1 file changed

+17
-1
lines changed

src/Command/DumpEncryptedFieldsMapCommand.php

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,15 @@
2020
use function array_keys;
2121
use function array_map;
2222
use function array_values;
23+
use function json_encode;
2324
use function sprintf;
2425
use function var_export;
2526

27+
use const JSON_PRETTY_PRINT;
28+
use const JSON_THROW_ON_ERROR;
29+
use const JSON_UNESCAPED_SLASHES;
30+
use const JSON_UNESCAPED_UNICODE;
31+
2632
/** @internal */
2733
#[AsCommand(
2834
name: 'doctrine:mongodb:dump-encrypted-fields-map',
@@ -38,7 +44,14 @@ public function __construct(private readonly ServiceCollectionInterface $documen
3844

3945
protected function configure(): void
4046
{
41-
$this->addOption('format', 'f', InputOption::VALUE_REQUIRED, 'The output format for the encrypted fields map (yaml, php)', 'yaml');
47+
$this->addOption(
48+
'format',
49+
'f',
50+
InputOption::VALUE_REQUIRED,
51+
'The output format for the encrypted fields map (yaml, php)',
52+
'yaml',
53+
['yaml', 'php', 'json']
54+
);
4255
}
4356

4457
protected function execute(InputInterface $input, OutputInterface $output): int
@@ -77,6 +90,9 @@ protected function execute(InputInterface $input, OutputInterface $output): int
7790
case 'php':
7891
$outputContent = var_export($encryptedFieldsMap, true);
7992
break;
93+
case 'json':
94+
$outputContent = json_encode($encryptedFieldsMap, JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE | JSON_THROW_ON_ERROR);
95+
break;
8096
default:
8197
$io->error(sprintf('Unknown format "%s"', $format));
8298

0 commit comments

Comments
 (0)