SimpleBusBridgeExtension   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 63
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 6

Importance

Changes 0
Metric Value
wmc 3
lcom 0
cbo 6
dl 0
loc 63
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A load() 0 6 1
A prepend() 0 8 1
B addMiddlewareTags() 0 35 1
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\DependencyInjection;
14
15
use BenGorUser\UserBundle\DependencyInjection\Configuration;
16
use SimpleBus\Message\Handler\DelegatesToMessageHandlerMiddleware;
17
use SimpleBus\Message\Recorder\HandlesRecordedMessagesMiddleware;
18
use SimpleBus\Message\Subscriber\NotifiesMessageSubscribersMiddleware;
19
use Symfony\Component\Config\FileLocator;
20
use Symfony\Component\DependencyInjection\ContainerBuilder;
21
use Symfony\Component\DependencyInjection\Definition;
22
use Symfony\Component\DependencyInjection\Extension\PrependExtensionInterface;
23
use Symfony\Component\DependencyInjection\Loader\YamlFileLoader;
24
use Symfony\Component\HttpKernel\DependencyInjection\Extension;
25
26
/**
27
 * Simple bus bridge bundle extension class.
28
 *
29
 * @author Beñat Espiña <[email protected]>
30
 */
31
class SimpleBusBridgeExtension extends Extension implements PrependExtensionInterface, SimpleBusTaggerExtension
32
{
33
    /**
34
     * {@inheritdoc}
35
     */
36
    public function load(array $configs, ContainerBuilder $container)
37
    {
38
        $loader = new YamlFileLoader($container, new FileLocator(__DIR__ . '/../Resources/config'));
39
40
        $loader->load('middlewares.yml');
41
    }
42
43
    /**
44
     * {@inheritdoc}
45
     */
46
    public function prepend(ContainerBuilder $container)
47
    {
48
        $configuration = new Configuration();
49
        $configs = $container->getExtensionConfig('ben_gor_user');
50
        $config = $this->processConfiguration($configuration, $configs);
51
52
        $container->setParameter('bengor_user.config', $config);
53
    }
54
55
    /**
56
     * {@inheritdoc}
57
     */
58
    public function addMiddlewareTags(ContainerBuilder $container, $user)
59
    {
60
        // Related with Command Bus
61
        $container->setDefinition(
62
            'bengor_user.simple_bus_bridge_bundle.' . $user . '_command_bus.delegates_to_message_handler_middleware',
63
            (new Definition(DelegatesToMessageHandlerMiddleware::class))->addTag(
64
                'bengor_user_' . $user . '_command_bus_middleware', ['priority' => '-1000']
65
            )
66
        );
67
        $container->getDefinition(
68
            'bengor_user.simple_bus_bridge_bundle.finishes_command_before_handling_next_middleware'
69
        )->addTag(
70
            'bengor_user_' . $user . '_command_bus_middleware', ['priority' => '1000']
71
        );
72
73
        // Related with Event Bus
74
        $container->setDefinition(
75
            'bengor_user.simple_bus_bridge_bundle.' . $user . '_event_bus.delegates_to_message_handler_middleware',
76
            (new Definition(NotifiesMessageSubscribersMiddleware::class))->addTag(
77
                'bengor_user_' . $user . '_event_bus_middleware', ['priority' => '-1000']
78
            )
79
        )->addTag(
80
            'bengor_user_' . $user . '_command_bus_middleware', ['priority' => '200']
81
        );
82
        $container->setDefinition(
83
            'bengor_user.simple_bus_bridge_bundle.' . $user . '_event_bus.handles_recorded_messages_middleware',
84
            (new Definition(HandlesRecordedMessagesMiddleware::class))->addTag(
85
                'bengor_user_' . $user . '_event_bus_middleware', ['priority' => '-1000']
86
            )
87
        )->addTag(
88
            'bengor_user_' . $user . '_command_bus_middleware', ['priority' => '200']
89
        );
90
91
        return $container;
92
    }
93
}
94