vendor\project-biz\database-bundle\src\Database\GenericRepositoryFactory.php line 61

Open in your IDE?
  1. <?php
  2. namespace ProjectBiz\DatabaseBundle\Database;
  3. use Doctrine\Persistence\ManagerRegistry;
  4. use ProjectBiz\PortalBundle\Exceptions\PortalException;
  5. use ProjectBiz\DatabaseBundle\Service\RepositoryConfigurationManager;
  6. use ProjectBiz\UserBundle\Service\SecurityContextWrapper;
  7. use Psr\Log\LoggerInterface;
  8. use Symfony\Component\DependencyInjection\Container;
  9. class GenericRepositoryFactory implements GenericRepositoryFactoryInterface
  10. {
  11.     const msgMissingTable 'Die Tabelle »%table%« existiert nicht.';
  12.     protected $doctrine;
  13.     protected $securityContextWrapper;
  14.     protected $tableHelper;
  15.     protected $logger;
  16.     protected $configManager;
  17.     protected $dateTimeFactory;
  18.     protected $serviceContainer;
  19.     protected $repoFactory;
  20.     protected $dateFormat;
  21.     protected $dateTimeFormat;
  22.     /**
  23.      * Construct.
  24.      *
  25.      * @param ManagerRegistry                       $doctrine
  26.      * @param SecurityContextWrapper         $securityContextWrapper
  27.      * @param TableHelper                    $tableHelper
  28.      * @param LoggerInterface                $logger
  29.      * @param RepositoryConfigurationManager $configManager
  30.      */
  31.     public function __construct(
  32.         ManagerRegistry $doctrine,
  33.         SecurityContextWrapper $securityContextWrapper,
  34.         TableHelper $tableHelper,
  35.         LoggerInterface $logger,
  36.         RepositoryConfigurationManager $configManager,
  37.         string $prefix,
  38.         DateTimeFactory $dateTimeFactory,
  39.         Container $serviceContainer,
  40.         $dateFormat,
  41.         $dateTimeFormat,
  42.         $schemaCache,
  43.         $requestStack
  44.     ) {
  45.         $this->doctrine               $doctrine->getManager();
  46.         $this->securityContextWrapper $securityContextWrapper;
  47.         $this->tableHelper            $tableHelper;
  48.         $this->logger                 $logger;
  49.         $this->configManager          $configManager;
  50.         $this->prefix                 $prefix;
  51.         $this->dateTimeFactory        $dateTimeFactory;
  52.         $this->serviceContainer       $serviceContainer;
  53.         $this->dateFormat             $dateFormat;
  54.         $this->dateTimeFormat         $dateTimeFormat;
  55.         $this->schemaCache            $schemaCache;
  56.         $this->requestStack           $requestStack;
  57.     }
  58.     /**
  59.      * @inheritdoc
  60.      */
  61.     public function createGenericRepository($tablename$options = []) : GenericRepository
  62.     {
  63.         // Get a table descriptor. It is just used to determine the MAIN tablename
  64.         $tableDesciptor $this->configManager->lookupDescriptor($tablename);
  65.         if (!$tableDesciptor) {
  66.             if (!in_array($tablename$this->tableHelper->getTables())) {
  67.                 throw new PortalException(self::msgMissingTable, ['%table%' => $tablename], PortalException::MISSING_TABLE);
  68.             }
  69.             $tableDesciptor = new TableDescriptor($tablename$tablename);
  70.         }
  71.         // Let the config manager modify the options / supply defaults
  72.         $options $this->configManager->buildOptions($tablename$options);
  73.         // Create the repository options - use MAIN tablename
  74.         $repositoryOptions = new GenericRepositoryOptions(
  75.             $this->tableHelper->getTableInfo($tableDesciptor->getMainTablename()),
  76.             $options
  77.         );
  78.         // Create the repository
  79.         $repo = new GenericRepository(
  80.             $this->doctrine->getConnection(),
  81.             $this->securityContextWrapper,
  82.             $this->tableHelper->getTableInfo($tablename),
  83.             $repositoryOptions,
  84.             $this->prefix,
  85.             $this->tableHelper,
  86.             $this->logger,
  87.             $this->dateTimeFactory,
  88.             $this->serviceContainer->get('projectbiz.mailer.mail_notifier'),
  89.             $this,
  90.             $this->dateFormat,
  91.             $this->dateTimeFormat,
  92.             $this->schemaCache,
  93.             $this->requestStack,
  94.             $this->serviceContainer
  95.         );
  96.         // Let the configuration manager setup event handler for the repository
  97.         return $this->configManager->afterCreate($tablename$repo);
  98.     }
  99. }