<?php
namespace Nellapp\Bundle\SDKBundle;
use Doctrine\Bundle\DoctrineBundle\DependencyInjection\Compiler\DoctrineOrmMappingsPass;
use Nellapp\Bundle\SDKBundle\DependencyInjection\Compiler\GlobalEntityPass;
use Nellapp\Bundle\SDKBundle\GlobalGetters\GlobalEntityKeys;
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\HttpKernel\Bundle\Bundle;
class NellappSDKBundle extends Bundle
{
public function build(ContainerBuilder $container)
{
$container->addCompilerPass(new GlobalEntityPass());
$this->doctrineMappingConfig($container);
foreach (GlobalEntityKeys::GLOBAL_REPOSITORIES as $globalKey => $globalRepository) {
if ($globalRepository !== null) {
$container->registerForAutoconfiguration($globalRepository)
->addTag(sprintf(GlobalEntityPass::REPOSITORY_TAG_NAME, $globalKey));
}
}
}
private function doctrineMappingConfig(ContainerBuilder $container): void
{
$configs = [
'nellapp_sdk.auth.enable' => [
'namespaces' => [
'Nellapp\Bundle\SDKBundle\Auth\Entity',
],
'directories' => [
realpath(__DIR__ . '/Auth/Entity'),
],
],
'nellapp_sdk.channel.enable' => [
'namespaces' => [
'Nellapp\Bundle\SDKBundle\Channel\Entity',
],
'directories' => [
realpath(__DIR__ . '/Channel/Entity'),
],
],
[
'namespaces' => [
'Nellapp\Bundle\SDKBundle\Permission\Entity',
],
'directories' => [
realpath(__DIR__ . '/Permission/Entity'),
]
]
];
foreach ($configs as $param => $config) {
$container->addCompilerPass(DoctrineOrmMappingsPass::createAttributeMappingDriver(
namespaces: $config['namespaces'],
directories: $config['directories'],
enabledParameter: is_string($param) ? $param : false,
));
}
}
}