Skip to content

Commit eec60e4

Browse files
authored
Inject the ManagerRegistry into DumpFieldsMapCommand for compatibility with Symfony 6.4 (#927)
1 parent 113a942 commit eec60e4

File tree

3 files changed

+36
-5
lines changed

3 files changed

+36
-5
lines changed

config/command.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@
3030

3131
->set('doctrine_mongodb.odm.command.encryption_dump_fields_map', DumpFieldsMapCommand::class)
3232
->tag('console.command', ['command' => 'doctrine:mongodb:encryption:dump-fields-map'])
33-
->args([tagged_locator('doctrine_mongodb.odm.document_manager', 'name')])
33+
->args([service('doctrine_mongodb')])
3434

3535
->set('doctrine_mongodb.odm.command.create_schema', CreateSchemaDoctrineODMCommand::class)
3636
->tag('console.command', ['command' => 'doctrine:mongodb:schema:create'])

src/Command/Encryption/DumpFieldsMapCommand.php

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
namespace Doctrine\Bundle\MongoDBBundle\Command\Encryption;
66

7+
use Doctrine\Bundle\MongoDBBundle\ManagerRegistry;
78
use Doctrine\ODM\MongoDB\DocumentManager;
89
use Doctrine\ODM\MongoDB\Mapping\ClassMetadata;
910
use MongoDB\BSON\PackedArray;
@@ -14,8 +15,8 @@
1415
use Symfony\Component\Console\Output\OutputInterface;
1516
use Symfony\Component\Console\Style\SymfonyStyle;
1617
use Symfony\Component\Yaml\Dumper;
17-
use Symfony\Contracts\Service\ServiceCollectionInterface;
1818

19+
use function assert;
1920
use function json_decode;
2021
use function json_encode;
2122
use function sprintf;
@@ -34,8 +35,7 @@
3435
)]
3536
final class DumpFieldsMapCommand extends Command
3637
{
37-
/** @param ServiceCollectionInterface<DocumentManager> $documentManagers */
38-
public function __construct(private readonly ServiceCollectionInterface $documentManagers)
38+
public function __construct(private readonly ManagerRegistry $registry)
3939
{
4040
parent::__construct();
4141
}
@@ -60,7 +60,8 @@ protected function execute(InputInterface $input, OutputInterface $output): int
6060

6161
$dumper = new Dumper();
6262

63-
foreach ($this->documentManagers as $name => $documentManager) {
63+
foreach ($this->registry->getManagers() as $name => $documentManager) {
64+
assert($documentManager instanceof DocumentManager);
6465
$encryptedFieldsMap = [];
6566
foreach ($documentManager->getMetadataFactory()->getAllMetadata() as $metadata) {
6667
$database = $documentManager->getDocumentDatabase($metadata->getName());

tests/DependencyInjection/DoctrineMongoDBExtensionTest.php

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@
88
use Composer\InstalledVersions;
99
use Composer\Semver\VersionParser;
1010
use Doctrine\Bundle\MongoDBBundle\Attribute\MapDocument;
11+
use Doctrine\Bundle\MongoDBBundle\Command\Encryption\DiagnosticCommand;
12+
use Doctrine\Bundle\MongoDBBundle\Command\Encryption\DumpFieldsMapCommand;
1113
use Doctrine\Bundle\MongoDBBundle\DependencyInjection\Compiler\ServiceRepositoryCompilerPass;
1214
use Doctrine\Bundle\MongoDBBundle\DependencyInjection\DoctrineMongoDBExtension;
1315
use Doctrine\Bundle\MongoDBBundle\Tests\DependencyInjection\Fixtures\Bundles\DocumentListenerBundle\EventListener\TestAttributeListener;
@@ -487,6 +489,34 @@ public function testUseTransactionalFlush(): void
487489
);
488490
}
489491

492+
public function testEncryptionCommands(): void
493+
{
494+
self::requireAutoEncryptionSupportInODM();
495+
496+
$container = $this->buildMinimalContainer();
497+
$loader = new DoctrineMongoDBExtension();
498+
499+
$config = [
500+
'connections' => [
501+
'default' => [
502+
'autoEncryption' => [
503+
'kmsProvider' => ['type' => 'local', 'key' => 'base64_encoded_key'],
504+
],
505+
],
506+
],
507+
'document_managers' => ['default' => []],
508+
];
509+
510+
$loader->load([$config], $container);
511+
(new ServiceRepositoryCompilerPass())->process($container);
512+
513+
$dumpFieldsMapCommand = $container->get('doctrine_mongodb.odm.command.encryption_dump_fields_map');
514+
$this->assertInstanceOf(DumpFieldsMapCommand::class, $dumpFieldsMapCommand);
515+
516+
$diagnosticCommand = $container->get('doctrine_mongodb.odm.command.encryption_diagnostic');
517+
$this->assertInstanceOf(DiagnosticCommand::class, $diagnosticCommand);
518+
}
519+
490520
public function testAutoEncryptionWithKeyVaultClientService(): void
491521
{
492522
self::requireAutoEncryptionSupportInODM();

0 commit comments

Comments
 (0)