Completed
Push — master ( 2e5350...f0c5b4 )
by Tobias
10:07
created

AppKernel   A

Complexity

Total Complexity 9

Size/Duplication

Total Lines 70
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 4

Importance

Changes 5
Bugs 1 Features 1
Metric Value
wmc 9
c 5
b 1
f 1
lcom 0
cbo 4
dl 0
loc 70
rs 10
1
<?php
2
3
use Symfony\Component\Config\Loader\LoaderInterface;
4
use Symfony\Component\HttpKernel\Kernel;
5
6
class AppKernel extends Kernel
7
{
8
    /**
9
     * {@inheritdoc}
10
     */
11
    public function registerBundles()
12
    {
13
        $bundles = [
14
            new \Symfony\Bundle\FrameworkBundle\FrameworkBundle(),
15
            new \Happyr\SerializerBundle\HappyrSerializerBundle(),
16
        ];
17
18
        return $bundles;
19
    }
20
21
    /**
22
     * {@inheritdoc}
23
     */
24
    public function registerContainerConfiguration(LoaderInterface $loader)
25
    {
26
        $loader->load(__DIR__.'/config/config.yml');
27
    }
28
29
    /**
30
     * {@inheritdoc}
31
     */
32
    public function getCacheDir()
33
    {
34
        return sys_get_temp_dir().'/serializer-bundle/cache';
35
    }
36
37
    /**
38
     * Clear the cache before boot.
39
     */
40
    public function boot()
41
    {
42
        $this->removeDirectory($this->getCacheDir());
43
44
        return parent::boot();
45
    }
46
47
    /**
48
     * Removes a directory and all contents.
49
     *
50
     * @param string $dir
51
     *
52
     * @return bool
53
     */
54
    private function removeDirectory($dir)
55
    {
56
        if (!is_dir($dir)) {
57
            return;
58
        }
59
60
        $files = array_diff(scandir($dir), array('.', '..'));
61
        foreach ($files as $file) {
62
            (is_dir("$dir/$file")) ? $this->removeDirectory("$dir/$file") : unlink("$dir/$file");
63
        }
64
65
        return rmdir($dir);
66
    }
67
68
    /**
69
     * {@inheritdoc}
70
     */
71
    public function getLogDir()
72
    {
73
        return sys_get_temp_dir().'/serializer-bundle/logs';
74
    }
75
}
76