Passed
Pull Request — master (#3)
by Vincent
08:42
created

PrimeBundle   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 41
Duplicated Lines 0 %

Test Coverage

Coverage 56.25%

Importance

Changes 2
Bugs 0 Features 0
Metric Value
eloc 12
c 2
b 0
f 0
dl 0
loc 41
ccs 9
cts 16
cp 0.5625
rs 10
wmc 6

3 Methods

Rating   Name   Duplication   Size   Complexity  
A boot() 0 5 2
A shutdown() 0 15 3
A build() 0 4 1
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
            Locatorizable::configure(function() {
26 2
                return $this->container->get('prime');
27 8
            });
28
        }
29 8
    }
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 7
    }
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