Passed
Push — master ( 777d67...42dc8a )
by Sébastien
12:06 queued 03:26
created

PrimeBundle   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 41
Duplicated Lines 0 %

Test Coverage

Coverage 50%

Importance

Changes 2
Bugs 0 Features 0
Metric Value
eloc 12
c 2
b 0
f 0
dl 0
loc 41
ccs 7
cts 14
cp 0.5
rs 10
wmc 6

3 Methods

Rating   Name   Duplication   Size   Complexity  
A shutdown() 0 15 3
A build() 0 4 1
A boot() 0 5 2
1
<?php
2
3
namespace Bdf\PrimeBundle;
4
5
use Bdf\Prime\Locatorizable;
6
use Bdf\Prime\ServiceLocator;
7
use Bdf\PrimeBundle\DependencyInjection\Compiler\IgnorePrimeAnnotationsPass;
8
use Bdf\PrimeBundle\DependencyInjection\Compiler\PrimeConnectionFactoryPass;
9
use Symfony\Component\DependencyInjection\ContainerBuilder;
10
use Symfony\Component\HttpKernel\Bundle\Bundle;
11
12
/**
13
 * PrimeBundle
14
 *
15
 * @author Seb
16
 */
17
class PrimeBundle extends Bundle
18
{
19
    /**
20
     * {@inheritDoc}
21
     */
22 8
    public function boot()
23
    {
24 8
        if ($this->container->getParameter('prime.locatorizable')) {
25 8
            Locatorizable::configure(function() {
26 2
                return $this->container->get('prime');
27
            });
28
        }
29
    }
30
31
    /**
32
     * {@inheritDoc}
33
     */
34 7
    public function build(ContainerBuilder $container)
35
    {
36 7
        $container->addCompilerPass(new PrimeConnectionFactoryPass());
37 7
        $container->addCompilerPass(new IgnorePrimeAnnotationsPass());
38
    }
39
40
    /**
41
     * {@inheritDoc}
42
     */
43
    public function shutdown()
44
    {
45
        if (!$this->container->initialized('prime')) {
46
            return;
47
        }
48
49
        /** @var ServiceLocator $prime */
50
        $prime = $this->container->get('prime');
51
52
        // Clear circle references
53
        $prime->clearRepositories();
54
55
        // Close all loaded connections
56
        foreach ($prime->connections() as $connection) {
57
            $connection->close();
58
        }
59
    }
60
}
61