1 | <?php |
||
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 |