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