Passed
Push — master ( d798c9...9bab39 )
by Julito
08:46
created

Kernel::getLogDir()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 1
nc 1
nop 0
dl 0
loc 3
rs 10
c 1
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\Config\Resource\FileResource;
10
use Symfony\Component\DependencyInjection\ContainerBuilder;
11
use Symfony\Component\HttpKernel\Kernel as BaseKernel;
12
use Symfony\Component\Routing\RouteCollectionBuilder;
13
14
/**
15
 * Class Kernel.
16
 */
17
class Kernel extends BaseKernel
18
{
19
    use MicroKernelTrait;
20
21
    public const CONFIG_EXTS = '.{php,xml,yaml,yml}';
22
23
    /**
24
     * @return \Generator|\Symfony\Component\HttpKernel\Bundle\BundleInterface[]
25
     */
26
    public function registerBundles()
27
    {
28
        $contents = require $this->getProjectDir().'/config/bundles.php';
29
        foreach ($contents as $class => $envs) {
30
            if (isset($envs['all']) || isset($envs[$this->environment])) {
31
                yield new $class();
32
            }
33
        }
34
    }
35
36
    public function getProjectDir(): string
37
    {
38
        return \dirname(__DIR__);
39
    }
40
41
    /**
42
     * @return string
43
     */
44
    public function getConfigurationFile()
45
    {
46
        return $this->getProjectDir().'/config/configuration.php';
47
    }
48
49
    public function setApi(array $configuration)
50
    {
51
        new ChamiloApi($configuration);
52
    }
53
54
    /**
55
     * Check if system is installed
56
     * Checks the APP_INSTALLED env value.
57
     *
58
     * @return bool
59
     */
60
    public function isInstalled()
61
    {
62
        return !empty($this->getContainer()->getParameter('installed'));
63
    }
64
65
    protected function configureContainer(ContainerBuilder $container, LoaderInterface $loader): void
66
    {
67
        $container->addResource(new FileResource($this->getProjectDir().'/config/bundles.php'));
68
        $container->setParameter('container.dumper.inline_class_loader', true);
69
        $confDir = $this->getProjectDir().'/config';
70
71
        $loader->load($confDir.'/{packages}/*'.self::CONFIG_EXTS, 'glob');
72
        $loader->load($confDir.'/{packages}/'.$this->environment.'/**/*'.self::CONFIG_EXTS, 'glob');
73
        $loader->load($confDir.'/{services}'.self::CONFIG_EXTS, 'glob');
74
        $loader->load($confDir.'/{services}_'.$this->environment.self::CONFIG_EXTS, 'glob');
75
    }
76
77
    protected function configureRoutes(RouteCollectionBuilder $routes): void
78
    {
79
        $confDir = $this->getProjectDir().'/config';
80
81
        $routes->import($confDir.'/{routes}/'.$this->environment.'/**/*'.self::CONFIG_EXTS, '/', 'glob');
82
        $routes->import($confDir.'/{routes}/*'.self::CONFIG_EXTS, '/', 'glob');
83
        $routes->import($confDir.'/{routes}'.self::CONFIG_EXTS, '/', 'glob');
84
    }
85
}
86