Skip to content

Commit

Permalink
Remove unused and .class parameters
Browse files Browse the repository at this point in the history
  • Loading branch information
franmomu committed Dec 13, 2023
1 parent 62b1ab9 commit 187fc88
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 39 deletions.
12 changes: 7 additions & 5 deletions DependencyInjection/DoctrineMongoDBExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,10 @@
use Doctrine\Common\Cache\RedisCache;
use Doctrine\Common\DataFixtures\Loader as DataFixturesLoader;
use Doctrine\Common\EventSubscriber;
use Doctrine\ODM\MongoDB\Configuration as MongoDBConfiguration;
use Doctrine\ODM\MongoDB\DocumentManager;
use InvalidArgumentException;
use MongoDB\Client;
use Symfony\Bridge\Doctrine\DependencyInjection\AbstractDoctrineExtension;
use Symfony\Bridge\Doctrine\Messenger\DoctrineClearEntityManagerWorkerSubscriber;
use Symfony\Component\Cache\Adapter\ApcuAdapter;
Expand Down Expand Up @@ -229,7 +231,7 @@ protected function loadDocumentManager(array $documentManager, $defaultDM, $defa
$configurationId = sprintf('doctrine_mongodb.odm.%s_configuration', $documentManager['name']);
$defaultDatabase = $documentManager['database'] ?? $defaultDB;

$odmConfigDef = new Definition('%doctrine_mongodb.odm.configuration.class%');
$odmConfigDef = new Definition(MongoDBConfiguration::class);
$odmConfigDef->addTag(self::CONFIGURATION_TAG);
$container->setDefinition(
$configurationId,
Expand Down Expand Up @@ -318,8 +320,8 @@ protected function loadDocumentManager(array $documentManager, $defaultDM, $defa
// Document managers will share their connection's event manager
new Reference(sprintf('doctrine_mongodb.odm.%s_connection.event_manager', $connectionName)),
];
$odmDmDef = new Definition('%doctrine_mongodb.odm.document_manager.class%', $odmDmArgs);
$odmDmDef->setFactory(['%doctrine_mongodb.odm.document_manager.class%', 'create']);
$odmDmDef = new Definition(DocumentManager::class, $odmDmArgs);
$odmDmDef->setFactory([DocumentManager::class, 'create']);
$odmDmDef->addTag('doctrine_mongodb.odm.document_manager');
$odmDmDef->setPublic(true);

Expand Down Expand Up @@ -363,7 +365,7 @@ protected function loadConnections(array $connections, ContainerBuilder $contain
$configurationId = sprintf('doctrine_mongodb.odm.%s_configuration', $name);
$container->setDefinition(
$configurationId,
new Definition('%doctrine_mongodb.odm.configuration.class%'),
new Definition(MongoDBConfiguration::class),
);

$odmConnArgs = [
Expand All @@ -373,7 +375,7 @@ protected function loadConnections(array $connections, ContainerBuilder $contain
$this->normalizeDriverOptions($connection),
];

$odmConnDef = new Definition('%doctrine_mongodb.odm.connection.class%', $odmConnArgs);
$odmConnDef = new Definition(Client::class, $odmConnArgs);
$odmConnDef->setPublic(true);
$id = sprintf('doctrine_mongodb.odm.%s_connection', $name);
$container->setDefinition($id, $odmConnDef);
Expand Down
15 changes: 2 additions & 13 deletions Resources/config/mongodb.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,10 @@
use Doctrine\Bundle\MongoDBBundle\ManagerRegistry;
use Doctrine\Bundle\MongoDBBundle\Mapping\Driver\XmlDriver;
use Doctrine\Bundle\MongoDBBundle\Repository\ContainerRepositoryFactory;
use Doctrine\ODM\MongoDB\Configuration;
use Doctrine\ODM\MongoDB\DocumentManager;
use Doctrine\ODM\MongoDB\Mapping\Driver\AttributeDriver;
use Doctrine\ODM\MongoDB\Tools\ResolveTargetDocumentListener;
use Doctrine\Persistence\Mapping\Driver\MappingDriverChain;
use MongoDB\Client;
use ProxyManager\Proxy\GhostObjectInterface;
use Symfony\Bridge\Doctrine\ContainerAwareEventManager;
use Symfony\Bridge\Doctrine\Security\User\EntityUserProvider;
Expand All @@ -31,18 +29,9 @@
->set('doctrine_mongodb.odm.cache.memcache_port', 11211)
->set('doctrine_mongodb.odm.cache.memcache_instance.class', 'Memcache')
->set('doctrine_mongodb.odm.cache.xcache.class', 'Doctrine\Common\Cache\XcacheCache')
->set('doctrine_mongodb.odm.connection.class', Client::class)
->set('doctrine_mongodb.odm.configuration.class', Configuration::class)
->set('doctrine_mongodb.odm.document_manager.class', DocumentManager::class)
->set('doctrine_mongodb.odm.manager_configurator.class', ManagerConfigurator::class)
->set('doctrine_mongodb.odm.class', ManagerRegistry::class)
->set('doctrine_mongodb.odm.metadata.driver_chain.class', MappingDriverChain::class)
->set('doctrine_mongodb.odm.metadata.attribute.class', AttributeDriver::class)
->set('doctrine_mongodb.odm.metadata.xml.class', XmlDriver::class)
->set('doctrine_mongodb.odm.mapping_dirs', [])
->set('doctrine_mongodb.odm.xml_mapping_dirs', '%doctrine_mongodb.odm.mapping_dirs%')
->set('doctrine_mongodb.odm.document_dirs', [])
->set('doctrine_mongodb.odm.fixtures_dirs', []);
->set('doctrine_mongodb.odm.metadata.xml.class', XmlDriver::class);

$containerConfigurator->services()

Expand Down Expand Up @@ -73,7 +62,7 @@
service('doctrine_mongodb'),
])

->set('doctrine_mongodb', '%doctrine_mongodb.odm.class%')
->set('doctrine_mongodb', ManagerRegistry::class)
->public()
->args([
'MongoDB',
Expand Down
39 changes: 18 additions & 21 deletions Tests/DependencyInjection/AbstractMongoDBExtensionTestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -49,9 +49,6 @@ public function testDependencyInjectionConfigurationDefaults(): void

$loader->load(DoctrineMongoDBExtensionTest::buildConfiguration(), $container);

$this->assertEquals(Client::class, $container->getParameter('doctrine_mongodb.odm.connection.class'));
$this->assertEquals(Configuration::class, $container->getParameter('doctrine_mongodb.odm.configuration.class'));
$this->assertEquals(DocumentManager::class, $container->getParameter('doctrine_mongodb.odm.document_manager.class'));
$this->assertEquals('MongoDBODMProxies', $container->getParameter('doctrine_mongodb.odm.proxy_namespace'));
$this->assertEquals(Configuration::AUTOGENERATE_EVAL, $container->getParameter('doctrine_mongodb.odm.auto_generate_proxy_classes'));
$this->assertEquals(ArrayCache::class, $container->getParameter('doctrine_mongodb.odm.cache.array.class'));
Expand All @@ -77,7 +74,7 @@ public function testDependencyInjectionConfigurationDefaults(): void
$this->assertEquals(true, $container->getParameter('doctrine_mongodb.odm.auto_generate_proxy_classes'));

$definition = $container->getDefinition('doctrine_mongodb.odm.default_connection');
$this->assertEquals('%doctrine_mongodb.odm.connection.class%', $definition->getClass());
$this->assertEquals(Client::class, $definition->getClass());

$arguments = $definition->getArguments();
$this->assertEquals(null, $arguments[0]);
Expand All @@ -86,8 +83,8 @@ public function testDependencyInjectionConfigurationDefaults(): void
$this->assertSame(['root' => 'array', 'document' => 'array'], $arguments[2]['typeMap']);

$definition = $container->getDefinition('doctrine_mongodb.odm.default_document_manager');
$this->assertEquals('%doctrine_mongodb.odm.document_manager.class%', $definition->getClass());
$this->assertEquals(['%doctrine_mongodb.odm.document_manager.class%', 'create'], $definition->getFactory());
$this->assertEquals(DocumentManager::class, $definition->getClass());
$this->assertEquals([DocumentManager::class, 'create'], $definition->getFactory());
$this->assertArrayHasKey('doctrine_mongodb.odm.document_manager', $definition->getTags());

$arguments = $definition->getArguments();
Expand Down Expand Up @@ -115,7 +112,7 @@ public function testSingleDocumentManagerConfiguration(): void
$loader->load([$config], $container);

$definition = $container->getDefinition('doctrine_mongodb.odm.default_connection');
$this->assertEquals('%doctrine_mongodb.odm.connection.class%', $definition->getClass());
$this->assertEquals(Client::class, $definition->getClass());

$arguments = $definition->getArguments();
$this->assertEquals('mongodb://localhost:27017', $arguments[0]);
Expand All @@ -126,8 +123,8 @@ public function testSingleDocumentManagerConfiguration(): void
$this->assertEquals(new Reference('my_context'), $arguments[2]['context']);

$definition = $container->getDefinition('doctrine_mongodb.odm.default_document_manager');
$this->assertEquals('%doctrine_mongodb.odm.document_manager.class%', $definition->getClass());
$this->assertEquals(['%doctrine_mongodb.odm.document_manager.class%', 'create'], $definition->getFactory());
$this->assertEquals(DocumentManager::class, $definition->getClass());
$this->assertEquals([DocumentManager::class, 'create'], $definition->getFactory());
$this->assertArrayHasKey('doctrine_mongodb.odm.document_manager', $definition->getTags());

$arguments = $definition->getArguments();
Expand All @@ -150,7 +147,7 @@ public function testLoadSimpleSingleConnection(): void
$container->compile();

$definition = $container->getDefinition('doctrine_mongodb.odm.default_connection');
$this->assertEquals('%doctrine_mongodb.odm.connection.class%', $definition->getClass());
$this->assertEquals(Client::class, $definition->getClass());

$arguments = $definition->getArguments();
$this->assertEquals('mongodb://localhost:27017', $arguments[0]);
Expand All @@ -165,8 +162,8 @@ public function testLoadSimpleSingleConnection(): void
$this->assertEquals('mydb', $methodCalls[$pos][1][0]);

$definition = $container->getDefinition('doctrine_mongodb.odm.default_document_manager');
$this->assertEquals('%doctrine_mongodb.odm.document_manager.class%', $definition->getClass());
$this->assertEquals(['%doctrine_mongodb.odm.document_manager.class%', 'create'], $definition->getFactory());
$this->assertEquals(DocumentManager::class, $definition->getClass());
$this->assertEquals([DocumentManager::class, 'create'], $definition->getFactory());
$this->assertArrayHasKey('doctrine_mongodb.odm.document_manager', $definition->getTags());

$arguments = $definition->getArguments();
Expand All @@ -192,7 +189,7 @@ public function testLoadSingleConnection(): void
$container->compile();

$definition = $container->getDefinition('doctrine_mongodb.odm.default_connection');
$this->assertEquals('%doctrine_mongodb.odm.connection.class%', $definition->getClass());
$this->assertEquals(Client::class, $definition->getClass());

$arguments = $definition->getArguments();
$this->assertEquals('mongodb://localhost:27017', $arguments[0]);
Expand All @@ -201,8 +198,8 @@ public function testLoadSingleConnection(): void
$this->assertSame(['root' => 'array', 'document' => 'array'], $arguments[2]['typeMap']);

$definition = $container->getDefinition('doctrine_mongodb.odm.default_document_manager');
$this->assertEquals('%doctrine_mongodb.odm.document_manager.class%', $definition->getClass());
$this->assertEquals(['%doctrine_mongodb.odm.document_manager.class%', 'create'], $definition->getFactory());
$this->assertEquals(DocumentManager::class, $definition->getClass());
$this->assertEquals([DocumentManager::class, 'create'], $definition->getFactory());
$this->assertArrayHasKey('doctrine_mongodb.odm.document_manager', $definition->getTags());

$arguments = $definition->getArguments();
Expand All @@ -228,7 +225,7 @@ public function testLoadMultipleConnections(): void
$container->compile();

$definition = $container->getDefinition('doctrine_mongodb.odm.conn1_connection');
$this->assertEquals('%doctrine_mongodb.odm.connection.class%', $definition->getClass());
$this->assertEquals(Client::class, $definition->getClass());

$arguments = $definition->getArguments();
$this->assertEquals('mongodb://localhost:27017', $arguments[0]);
Expand All @@ -237,8 +234,8 @@ public function testLoadMultipleConnections(): void
$this->assertSame(['root' => 'array', 'document' => 'array'], $arguments[2]['typeMap']);

$definition = $container->getDefinition('doctrine_mongodb.odm.dm1_document_manager');
$this->assertEquals('%doctrine_mongodb.odm.document_manager.class%', $definition->getClass());
$this->assertEquals(['%doctrine_mongodb.odm.document_manager.class%', 'create'], $definition->getFactory());
$this->assertEquals(DocumentManager::class, $definition->getClass());
$this->assertEquals([DocumentManager::class, 'create'], $definition->getFactory());
$this->assertArrayHasKey('doctrine_mongodb.odm.document_manager', $definition->getTags());

$arguments = $definition->getArguments();
Expand All @@ -248,7 +245,7 @@ public function testLoadMultipleConnections(): void
$this->assertEquals('doctrine_mongodb.odm.dm1_configuration', (string) $arguments[1]);

$definition = $container->getDefinition('doctrine_mongodb.odm.conn2_connection');
$this->assertEquals('%doctrine_mongodb.odm.connection.class%', $definition->getClass());
$this->assertEquals(Client::class, $definition->getClass());

$arguments = $definition->getArguments();
$this->assertEquals('mongodb://localhost:27017', $arguments[0]);
Expand All @@ -257,8 +254,8 @@ public function testLoadMultipleConnections(): void
$this->assertSame(['root' => 'array', 'document' => 'array'], $arguments[2]['typeMap']);

$definition = $container->getDefinition('doctrine_mongodb.odm.dm2_document_manager');
$this->assertEquals('%doctrine_mongodb.odm.document_manager.class%', $definition->getClass());
$this->assertEquals(['%doctrine_mongodb.odm.document_manager.class%', 'create'], $definition->getFactory());
$this->assertEquals(DocumentManager::class, $definition->getClass());
$this->assertEquals([DocumentManager::class, 'create'], $definition->getFactory());
$this->assertArrayHasKey('doctrine_mongodb.odm.document_manager', $definition->getTags());

$arguments = $definition->getArguments();
Expand Down

0 comments on commit 187fc88

Please sign in to comment.