Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[FrameworkExtraBundle/DoctrineExtra] allow to enabled/disabled mongodb #227

Merged
merged 1 commit into from
Jan 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,14 @@

namespace Draw\Bundle\FrameworkExtraBundle\DependencyInjection\Integration;

use Doctrine\ODM\MongoDB\DocumentManager;
use Doctrine\ORM\EntityManagerInterface;
use Doctrine\Persistence\ManagerRegistry;
use Draw\DoctrineExtra\ORM\EntityHandler;
use Draw\DoctrineExtra\ORM\Query\CommentSqlWalker;
use Symfony\Component\Config\Definition\Builder\ArrayNodeDefinition;
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\DependencyInjection\Loader\PhpFileLoader;
use Symfony\Component\Notifier\NotifierInterface;

class DoctrineExtraIntegration implements IntegrationInterface
{
Expand All @@ -21,13 +22,8 @@ public function getConfigSectionName(): string

public function load(array $config, PhpFileLoader $loader, ContainerBuilder $container): void
{
$container
->registerAliasForArgument('doctrine', ManagerRegistry::class, 'ormManagerRegistry');

$container
->registerAliasForArgument('doctrine_mongodb', ManagerRegistry::class, 'odmManagerRegistry');

$this->loadORM($config['orm'], $loader, $container);
$this->loadMongoODM($config['mongodb_odm'], $loader, $container);
}

private function loadORM(array $config, PhpFileLoader $loader, ContainerBuilder $container): void
Expand All @@ -36,6 +32,9 @@ private function loadORM(array $config, PhpFileLoader $loader, ContainerBuilder
return;
}

$container
->registerAliasForArgument('doctrine', ManagerRegistry::class, 'ormManagerRegistry');

$this->registerClasses(
$loader,
$namespace = 'Draw\\DoctrineExtra\\ORM\\',
Expand All @@ -55,19 +54,41 @@ private function loadORM(array $config, PhpFileLoader $loader, ContainerBuilder
);
}

private function loadMongoODM(array $config, PhpFileLoader $loader, ContainerBuilder $container): void
{
if (!$this->isConfigEnabled($container, $config)) {
return;
}

$container
->registerAliasForArgument('doctrine_mongodb', ManagerRegistry::class, 'odmManagerRegistry');
}

public function addConfiguration(ArrayNodeDefinition $node): void
{
$node
->children()
->append($this->createORMNode())
->append($this->createMongoODMNode())
->end();
}

private function createMongoODMNode(): ArrayNodeDefinition
{
$node = new ArrayNodeDefinition('mongodb_odm');

ContainerBuilder::willBeAvailable('doctrine/mongodb-odm', DocumentManager::class, [])
? $node->canBeDisabled()
: $node->canBeEnabled();

return $node;
}

private function createORMNode(): ArrayNodeDefinition
{
$node = new ArrayNodeDefinition('orm');

ContainerBuilder::willBeAvailable('doctrine/orm', NotifierInterface::class, [])
ContainerBuilder::willBeAvailable('doctrine/orm', EntityManagerInterface::class, [])
? $node->canBeDisabled()
: $node->canBeEnabled();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,15 @@

namespace Draw\Bundle\FrameworkExtraBundle\Tests\DependencyInjection\Integration;

use Doctrine\ODM\MongoDB\DocumentManager;
use Doctrine\ORM\EntityManagerInterface;
use Draw\Bundle\FrameworkExtraBundle\DependencyInjection\Integration\DoctrineExtraIntegration;
use Draw\Bundle\FrameworkExtraBundle\DependencyInjection\Integration\IntegrationInterface;
use Draw\DoctrineExtra\ORM\Command\ImportFileCommand;
use Draw\DoctrineExtra\ORM\Command\MysqlDumpCommand;
use Draw\DoctrineExtra\ORM\EntityHandler;
use PHPUnit\Framework\Attributes\CoversClass;
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\Notifier\NotifierInterface;

/**
* @property DoctrineExtraIntegration $integration
Expand All @@ -31,7 +32,10 @@ public function getDefaultConfiguration(): array
{
return [
'orm' => [
'enabled' => ContainerBuilder::willBeAvailable('doctrine/orm', NotifierInterface::class, []),
'enabled' => ContainerBuilder::willBeAvailable('doctrine/orm', EntityManagerInterface::class, []),
],
'mongodb_odm' => [
'enabled' => ContainerBuilder::willBeAvailable('doctrine/mongodb-odm', DocumentManager::class, []),
],
];
}
Expand All @@ -44,6 +48,9 @@ public static function provideTestLoad(): iterable
'orm' => [
'enabled' => true,
],
'mongodb_odm' => [
'enabled' => true,
],
],
],
[
Expand Down
Loading