Kernel.php 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155
  1. <?php
  2. /* For licensing terms, see /license.txt */
  3. namespace Chamilo;
  4. use Chamilo\CoreBundle\Component\Utils\ChamiloApi;
  5. use Symfony\Bundle\FrameworkBundle\Kernel\MicroKernelTrait;
  6. use Symfony\Component\Config\Loader\LoaderInterface;
  7. use Symfony\Component\Config\Resource\FileResource;
  8. use Symfony\Component\DependencyInjection\ContainerBuilder;
  9. use Symfony\Component\HttpKernel\Kernel as BaseKernel;
  10. use Symfony\Component\Routing\RouteCollectionBuilder;
  11. /**
  12. * Class Kernel.
  13. */
  14. class Kernel extends BaseKernel
  15. {
  16. use MicroKernelTrait;
  17. public const CONFIG_EXTS = '.{php,xml,yaml,yml}';
  18. /**
  19. * @return string
  20. */
  21. public function getCacheDir()
  22. {
  23. return $this->getProjectDir().'/var/cache/'.$this->environment;
  24. }
  25. /**
  26. * @return string
  27. */
  28. public function getResourceCacheDir()
  29. {
  30. return $this->getProjectDir().'/var/cache/resource/';
  31. }
  32. /**
  33. * @return string
  34. */
  35. public function getLogDir()
  36. {
  37. return $this->getProjectDir().'/var/log';
  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. * @return string
  53. */
  54. public function getRootDir()
  55. {
  56. if (null === $this->rootDir) {
  57. $r = new \ReflectionObject($this);
  58. $this->rootDir = str_replace('\\', '/', dirname($r->getFileName()));
  59. }
  60. return $this->rootDir;
  61. }
  62. /**
  63. * Returns the real root path.
  64. *
  65. * @return string
  66. */
  67. public function getRealRootDir()
  68. {
  69. return realpath($this->getRootDir().'/../').'/';
  70. }
  71. /**
  72. * Returns the data path.
  73. *
  74. * @return string
  75. */
  76. public function getDataDir()
  77. {
  78. return $this->getRealRootDir().'data/';
  79. }
  80. /**
  81. * @return string
  82. */
  83. public function getConfigurationFile()
  84. {
  85. return $this->getRealRootDir().'config/configuration.php';
  86. }
  87. /**
  88. * @param array $configuration
  89. */
  90. public function setApi(array $configuration)
  91. {
  92. new ChamiloApi($configuration);
  93. }
  94. /**
  95. * Check if system is installed
  96. * Checks the APP_INSTALLED env value.
  97. *
  98. * @return bool
  99. */
  100. public function isInstalled()
  101. {
  102. return !empty($this->getContainer()->getParameter('installed'));
  103. }
  104. /**
  105. * @return string
  106. */
  107. public function getUrlAppend()
  108. {
  109. return $this->getContainer()->getParameter('url_append');
  110. }
  111. /**
  112. * @param ContainerBuilder $container
  113. * @param LoaderInterface $loader
  114. */
  115. protected function configureContainer(ContainerBuilder $container, LoaderInterface $loader): void
  116. {
  117. $container->addResource(new FileResource($this->getProjectDir().'/config/bundles.php'));
  118. $container->setParameter('container.dumper.inline_class_loader', true);
  119. $confDir = $this->getProjectDir().'/config';
  120. $loader->load($confDir.'/{packages}/*'.self::CONFIG_EXTS, 'glob');
  121. $loader->load($confDir.'/{packages}/'.$this->environment.'/**/*'.self::CONFIG_EXTS, 'glob');
  122. $loader->load($confDir.'/{services}'.self::CONFIG_EXTS, 'glob');
  123. $loader->load($confDir.'/{services}_'.$this->environment.self::CONFIG_EXTS, 'glob');
  124. }
  125. /**
  126. * @param RouteCollectionBuilder $routes
  127. */
  128. protected function configureRoutes(RouteCollectionBuilder $routes): void
  129. {
  130. $confDir = $this->getProjectDir().'/config';
  131. $routes->import($confDir.'/{routes}/'.$this->environment.'/**/*'.self::CONFIG_EXTS, '/', 'glob');
  132. $routes->import($confDir.'/{routes}/*'.self::CONFIG_EXTS, '/', 'glob');
  133. $routes->import($confDir.'/{routes}'.self::CONFIG_EXTS, '/', 'glob');
  134. }
  135. }