Skip to content

Commit 2322fd5

Browse files
authored
Merge pull request #9 from ne0h12/master
Supports mongodb persistence driver
2 parents 6e9aaf9 + 7bf5352 commit 2322fd5

File tree

3 files changed

+48
-4
lines changed

3 files changed

+48
-4
lines changed

DependencyInjection/Configuration.php

+3
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,9 @@ public function getConfigTreeBuilder()
1919
->scalarNode('context')->defaultValue('enqueue.transport.context')->cannotBeEmpty()->end()
2020
->arrayNode('doctrine')
2121
->children()
22+
->scalarNode('driver')->defaultValue('orm')->cannotBeEmpty()
23+
->validate()->ifNotInArray(['orm', 'mongodb'])->thenInvalid('Invalid driver')
24+
->end()->end()
2225
->arrayNode('queue_listeners')
2326
->prototype('array')
2427
->addDefaultsIfNotSet()

DependencyInjection/EnqueueElasticaExtension.php

+42-1
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ public function load(array $configs, ContainerBuilder $container)
2323

2424
$container->setAlias('enqueue_elastica.context', $config['context']);
2525

26+
$doctrineDriver = $config['doctrine']['driver'];
2627
if (false == empty($config['doctrine']['queue_listeners'])) {
2728
foreach ($config['doctrine']['queue_listeners'] as $listenerConfig) {
2829
$listenerId = sprintf(
@@ -36,9 +37,49 @@ public function load(array $configs, ContainerBuilder $container)
3637
->addArgument(new Reference('enqueue_elastica.context'))
3738
->addArgument($listenerConfig['model_class'])
3839
->addArgument($listenerConfig)
39-
->addTag('doctrine.event_subscriber', ['connection' => $listenerConfig['connection']])
40+
->addTag($this->getEventSubscriber($doctrineDriver), ['connection' => $listenerConfig['connection']])
4041
;
4142
}
4243
}
44+
45+
$serviceId = 'enqueue_elastica.doctrine.sync_index_with_object_change_processor';
46+
$managerRegistry = $this->getManagerRegistry($doctrineDriver);
47+
$container
48+
->getDefinition($serviceId)
49+
->replaceArgument(0, new Reference($managerRegistry));
50+
}
51+
52+
/**
53+
* @param string $driver
54+
*
55+
* @return string
56+
*/
57+
private function getManagerRegistry(string $driver): string
58+
{
59+
switch ($driver) {
60+
case 'mongodb':
61+
return 'doctrine_mongodb';
62+
break;
63+
case 'orm':
64+
default:
65+
return 'doctrine';
66+
}
67+
}
68+
69+
/**
70+
* @param string $driver
71+
*
72+
* @return string
73+
*/
74+
private function getEventSubscriber(string $driver): string
75+
{
76+
switch ($driver) {
77+
case 'mongodb':
78+
return 'doctrine_mongodb.odm.event_subscriber';
79+
break;
80+
case 'orm':
81+
default:
82+
return 'doctrine.event_subscriber';
83+
}
4384
}
4485
}

Doctrine/Queue/SyncIndexWithObjectChangeProcessor.php

+3-3
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
use Interop\Queue\PsrContext;
1111
use Interop\Queue\PsrMessage;
1212
use Interop\Queue\PsrProcessor;
13-
use Symfony\Bridge\Doctrine\RegistryInterface;
13+
use Doctrine\Common\Persistence\ManagerRegistry;
1414

1515
final class SyncIndexWithObjectChangeProcessor implements PsrProcessor, CommandSubscriberInterface, QueueSubscriberInterface
1616
{
@@ -31,11 +31,11 @@ final class SyncIndexWithObjectChangeProcessor implements PsrProcessor, CommandS
3131
private $indexable;
3232

3333
/**
34-
* @var RegistryInterface
34+
* @var ManagerRegistry
3535
*/
3636
private $doctrine;
3737

38-
public function __construct(RegistryInterface $doctrine, PersisterRegistry $persisterRegistry, IndexableInterface $indexable)
38+
public function __construct(ManagerRegistry $doctrine, PersisterRegistry $persisterRegistry, IndexableInterface $indexable)
3939
{
4040
$this->persisterRegistry = $persisterRegistry;
4141
$this->indexable = $indexable;

0 commit comments

Comments
 (0)