forked from swarrot/swarrot
-
Notifications
You must be signed in to change notification settings - Fork 0
/
ObjectManagerProcessor.php
43 lines (36 loc) · 1.1 KB
/
ObjectManagerProcessor.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
<?php
namespace Swarrot\Processor\Doctrine;
use Doctrine\Persistence\ManagerRegistry;
use Swarrot\Broker\Message;
use Swarrot\Processor\ProcessorInterface;
/**
* @author Adrien Brault <[email protected]>
*/
class ObjectManagerProcessor implements ProcessorInterface
{
private $processor;
private $managerRegistry;
public function __construct(ProcessorInterface $processor, ManagerRegistry $managerRegistry)
{
$this->processor = $processor;
$this->managerRegistry = $managerRegistry;
}
/**
* {@inheritdoc}
*/
public function process(Message $message, array $options): bool
{
try {
return $this->processor->process($message, $options);
} finally {
foreach ($this->managerRegistry->getManagers() as $managerName => $manager) {
if (method_exists($manager, 'isOpen')
&& !$manager->isOpen()) {
$this->managerRegistry->resetManager($managerName);
continue;
}
$manager->clear();
}
}
}
}