WrapsMessageHandlingInTransaction   A
last analyzed

Complexity

Total Complexity 2

Size/Duplication

Total Lines 39
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Importance

Changes 0
Metric Value
wmc 2
c 0
b 0
f 0
lcom 1
cbo 2
dl 0
loc 39
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 5 1
A handle() 0 7 1
1
<?php
2
3
/*
4
 * This file is part of the BenGorFile 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 BenGorFile\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
     * Constructor.
41
     *
42
     * @param ManagerRegistry $managerRegistry     The manager registry
43
     * @param string          $documentManagerName The document manager name
44
     */
45
    public function __construct(ManagerRegistry $managerRegistry, $documentManagerName)
46
    {
47
        $this->managerRegistry = $managerRegistry;
48
        $this->documentManagerName = $documentManagerName;
49
    }
50
51
    /**
52
     * {@inheritdoc}
53
     */
54
    public function handle($message, callable $next)
55
    {
56
        $documentManager = $this->managerRegistry->getManager($this->documentManagerName);
57
58
        call_user_func($next, $message);
59
        $documentManager->flush();
60
    }
61
}
62