diff --git a/APM/CommandLoggerRegistry.php b/APM/CommandLoggerRegistry.php new file mode 100644 index 00000000..7dde9a4f --- /dev/null +++ b/APM/CommandLoggerRegistry.php @@ -0,0 +1,40 @@ +addLogger($commandLogger); + } + } + + public function register() : void + { + array_map(static function (CommandLoggerInterface $commandLogger) { + $commandLogger->register(); + }, $this->commandLoggers); + } + + public function unregister() : void + { + array_map(static function (CommandLoggerInterface $commandLogger) { + $commandLogger->unregister(); + }, $this->commandLoggers); + } + + private function addLogger(CommandLoggerInterface $logger) : void + { + $this->commandLoggers[] = $logger; + } +} diff --git a/DependencyInjection/DoctrineMongoDBExtension.php b/DependencyInjection/DoctrineMongoDBExtension.php index f9b37626..92f44433 100644 --- a/DependencyInjection/DoctrineMongoDBExtension.php +++ b/DependencyInjection/DoctrineMongoDBExtension.php @@ -214,13 +214,13 @@ protected function loadDocumentManager(array $documentManager, $defaultDM, $defa // logging if ($container->getParameterBag()->resolveValue($documentManager['logging'])) { $logger = $container->getDefinition('doctrine_mongodb.odm.command_logger'); - $logger->addMethodCall('register'); + $logger->addTag('doctrine_mongodb.odm.command_logger'); } // profiler if ($container->getParameterBag()->resolveValue($documentManager['profiler']['enabled'])) { $logger = $container->getDefinition('doctrine_mongodb.odm.data_collector.command_logger'); - $logger->addMethodCall('register'); + $logger->addTag('doctrine_mongodb.odm.command_logger'); $container ->getDefinition('doctrine_mongodb.odm.data_collector') diff --git a/DoctrineMongoDBBundle.php b/DoctrineMongoDBBundle.php index 5640064e..d40f6d52 100644 --- a/DoctrineMongoDBBundle.php +++ b/DoctrineMongoDBBundle.php @@ -55,6 +55,7 @@ public function boot() $registry = $this->container->get('doctrine_mongodb'); $this->registerAutoloader($registry->getManager()); + $this->registerCommandLoggers(); } private function registerAutoloader(DocumentManager $documentManager) : void @@ -69,7 +70,7 @@ private function registerAutoloader(DocumentManager $documentManager) : void spl_autoload_register($this->autoloader); } - public function shutdown() + private function unregisterAutoloader() : void { if ($this->autoloader === null) { return; @@ -78,4 +79,22 @@ public function shutdown() spl_autoload_unregister($this->autoloader); $this->autoloader = null; } + + private function registerCommandLoggers() : void + { + $commandLoggerRegistry = $this->container->get('doctrine_mongodb.odm.command_logger_registry'); + $commandLoggerRegistry->register(); + } + + private function unregisterCommandLoggers() : void + { + $commandLoggerRegistry = $this->container->get('doctrine_mongodb.odm.command_logger_registry'); + $commandLoggerRegistry->unregister(); + } + + public function shutdown() + { + $this->unregisterAutoloader(); + $this->unregisterCommandLoggers(); + } } diff --git a/Resources/config/mongodb.xml b/Resources/config/mongodb.xml index 914ab7ce..af58039c 100644 --- a/Resources/config/mongodb.xml +++ b/Resources/config/mongodb.xml @@ -132,6 +132,10 @@ + + + + diff --git a/Tests/ContainerTest.php b/Tests/ContainerTest.php index d6674bf4..6bfc6d1e 100644 --- a/Tests/ContainerTest.php +++ b/Tests/ContainerTest.php @@ -46,7 +46,7 @@ public function testLoggerConfig(bool $expected, array $config, bool $debug) $this->extension->load([$config], $this->container); $definition = $this->container->getDefinition('doctrine_mongodb.odm.command_logger'); - $this->assertSame($expected, $definition->hasMethodCall('register')); + $this->assertSame($expected, $definition->hasTag('doctrine_mongodb.odm.command_logger')); } public function provideLoggerConfigs() @@ -90,7 +90,7 @@ public function testDataCollectorConfig(bool $expected, array $config, bool $deb $this->extension->load([$config], $this->container); $loggerDefinition = $this->container->getDefinition('doctrine_mongodb.odm.data_collector.command_logger'); - $this->assertSame($expected, $loggerDefinition->hasMethodCall('register')); + $this->assertSame($expected, $loggerDefinition->hasTag('doctrine_mongodb.odm.command_logger')); $dataCollectorDefinition = $this->container->getDefinition('doctrine_mongodb.odm.data_collector'); $this->assertSame($expected, $dataCollectorDefinition->hasTag('data_collector')); diff --git a/Tests/FixtureIntegrationTest.php b/Tests/FixtureIntegrationTest.php index 842c72e7..b4dd8853 100644 --- a/Tests/FixtureIntegrationTest.php +++ b/Tests/FixtureIntegrationTest.php @@ -41,7 +41,7 @@ protected function setUp() public function testFixturesLoader() : void { - $kernel = new IntegrationTestKernel('dev', true); + $kernel = new IntegrationTestKernel('dev', false); $kernel->addServices(static function (ContainerBuilder $c) : void { $c->autowire(OtherFixtures::class) ->addTag(FixturesCompilerPass::FIXTURE_TAG); @@ -74,7 +74,7 @@ public function testFixturesLoaderWhenFixtureHasDependencyThatIsNotYetLoaded() : { // See https://github.com/doctrine/DoctrineFixturesBundle/issues/215 - $kernel = new IntegrationTestKernel('dev', true); + $kernel = new IntegrationTestKernel('dev', false); $kernel->addServices(static function (ContainerBuilder $c) : void { $c->autowire(WithDependenciesFixtures::class) ->addTag(FixturesCompilerPass::FIXTURE_TAG); @@ -116,7 +116,7 @@ public function testExceptionWithDependenciesWithRequiredArguments() : void $this->markTestSkipped(); } - $kernel = new IntegrationTestKernel('dev', true); + $kernel = new IntegrationTestKernel('dev', false); $kernel->addServices(static function (ContainerBuilder $c) { $c->autowire(DependentOnRequiredConstructorArgsFixtures::class) ->addTag(FixturesCompilerPass::FIXTURE_TAG); @@ -147,7 +147,7 @@ public function testExceptionIfDependentFixtureNotWired() : void $this->markTestSkipped(); } - $kernel = new IntegrationTestKernel('dev', true); + $kernel = new IntegrationTestKernel('dev', false); $kernel->addServices(static function (ContainerBuilder $c) : void { $c->autowire(DependentOnRequiredConstructorArgsFixtures::class) ->addTag(FixturesCompilerPass::FIXTURE_TAG); @@ -165,7 +165,7 @@ public function testExceptionIfDependentFixtureNotWired() : void public function testFixturesLoaderWithGroupsOptionViaInterface() : void { - $kernel = new IntegrationTestKernel('dev', true); + $kernel = new IntegrationTestKernel('dev', false); $kernel->addServices(static function (ContainerBuilder $c) : void { // has a "staging" group via the getGroups() method $c->autowire(OtherFixtures::class) @@ -197,7 +197,7 @@ public function testFixturesLoaderWithGroupsOptionViaInterface() : void public function testFixturesLoaderWithGroupsOptionViaTag() : void { - $kernel = new IntegrationTestKernel('dev', true); + $kernel = new IntegrationTestKernel('dev', false); $kernel->addServices(static function (ContainerBuilder $c) : void { // has a "staging" group via the getGroups() method $c->autowire(OtherFixtures::class) @@ -224,7 +224,7 @@ public function testFixturesLoaderWithGroupsOptionViaTag() : void public function testLoadFixturesViaGroupWithMissingDependency() : void { - $kernel = new IntegrationTestKernel('dev', true); + $kernel = new IntegrationTestKernel('dev', false); $kernel->addServices(static function (ContainerBuilder $c) : void { // has a "staging" group via the getGroups() method $c->autowire(OtherFixtures::class) @@ -250,7 +250,7 @@ public function testLoadFixturesViaGroupWithMissingDependency() : void public function testLoadFixturesViaGroupWithFulfilledDependency() : void { - $kernel = new IntegrationTestKernel('dev', true); + $kernel = new IntegrationTestKernel('dev', false); $kernel->addServices(static function (ContainerBuilder $c) : void { // has a "staging" group via the getGroups() method $c->autowire(OtherFixtures::class) @@ -283,7 +283,7 @@ public function testLoadFixturesViaGroupWithFulfilledDependency() : void public function testLoadFixturesByShortName() : void { - $kernel = new IntegrationTestKernel('dev', true); + $kernel = new IntegrationTestKernel('dev', false); $kernel->addServices(static function (ContainerBuilder $c) : void { // has a "staging" group via the getGroups() method $c->autowire(OtherFixtures::class) diff --git a/composer.json b/composer.json index 5e2cfe54..3f796406 100644 --- a/composer.json +++ b/composer.json @@ -13,7 +13,7 @@ "require": { "php": "^7.2", "doctrine/annotations": "^1.2", - "doctrine/mongodb-odm": "^2.0.0-beta1", + "doctrine/mongodb-odm": "^2.0.0-RC1", "psr/log": "^1.0", "symfony/console": "^3.4 || ^4.0", "symfony/dependency-injection": "^3.4 || ^4.0",