123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155 |
- <?php
- /* For licensing terms, see /license.txt */
- namespace Chamilo;
- use Chamilo\CoreBundle\Component\Utils\ChamiloApi;
- use Symfony\Bundle\FrameworkBundle\Kernel\MicroKernelTrait;
- use Symfony\Component\Config\Loader\LoaderInterface;
- use Symfony\Component\Config\Resource\FileResource;
- use Symfony\Component\DependencyInjection\ContainerBuilder;
- use Symfony\Component\HttpKernel\Kernel as BaseKernel;
- use Symfony\Component\Routing\RouteCollectionBuilder;
- /**
- * Class Kernel.
- */
- class Kernel extends BaseKernel
- {
- use MicroKernelTrait;
- public const CONFIG_EXTS = '.{php,xml,yaml,yml}';
- /**
- * @return string
- */
- public function getCacheDir()
- {
- return $this->getProjectDir().'/var/cache/'.$this->environment;
- }
- /**
- * @return string
- */
- public function getResourceCacheDir()
- {
- return $this->getProjectDir().'/var/cache/resource/';
- }
- /**
- * @return string
- */
- public function getLogDir()
- {
- return $this->getProjectDir().'/var/log';
- }
- /**
- * @return \Generator|\Symfony\Component\HttpKernel\Bundle\BundleInterface[]
- */
- public function registerBundles()
- {
- $contents = require $this->getProjectDir().'/config/bundles.php';
- foreach ($contents as $class => $envs) {
- if (isset($envs['all']) || isset($envs[$this->environment])) {
- yield new $class();
- }
- }
- }
- /**
- * @return string
- */
- public function getRootDir()
- {
- if (null === $this->rootDir) {
- $r = new \ReflectionObject($this);
- $this->rootDir = str_replace('\\', '/', dirname($r->getFileName()));
- }
- return $this->rootDir;
- }
- /**
- * Returns the real root path.
- *
- * @return string
- */
- public function getRealRootDir()
- {
- return realpath($this->getRootDir().'/../').'/';
- }
- /**
- * Returns the data path.
- *
- * @return string
- */
- public function getDataDir()
- {
- return $this->getRealRootDir().'data/';
- }
- /**
- * @return string
- */
- public function getConfigurationFile()
- {
- return $this->getRealRootDir().'config/configuration.php';
- }
- /**
- * @param array $configuration
- */
- public function setApi(array $configuration)
- {
- new ChamiloApi($configuration);
- }
- /**
- * Check if system is installed
- * Checks the APP_INSTALLED env value.
- *
- * @return bool
- */
- public function isInstalled()
- {
- return !empty($this->getContainer()->getParameter('installed'));
- }
- /**
- * @return string
- */
- public function getUrlAppend()
- {
- return $this->getContainer()->getParameter('url_append');
- }
- /**
- * @param ContainerBuilder $container
- * @param LoaderInterface $loader
- */
- protected function configureContainer(ContainerBuilder $container, LoaderInterface $loader): void
- {
- $container->addResource(new FileResource($this->getProjectDir().'/config/bundles.php'));
- $container->setParameter('container.dumper.inline_class_loader', true);
- $confDir = $this->getProjectDir().'/config';
- $loader->load($confDir.'/{packages}/*'.self::CONFIG_EXTS, 'glob');
- $loader->load($confDir.'/{packages}/'.$this->environment.'/**/*'.self::CONFIG_EXTS, 'glob');
- $loader->load($confDir.'/{services}'.self::CONFIG_EXTS, 'glob');
- $loader->load($confDir.'/{services}_'.$this->environment.self::CONFIG_EXTS, 'glob');
- }
- /**
- * @param RouteCollectionBuilder $routes
- */
- protected function configureRoutes(RouteCollectionBuilder $routes): void
- {
- $confDir = $this->getProjectDir().'/config';
- $routes->import($confDir.'/{routes}/'.$this->environment.'/**/*'.self::CONFIG_EXTS, '/', 'glob');
- $routes->import($confDir.'/{routes}/*'.self::CONFIG_EXTS, '/', 'glob');
- $routes->import($confDir.'/{routes}'.self::CONFIG_EXTS, '/', 'glob');
- }
- }
|