WrapsMessageHandlingInTransaction::__construct()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 5
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 3
nc 1
nop 2
1
<?php
2
3
/*
4
 * This file is part of the BenGorUser package.
5
 *
6
 * (c) Beñat Espiña <[email protected]>
7
 * (c) Gorka Laucirica <[email protected]>
8
 *
9
 * For the full copyright and license information, please view the LICENSE
10
 * file that was distributed with this source code.
11
 */
12
13
namespace BenGorUser\SimpleBusBridgeBundle\MessageBus\Doctrine\ODM\MongoDB;
14
15
use Doctrine\Common\Persistence\ManagerRegistry;
16
use SimpleBus\Message\Bus\Middleware\MessageBusMiddleware;
17
18
/**
19
 * Transactional middleware for Doctrine ODM MongoDB.
20
 *
21
 * @author Beñat Espiña <[email protected]>
22
 */
23
class WrapsMessageHandlingInTransaction implements MessageBusMiddleware
24
{
25
    /**
26
     * The document manager name.
27
     *
28
     * @var string
29
     */
30
    private $documentManagerName;
31
32
    /**
33
     * The manager registry.
34
     *
35
     * @var ManagerRegistry
36
     */
37
    private $managerRegistry;
38
39
    /**
40
     * @param ManagerRegistry $managerRegistry     The manager registry
41
     * @param string          $documentManagerName The document manager name
42
     */
43
    public function __construct(ManagerRegistry $managerRegistry, $documentManagerName)
44
    {
45
        $this->managerRegistry = $managerRegistry;
46
        $this->documentManagerName = $documentManagerName;
47
    }
48
49
    /**
50
     * {@inheritdoc}
51
     */
52
    public function handle($message, callable $next)
53
    {
54
        $documentManager = $this->managerRegistry->getManager($this->documentManagerName);
55
56
        call_user_func($next, $message);
57
        $documentManager->flush();
58
    }
59
}
60