You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
180 lines
4.5 KiB
180 lines
4.5 KiB
<?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\DependencyInjection\ContainerBuilder;
|
|
use Symfony\Component\HttpKernel\Kernel as BaseKernel;
|
|
use Symfony\Component\Routing\RouteCollectionBuilder;
|
|
|
|
/**
|
|
* Class Kernel.
|
|
*
|
|
* @package Chamilo
|
|
*/
|
|
class Kernel extends BaseKernel
|
|
{
|
|
use MicroKernelTrait;
|
|
|
|
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 getAppDir()
|
|
{
|
|
return $this->getRealRootDir().'app/';
|
|
}
|
|
|
|
/**
|
|
* @return string
|
|
*/
|
|
public function getConfigDir()
|
|
{
|
|
return $this->getRealRootDir().'app/config/';
|
|
}
|
|
|
|
/**
|
|
* @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
|
|
*
|
|
* @throws \Exception
|
|
*/
|
|
protected function configureContainer(ContainerBuilder $container, LoaderInterface $loader)
|
|
{
|
|
$container->setParameter('container.autowiring.strict_mode', true);
|
|
$container->setParameter('container.dumper.inline_class_loader', true);
|
|
$confDir = $this->getProjectDir().'/config';
|
|
$loader->load($confDir.'/packages/*'.self::CONFIG_EXTS, 'glob');
|
|
if (is_dir($confDir.'/packages/'.$this->environment)) {
|
|
$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
|
|
*
|
|
* @throws \Symfony\Component\Config\Exception\FileLoaderLoadException
|
|
*/
|
|
protected function configureRoutes(RouteCollectionBuilder $routes)
|
|
{
|
|
$confDir = $this->getProjectDir().'/config';
|
|
if (is_dir($confDir.'/routes/')) {
|
|
$routes->import($confDir.'/routes/*'.self::CONFIG_EXTS, '/', 'glob');
|
|
}
|
|
if (is_dir($confDir.'/routes/'.$this->environment)) {
|
|
$routes->import($confDir.'/routes/'.$this->environment.'/**/*'.self::CONFIG_EXTS, '/', 'glob');
|
|
}
|
|
$routes->import($confDir.'/routes'.self::CONFIG_EXTS, '/', 'glob');
|
|
}
|
|
}
|
|
|