<?php
use App\Backoffice\DependencyInjection\CompilerPass\ExporterPass;
use App\Core\AppConfiguration\AppConfigurationInterface;
use App\Core\Cron\DependencyInjection\CronPass;
use App\Dev\DependencyInjection\AwsPass;
use App\Dev\DependencyInjection\DevFilesystemPass;
use App\Core\Job\DependencyInjection\JobCommandPass;
use App\Core\Symfony\Environment;
use DocumentBundle\Model\TableMergeField\TableMergeFieldInterface;
use Symfony\Component\Config\Loader\LoaderInterface;
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\Dotenv\Dotenv;
use Symfony\Component\HttpKernel\Kernel;
use Symfony\Component\Routing\RouteCollectionBuilder;
class AppKernel extends Kernel
{
private const CONFIG_EXTS = '.{php,xml,yaml,yml}';
public function registerBundles()
{
$bundles = [
new Symfony\Bundle\FrameworkBundle\FrameworkBundle(),
new Symfony\Bundle\SecurityBundle\SecurityBundle(),
new Symfony\Bundle\TwigBundle\TwigBundle(),
new Symfony\Bundle\MonologBundle\MonologBundle(),
new Symfony\Bundle\SwiftmailerBundle\SwiftmailerBundle(),
new Doctrine\Bundle\DoctrineBundle\DoctrineBundle(),
new Sensio\Bundle\FrameworkExtraBundle\SensioFrameworkExtraBundle(),
new FOS\JsRoutingBundle\FOSJsRoutingBundle(),
new FOS\RestBundle\FOSRestBundle(),
new FOS\UserBundle\FOSUserBundle(),
new JMS\SerializerBundle\JMSSerializerBundle(),
new OldSound\RabbitMqBundle\OldSoundRabbitMqBundle(),
new Oneup\FlysystemBundle\OneupFlysystemBundle(),
new Snc\RedisBundle\SncRedisBundle(),
new Stof\DoctrineExtensionsBundle\StofDoctrineExtensionsBundle(),
new Bazinga\Bundle\JsTranslationBundle\BazingaJsTranslationBundle(),
new AppBundle\AppBundle(),
new CommonBundle\CommonBundle(),
new DocumentBundle\DocumentBundle(),
new DriveBundle\DriveBundle(),
new Craue\FormFlowBundle\CraueFormFlowBundle(),
new BillingBundle\BillingBundle(),
new Liip\ImagineBundle\LiipImagineBundle(),
new SettingsBundle\SettingsBundle(),
new CRMBundle\CRMBundle(),
new APY\DataGridBundle\APYDataGridBundle(),
new \Doctrine\Bundle\MigrationsBundle\DoctrineMigrationsBundle(),
new CalendarBundle\CalendarBundle(),
new \FOS\ElasticaBundle\FOSElasticaBundle(),
new Sg\DatatablesBundle\SgDatatablesBundle(),
new \MigrationBundle\MigrationBundle(),
new Gos\Bundle\WebSocketBundle\GosWebSocketBundle(),
new Gos\Bundle\PubSubRouterBundle\GosPubSubRouterBundle(),
new Lexik\Bundle\JWTAuthenticationBundle\LexikJWTAuthenticationBundle(),
new Gesdinet\JWTRefreshTokenBundle\GesdinetJWTRefreshTokenBundle(),
new Nelmio\CorsBundle\NelmioCorsBundle(),
new Sentry\SentryBundle\SentryBundle(),
new BabDev\PagerfantaBundle\BabDevPagerfantaBundle(),
new Scheb\TwoFactorBundle\SchebTwoFactorBundle(),
new KnpU\OAuth2ClientBundle\KnpUOAuth2ClientBundle(),
];
if ($this->getEnvironment() === Environment::Dev->value) {
$bundles[] = new Nelmio\ApiDocBundle\NelmioApiDocBundle();
}
if (in_array($this->getEnvironment(), [Environment::Dev->value, Environment::AwsDev->value, Environment::Test->value, Environment::Phpunit->value], true)) {
$bundles[] = new Doctrine\Bundle\FixturesBundle\DoctrineFixturesBundle();
$bundles[] = new Symfony\Bundle\MakerBundle\MakerBundle();
}
if (in_array($this->getEnvironment(), [Environment::Test->value, Environment::Phpunit->value], true)) {
$bundles[] = new DAMA\DoctrineTestBundle\DAMADoctrineTestBundle();
$bundles[] = new Zenstruck\Foundry\ZenstruckFoundryBundle();
}
if (in_array($this->getEnvironment(), [Environment::Uat->value, Environment::Dev->value, Environment::AwsDev->value, Environment::AwsPreprod->value, Environment::Test->value, Environment::Phpunit->value], true)) {
$bundles[] = new Symfony\Bundle\DebugBundle\DebugBundle();
$bundles[] = new Symfony\Bundle\WebProfilerBundle\WebProfilerBundle();
}
return $bundles;
}
public function getRootDir()
{
return __DIR__;
}
public function getCacheDir()
{
return dirname(__DIR__) . '/var/cache/' . $this->getEnvironment();
}
public function getLogDir()
{
return dirname(__DIR__) . '/var/logs';
}
public function registerContainerConfiguration(LoaderInterface $loader)
{
$confDir = $this->getProjectDir().'/app/config';
$loader->load($confDir . '/config_' . $this->getEnvironment() . '.yml');
$loader->load($confDir . '/app/*' . self::CONFIG_EXTS, 'glob');
$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');
}
}
/**
* @{inheritdoc}
*/
public function boot()
{
// Using environment variables to set some config var
(new Dotenv(true))->load(__DIR__.'/../.env');
parent::boot();
}
/**
* @inheritDoc
*/
protected function build(ContainerBuilder $container): void
{
$container->registerForAutoconfiguration(TableMergeFieldInterface::class)
->addTag('app.table_merge_field');
$container->registerForAutoconfiguration(AppConfigurationInterface::class)
->addTag('app.configuration');
$container->addCompilerPass(new ExporterPass());
$container->addCompilerPass(new CronPass());
$container->addCompilerPass(new JobCommandPass());
if ($this->getEnvironment() === Environment::Dev->value) {
$container->addCompilerPass(new AwsPass());
$container->addCompilerPass(new DevFilesystemPass());
}
}
}