Passed
Push — master ( 53af2f...2f4516 )
by Julito
11:40
created

Kernel::getUrlAppend()   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 Symfony\Bundle\FrameworkBundle\Kernel\MicroKernelTrait;
7
use Symfony\Component\Config\Loader\LoaderInterface;
8
use Symfony\Component\DependencyInjection\ContainerBuilder;
9
use Symfony\Component\HttpKernel\Kernel as BaseKernel;
10
use Symfony\Component\Routing\RouteCollectionBuilder;
11
use Chamilo\CoreBundle\Component\Utils\ChamiloApi;
12
13
/**
14
 * Class Kernel
15
 * @package Chamilo
16
 */
17
class Kernel extends BaseKernel
18
{
19
    use MicroKernelTrait;
20
21
    const CONFIG_EXTS = '.{php,xml,yaml,yml}';
22
23
    /**
24
     * @return string
25
     */
26
    public function getCacheDir()
27
    {
28
        return $this->getProjectDir().'/var/cache/'.$this->environment;
0 ignored issues
show
Bug introduced by
The method getProjectDir() does not exist on Chamilo\Kernel. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

28
        return $this->/** @scrutinizer ignore-call */ getProjectDir().'/var/cache/'.$this->environment;

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
29
    }
30
31
    /**
32
     * @return string
33
     */
34
    public function getLogDir()
35
    {
36
        return $this->getProjectDir().'/var/log';
37
    }
38
39
    /**
40
     * @return \Generator|\Symfony\Component\HttpKernel\Bundle\BundleInterface[]
41
     */
42
    public function registerBundles()
43
    {
44
        $contents = require $this->getProjectDir().'/config/bundles.php';
45
        foreach ($contents as $class => $envs) {
46
            if (isset($envs['all']) || isset($envs[$this->environment])) {
47
                yield new $class();
48
            }
49
        }
50
    }
51
52
    /**
53
     * @param ContainerBuilder $container
54
     * @param LoaderInterface $loader
55
     * @throws \Exception
56
     */
57
    protected function configureContainer(ContainerBuilder $container, LoaderInterface $loader)
58
    {
59
        $container->setParameter('container.autowiring.strict_mode', true);
60
        $container->setParameter('container.dumper.inline_class_loader', true);
61
        $confDir = $this->getProjectDir().'/config';
62
        $loader->load($confDir.'/packages/*'.self::CONFIG_EXTS, 'glob');
63
        if (is_dir($confDir.'/packages/'.$this->environment)) {
64
            $loader->load($confDir.'/packages/'.$this->environment.'/**/*'.self::CONFIG_EXTS, 'glob');
65
        }
66
        $loader->load($confDir.'/services'.self::CONFIG_EXTS, 'glob');
67
        $loader->load($confDir.'/services_'.$this->environment.self::CONFIG_EXTS, 'glob');
68
    }
69
70
    /**
71
     * @param RouteCollectionBuilder $routes
72
     * @throws \Symfony\Component\Config\Exception\FileLoaderLoadException
73
     */
74
    protected function configureRoutes(RouteCollectionBuilder $routes)
75
    {
76
        $confDir = $this->getProjectDir().'/config';
77
        if (is_dir($confDir.'/routes/')) {
78
            $routes->import($confDir.'/routes/*'.self::CONFIG_EXTS, '/', 'glob');
79
        }
80
        if (is_dir($confDir.'/routes/'.$this->environment)) {
81
            $routes->import($confDir.'/routes/'.$this->environment.'/**/*'.self::CONFIG_EXTS, '/', 'glob');
82
        }
83
        $routes->import($confDir.'/routes'.self::CONFIG_EXTS, '/', 'glob');
84
    }
85
86
    /**
87
     * @return string
88
     */
89
    public function getRootDir()
90
    {
91
        if (null === $this->rootDir) {
92
            $r = new \ReflectionObject($this);
93
            $this->rootDir = str_replace('\\', '/', dirname($r->getFileName()));
94
        }
95
96
        return $this->rootDir;
97
    }
98
99
    /**
100
     * Returns the real root path
101
     * @return string
102
     */
103
    public function getRealRootDir()
104
    {
105
        return realpath($this->getRootDir().'/../').'/';
106
    }
107
108
    /**
109
     * Returns the data path
110
     * @return string
111
     */
112
    public function getDataDir()
113
    {
114
        return $this->getRealRootDir().'data/';
115
    }
116
117
    /**
118
     * @return string
119
     */
120
    public function getAppDir()
121
    {
122
        return $this->getRealRootDir().'app/';
123
    }
124
125
    /**
126
     * @return string
127
     */
128
    public function getConfigDir()
129
    {
130
        return $this->getRealRootDir().'app/config/';
131
    }
132
133
    /**
134
     * @return string
135
     */
136
    public function getConfigurationFile()
137
    {
138
        return $this->getRealRootDir().'app/config/configuration.php';
139
    }
140
141
    /**
142
     * @param array $configuration
143
     */
144
    public function setApi(array $configuration)
145
    {
146
        new ChamiloApi($configuration);
147
    }
148
149
    /**
150
    * Check if system is installed
151
    * Checks the APP_INSTALLED env value
152
    * @return bool
153
    */
154
    public function isInstalled()
155
    {
156
        return !empty($this->getContainer()->getParameter('installed'));
157
    }
158
159
    public function getUrlAppend()
160
    {
161
        return $this->getContainer()->getParameter('url_append');
162
    }
163
}
164