Completed
Pull Request — development (#673)
by Nick
12:54 queued 04:44
created

AppKernel   A

Complexity

Total Complexity 9

Size/Duplication

Total Lines 104
Duplicated Lines 0 %

Coupling/Cohesion

Components 2
Dependencies 15

Importance

Changes 0
Metric Value
dl 0
loc 104
rs 9.1666
c 0
b 0
f 0
wmc 9
lcom 2
cbo 15

6 Methods

Rating   Name   Duplication   Size   Complexity  
A getRootDir() 0 4 1
A getCacheDir() 0 4 1
A getLogDir() 0 4 1
A registerContainerConfiguration() 0 4 1
A registerBundles() 0 23 2
A Container() 0 4 1
1
<?php
2
3
use Symfony\Component\Config\Loader\LoaderInterface;
4
use Symfony\Component\DependencyInjection\ContainerInterface;
5
use Symfony\Component\HttpKernel\Kernel;
6
7
class AppKernel extends Kernel
8
{
9
    /**
10
     * For legacy reasons.
11
     *
12
     * @var AppKernel
13
     */
14
    private static $instance;
15
16
    /**
17
     * Boots the current kernel.
18
     *
19
     * @return void
20
     */
21
    public function boot()
22
    {
23
        parent::boot();
24
        self::$instance = $this;
25
    }
26
27
    /**
28
     * @return array
29
     */
30
    public function registerBundles()
31
    {
32
        $bundles = [
33
            new Symfony\Bundle\FrameworkBundle\FrameworkBundle(),
34
            new Symfony\Bundle\SecurityBundle\SecurityBundle(),
35
            new Symfony\Bundle\TwigBundle\TwigBundle(),
36
            new Symfony\Bundle\MonologBundle\MonologBundle(),
37
            new Symfony\Bundle\SwiftmailerBundle\SwiftmailerBundle(),
38
            new Doctrine\Bundle\DoctrineBundle\DoctrineBundle(),
39
            new Sensio\Bundle\FrameworkExtraBundle\SensioFrameworkExtraBundle(),
40
            new Doctrine\Bundle\MigrationsBundle\DoctrineMigrationsBundle(),
41
            new JMS\TranslationBundle\JMSTranslationBundle()
42
        ];
43
44
        if (in_array($this->getEnvironment(), ['dev', 'test'], true)) {
45
            $bundles[] = new Symfony\Bundle\DebugBundle\DebugBundle();
46
            $bundles[] = new Symfony\Bundle\WebProfilerBundle\WebProfilerBundle();
47
            $bundles[] = new Sensio\Bundle\DistributionBundle\SensioDistributionBundle();
48
            $bundles[] = new Sensio\Bundle\GeneratorBundle\SensioGeneratorBundle();
49
        }
50
51
        return $bundles;
52
    }
53
54
    /**
55
     * @return string
56
     */
57
    public function getRootDir()
58
    {
59
        return __DIR__;
60
    }
61
62
    /**
63
     * @return string
64
     */
65
    public function getCacheDir()
66
    {
67
        return dirname(__DIR__) . '/var/cache/' . $this->getEnvironment();
68
    }
69
70
    /**
71
     * @return string
72
     */
73
    public function getLogDir()
74
    {
75
        return dirname(__DIR__) . '/var/logs';
76
    }
77
78
    /**
79
     * @param \Symfony\Component\Config\Loader\LoaderInterface $loader
80
     * @return void
81
     * @throws \Exception
82
     */
83
    public function registerContainerConfiguration(LoaderInterface $loader)
84
    {
85
        $loader->load($this->getRootDir() . '/config/config_' . $this->getEnvironment() . '.yml');
86
    }
87
88
    /**
89
     * Get instance of AppKernel.
90
     *
91
     * @return AppKernel
92
     */
93
    public static function getInstance()
94
    {
95
        return self::$instance;
96
    }
97
98
    /**
99
     * Dependency injection container.
100
     *
101
     * Is not named as getContainer because this is a function of the Kernel.
102
     * It acts as a shortcut for the legacy application to get the container.
103
     *
104
     * @return ContainerInterface
105
     */
106
    public static function Container()
107
    {
108
       return self::getInstance()->getContainer();
109
    }
110
}
111