vendor/nellapp/sdk-bundle/src/NellappSDKBundle.php line 19

Open in your IDE?
  1. <?php
  2. namespace Nellapp\Bundle\SDKBundle;
  3. use Doctrine\Bundle\DoctrineBundle\DependencyInjection\Compiler\DoctrineOrmMappingsPass;
  4. use Nellapp\Bundle\SDKBundle\Assignable\Permission\AssignableTypeAccessInterface;
  5. use Nellapp\Bundle\SDKBundle\Assignable\Permission\AssignableTypeAccessRegistry;
  6. use Nellapp\Bundle\SDKBundle\DependencyInjection\Compiler\AuthProviderPass;
  7. use Nellapp\Bundle\SDKBundle\DependencyInjection\Compiler\DevelopersDoctrineMappingPass;
  8. use Nellapp\Bundle\SDKBundle\DependencyInjection\Compiler\DevelopersMappingEnablePass;
  9. use Nellapp\Bundle\SDKBundle\DependencyInjection\Compiler\GlobalEntityPass;
  10. use Nellapp\Bundle\SDKBundle\DependencyInjection\Compiler\GoogleMappingPass;
  11. use Nellapp\Bundle\SDKBundle\DependencyInjection\Compiler\ReconnectingRedisSessionHandlerPass;
  12. use Nellapp\Bundle\SDKBundle\GlobalGetters\GlobalEntityKeys;
  13. use Symfony\Component\DependencyInjection\ContainerBuilder;
  14. use Symfony\Component\HttpKernel\Bundle\Bundle;
  15. use Symfony\Component\DependencyInjection\Compiler\PassConfig;
  16. class NellappSDKBundle extends Bundle
  17. {
  18. public function build(ContainerBuilder $container)
  19. {
  20. $container->addCompilerPass(new GlobalEntityPass());
  21. $container->addCompilerPass(new AuthProviderPass());
  22. $container->addCompilerPass(new ReconnectingRedisSessionHandlerPass());
  23. $container->addCompilerPass(
  24. new DevelopersDoctrineMappingPass(),
  25. PassConfig::TYPE_BEFORE_OPTIMIZATION,
  26. 1000
  27. );
  28. $this->doctrineMappingConfig($container);
  29. foreach (GlobalEntityKeys::GLOBAL_REPOSITORIES as $globalKey => $globalRepository) {
  30. if ($globalRepository !== null) {
  31. $container->registerForAutoconfiguration($globalRepository)
  32. ->addTag(sprintf(GlobalEntityPass::REPOSITORY_TAG_NAME, $globalKey));
  33. }
  34. }
  35. // Every assignable type access rule is tagged, wherever it is declared
  36. // (SDK bundle or app), and feeds the assignable listing scopes.
  37. $container->registerForAutoconfiguration(AssignableTypeAccessInterface::class)
  38. ->addTag(AssignableTypeAccessRegistry::TAG);
  39. }
  40. private function doctrineMappingConfig(ContainerBuilder $container): void
  41. {
  42. $configs = [
  43. 'nellapp_sdk.activity_feed.enable' => [
  44. 'namespaces' => [
  45. 'Nellapp\Bundle\SDKBundle\ActivityFeed\Entity',
  46. ],
  47. 'directories' => [
  48. realpath(__DIR__ . '/ActivityFeed/Entity'),
  49. ]
  50. ],
  51. 'nellapp_sdk.auth.enable' => [
  52. 'namespaces' => [
  53. 'Nellapp\Bundle\SDKBundle\Auth\Entity',
  54. ],
  55. 'directories' => [
  56. realpath(__DIR__ . '/Auth/Entity'),
  57. ],
  58. ],
  59. 'nellapp_sdk.channel.enable' => [
  60. 'namespaces' => [
  61. 'Nellapp\Bundle\SDKBundle\Channel\Entity',
  62. ],
  63. 'directories' => [
  64. realpath(__DIR__ . '/Channel/Entity'),
  65. ],
  66. ],
  67. [
  68. 'namespaces' => [
  69. 'Nellapp\Bundle\SDKBundle\Permission\Entity',
  70. ],
  71. 'directories' => [
  72. realpath(__DIR__ . '/Permission/Entity'),
  73. ]
  74. ],
  75. 'nellapp_sdk.google.enable' => [
  76. 'namespaces' => [
  77. 'Nellapp\Bundle\SDKBundle\Google\Entity',
  78. ],
  79. 'directories' => [
  80. realpath(__DIR__ . '/Google/Entity'),
  81. ]
  82. ],
  83. 'nellapp_sdk.assignable.enable' => [
  84. 'namespaces' => [
  85. 'Nellapp\Bundle\SDKBundle\Assignable\Entity',
  86. ],
  87. 'directories' => [
  88. realpath(__DIR__ . '/Assignable/Entity'),
  89. ]
  90. ]
  91. ];
  92. $configs['nellapp_sdk.developers.api.default_channel_user_access_mapping'] = [
  93. 'namespaces' => [
  94. 'Nellapp\\Bundle\\SDKBundle\\Developers\\Entity\\ApiTokenChannelUserAccess',
  95. ],
  96. 'directories' => [
  97. realpath(__DIR__ . '/Developers/Entity/ApiTokenChannelUserAccess'),
  98. ],
  99. ];
  100. foreach ($configs as $param => $config) {
  101. $container->addCompilerPass(DoctrineOrmMappingsPass::createAttributeMappingDriver(
  102. namespaces: $config['namespaces'],
  103. directories: $config['directories'],
  104. enabledParameter: is_string($param) ? $param : false,
  105. ));
  106. }
  107. }
  108. }