Completed
Push — master ( bcef33...84362a )
by Julito
09:49
created

Kernel::getLogDir()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 1
nc 1
nop 0
dl 0
loc 3
rs 10
c 0
b 0
f 0
1
<?php
2
/* For licensing terms, see /license.txt */
3
4
namespace Chamilo;
5
6
use Chamilo\CoreBundle\Component\Utils\ChamiloApi;
7
use Symfony\Bundle\FrameworkBundle\Kernel\MicroKernelTrait;
8
use Symfony\Component\Config\Loader\LoaderInterface;
9
use Symfony\Component\DependencyInjection\ContainerBuilder;
10
use Symfony\Component\HttpKernel\Kernel as BaseKernel;
11
use Symfony\Component\Routing\RouteCollectionBuilder;
12
13
/**
14
 * Class Kernel.
15
 *
16
 * @package Chamilo
17
 */
18
class Kernel extends BaseKernel
19
{
20
    use MicroKernelTrait;
21
22
    const CONFIG_EXTS = '.{php,xml,yaml,yml}';
23
24
    /**
25
     * @return string
26
     */
27
    public function getCacheDir()
28
    {
29
        return $this->getProjectDir().'/var/cache/'.$this->environment;
30
    }
31
32
    /**
33
     * @return string
34
     */
35
    public function getResourceCacheDir()
36
    {
37
        return $this->getProjectDir().'/var/cache/resource/';
38
    }
39
40
    /**
41
     * @return string
42
     */
43
    public function getLogDir()
44
    {
45
        return $this->getProjectDir().'/var/log';
46
    }
47
48
    /**
49
     * @return \Generator|\Symfony\Component\HttpKernel\Bundle\BundleInterface[]
50
     */
51
    public function registerBundles()
52
    {
53
        $contents = require $this->getProjectDir().'/config/bundles.php';
54
        foreach ($contents as $class => $envs) {
55
            if (isset($envs['all']) || isset($envs[$this->environment])) {
56
                yield new $class();
57
            }
58
        }
59
    }
60
61
    /**
62
     * @return string
63
     */
64
    public function getRootDir()
65
    {
66
        if (null === $this->rootDir) {
67
            $r = new \ReflectionObject($this);
68
            $this->rootDir = str_replace('\\', '/', dirname($r->getFileName()));
0 ignored issues
show
Bug Best Practice introduced by
The property rootDir does not exist. Although not strictly required by PHP, it is generally a best practice to declare properties explicitly.
Loading history...
69
        }
70
71
        return $this->rootDir;
72
    }
73
74
    /**
75
     * Returns the real root path.
76
     *
77
     * @return string
78
     */
79
    public function getRealRootDir()
80
    {
81
        return realpath($this->getRootDir().'/../').'/';
82
    }
83
84
    /**
85
     * Returns the data path.
86
     *
87
     * @return string
88
     */
89
    public function getDataDir()
90
    {
91
        return $this->getRealRootDir().'data/';
92
    }
93
94
    /**
95
     * @return string
96
     */
97
    public function getAppDir()
98
    {
99
        return $this->getRealRootDir().'app/';
100
    }
101
102
    /**
103
     * @return string
104
     */
105
    public function getConfigDir()
106
    {
107
        return $this->getRealRootDir().'app/config/';
108
    }
109
110
    /**
111
     * @return string
112
     */
113
    public function getConfigurationFile()
114
    {
115
        return $this->getRealRootDir().'config/configuration.php';
116
    }
117
118
    /**
119
     * @param array $configuration
120
     */
121
    public function setApi(array $configuration)
122
    {
123
        new ChamiloApi($configuration);
124
    }
125
126
    /**
127
     * Check if system is installed
128
     * Checks the APP_INSTALLED env value.
129
     *
130
     * @return bool
131
     */
132
    public function isInstalled()
133
    {
134
        return !empty($this->getContainer()->getParameter('installed'));
135
    }
136
137
    /**
138
     * @return string
139
     */
140
    public function getUrlAppend()
141
    {
142
        return $this->getContainer()->getParameter('url_append');
143
    }
144
145
    /**
146
     * @param ContainerBuilder $container
147
     * @param LoaderInterface  $loader
148
     *
149
     * @throws \Exception
150
     */
151
    protected function configureContainer(ContainerBuilder $container, LoaderInterface $loader)
152
    {
153
        $container->setParameter('container.autowiring.strict_mode', true);
154
        $container->setParameter('container.dumper.inline_class_loader', true);
155
        $confDir = $this->getProjectDir().'/config';
156
        $loader->load($confDir.'/packages/*'.self::CONFIG_EXTS, 'glob');
157
        if (is_dir($confDir.'/packages/'.$this->environment)) {
158
            $loader->load($confDir.'/packages/'.$this->environment.'/**/*'.self::CONFIG_EXTS, 'glob');
159
        }
160
        $loader->load($confDir.'/services'.self::CONFIG_EXTS, 'glob');
161
        $loader->load($confDir.'/services_'.$this->environment.self::CONFIG_EXTS, 'glob');
162
    }
163
164
    /**
165
     * @param RouteCollectionBuilder $routes
166
     *
167
     * @throws \Symfony\Component\Config\Exception\FileLoaderLoadException
168
     */
169
    protected function configureRoutes(RouteCollectionBuilder $routes)
170
    {
171
        $confDir = $this->getProjectDir().'/config';
172
        if (is_dir($confDir.'/routes/')) {
173
            $routes->import($confDir.'/routes/*'.self::CONFIG_EXTS, '/', 'glob');
174
        }
175
        if (is_dir($confDir.'/routes/'.$this->environment)) {
176
            $routes->import($confDir.'/routes/'.$this->environment.'/**/*'.self::CONFIG_EXTS, '/', 'glob');
177
        }
178
        $routes->import($confDir.'/routes'.self::CONFIG_EXTS, '/', 'glob');
179
    }
180
}
181