wallabag/app/AppKernel.php

183 lines
6.5 KiB
PHP
Raw Permalink Normal View History

2015-01-22 07:30:07 +00:00
<?php
use BabDev\PagerfantaBundle\BabDevPagerfantaBundle;
use Bazinga\Bundle\HateoasBundle\BazingaHateoasBundle;
use Craue\ConfigBundle\CraueConfigBundle;
use DAMA\DoctrineTestBundle\DAMADoctrineTestBundle;
use Doctrine\Bundle\DoctrineBundle\DoctrineBundle;
use Doctrine\Bundle\FixturesBundle\DoctrineFixturesBundle;
use Doctrine\Bundle\MigrationsBundle\DoctrineMigrationsBundle;
use FOS\JsRoutingBundle\FOSJsRoutingBundle;
use FOS\OAuthServerBundle\FOSOAuthServerBundle;
use FOS\RestBundle\FOSRestBundle;
use FOS\UserBundle\FOSUserBundle;
use JMS\SerializerBundle\JMSSerializerBundle;
use KPhoen\RulerZBundle\KPhoenRulerZBundle;
use Nelmio\ApiDocBundle\NelmioApiDocBundle;
use Nelmio\CorsBundle\NelmioCorsBundle;
use OldSound\RabbitMqBundle\OldSoundRabbitMqBundle;
use Scheb\TwoFactorBundle\SchebTwoFactorBundle;
use Sensio\Bundle\FrameworkExtraBundle\SensioFrameworkExtraBundle;
use Sentry\SentryBundle\SentryBundle;
use Spiriit\Bundle\FormFilterBundle\SpiriitFormFilterBundle;
use Stof\DoctrineExtensionsBundle\StofDoctrineExtensionsBundle;
use Symfony\Bundle\DebugBundle\DebugBundle;
use Symfony\Bundle\FrameworkBundle\FrameworkBundle;
use Symfony\Bundle\MakerBundle\MakerBundle;
use Symfony\Bundle\MonologBundle\MonologBundle;
use Symfony\Bundle\SecurityBundle\SecurityBundle;
use Symfony\Bundle\TwigBundle\TwigBundle;
use Symfony\Bundle\WebProfilerBundle\WebProfilerBundle;
use Symfony\Bundle\WebServerBundle\WebServerBundle;
2015-01-22 07:30:07 +00:00
use Symfony\Component\Config\Loader\LoaderInterface;
2018-10-24 19:02:35 +00:00
use Symfony\Component\DependencyInjection\ContainerBuilder;
2017-07-01 07:52:38 +00:00
use Symfony\Component\HttpKernel\Kernel;
use Symfony\WebpackEncoreBundle\WebpackEncoreBundle;
use Twig\Extra\TwigExtraBundle\TwigExtraBundle;
2024-02-19 00:30:12 +00:00
use Wallabag\Import\ImportCompilerPass;
2015-01-22 07:30:07 +00:00
class AppKernel extends Kernel
{
public function registerBundles()
{
2016-01-14 17:15:07 +00:00
$bundles = [
new FrameworkBundle(),
new SecurityBundle(),
new TwigBundle(),
new MonologBundle(),
new DoctrineBundle(),
new SensioFrameworkExtraBundle(),
new FOSRestBundle(),
new FOSUserBundle(),
new JMSSerializerBundle(),
new NelmioApiDocBundle(),
new NelmioCorsBundle(),
new BazingaHateoasBundle(),
new SpiriitFormFilterBundle(),
new FOSOAuthServerBundle(),
new StofDoctrineExtensionsBundle(),
new SchebTwoFactorBundle(),
new KPhoenRulerZBundle(),
new DoctrineMigrationsBundle(),
new CraueConfigBundle(),
new BabDevPagerfantaBundle(),
new FOSJsRoutingBundle(),
new OldSoundRabbitMqBundle(),
new SentryBundle(),
new TwigExtraBundle(),
new WebpackEncoreBundle(),
2016-01-14 17:15:07 +00:00
];
2015-01-22 07:30:07 +00:00
2016-01-14 17:15:07 +00:00
if (in_array($this->getEnvironment(), ['dev', 'test'], true)) {
$bundles[] = new DebugBundle();
$bundles[] = new WebProfilerBundle();
$bundles[] = new DoctrineFixturesBundle();
if ('test' === $this->getEnvironment()) {
$bundles[] = new DAMADoctrineTestBundle();
}
2018-10-24 19:02:35 +00:00
if ('dev' === $this->getEnvironment()) {
$bundles[] = new MakerBundle();
$bundles[] = new WebServerBundle();
2018-10-24 19:02:35 +00:00
}
2015-01-22 07:30:07 +00:00
}
return $bundles;
}
2016-01-14 17:15:07 +00:00
public function getCacheDir()
{
2017-07-01 07:52:38 +00:00
return dirname(__DIR__) . '/var/cache/' . $this->getEnvironment();
2016-01-14 17:15:07 +00:00
}
public function getLogDir()
{
2017-07-01 07:52:38 +00:00
return dirname(__DIR__) . '/var/logs';
2016-01-14 17:15:07 +00:00
}
2015-01-22 07:30:07 +00:00
public function registerContainerConfiguration(LoaderInterface $loader)
{
$loader->load($this->getProjectDir() . '/app/config/config_' . $this->getEnvironment() . '.yml');
2018-10-24 19:02:35 +00:00
$loader->load(function (ContainerBuilder $container): void {
2018-10-24 19:02:35 +00:00
// $container->setParameter('container.autowiring.strict_mode', true);
// $container->setParameter('container.dumper.inline_class_loader', true);
$container->addObjectResource($this);
});
2024-01-04 01:04:20 +00:00
$loader->load(function (ContainerBuilder $container): void {
2024-01-04 01:04:20 +00:00
$this->processDatabaseParameters($container);
2025-02-22 12:37:00 +00:00
$this->defineRedisUrlEnvVar($container);
2025-02-22 13:57:53 +00:00
$this->defineRabbitMqUrlEnvVar($container);
2024-01-04 01:04:20 +00:00
});
}
protected function build(ContainerBuilder $container)
{
$container->addCompilerPass(new ImportCompilerPass());
}
2024-01-04 23:41:13 +00:00
private function processDatabaseParameters(ContainerBuilder $container)
2024-01-04 01:04:20 +00:00
{
2025-04-05 11:56:56 +00:00
$scheme = match ($container->getParameter('database_driver')) {
'pdo_mysql' => 'mysql',
'pdo_pgsql' => 'pgsql',
'pdo_sqlite' => 'sqlite',
default => throw new RuntimeException('Unsupported database driver: ' . $container->getParameter('database_driver')),
};
2024-01-04 01:04:20 +00:00
2024-01-04 23:41:13 +00:00
$container->setParameter('database_scheme', $scheme);
2024-01-04 01:04:20 +00:00
if ('sqlite' === $scheme) {
2024-01-04 23:41:13 +00:00
$container->setParameter('database_name', $container->getParameter('database_path'));
2024-01-04 01:04:20 +00:00
}
2024-01-04 23:41:13 +00:00
$container->setParameter('database_user', (string) $container->getParameter('database_user'));
$container->setParameter('database_password', (string) $container->getParameter('database_password'));
$container->setParameter('database_port', (string) $container->getParameter('database_port'));
$container->setParameter('database_socket', (string) $container->getParameter('database_socket'));
2015-01-22 07:30:07 +00:00
}
2025-02-22 12:37:00 +00:00
private function defineRedisUrlEnvVar(ContainerBuilder $container)
{
$scheme = $container->getParameter('redis_scheme');
$host = $container->getParameter('redis_host');
$port = $container->getParameter('redis_port');
$path = $container->getParameter('redis_path');
$password = $container->getParameter('redis_password');
$url = $scheme . '://';
if ($password) {
$url .= $password . '@';
}
$url .= $host;
if ($port) {
$url .= ':' . $port;
}
$url .= '/' . ltrim($path, '/');
$container->setParameter('env(REDIS_URL)', $url);
}
2025-02-22 13:57:53 +00:00
private function defineRabbitMqUrlEnvVar(ContainerBuilder $container)
{
$host = $container->getParameter('rabbitmq_host');
$port = $container->getParameter('rabbitmq_port');
$user = $container->getParameter('rabbitmq_user');
$password = $container->getParameter('rabbitmq_password');
$url = 'amqp://' . $user . ':' . $password . '@' . $host;
if ($port) {
$url .= ':' . $port;
}
$container->setParameter('env(RABBITMQ_URL)', $url);
}
2015-01-22 07:30:07 +00:00
}