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

PrimeBundle::shutdown()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 15
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 12

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 3
eloc 6
c 1
b 0
f 0
nc 3
nop 0
dl 0
loc 15
ccs 0
cts 7
cp 0
crap 12
rs 10
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