vendor\project-biz\database-bundle\src\Database\TableHelper.php line 36

Open in your IDE?
  1. <?php
  2. namespace ProjectBiz\DatabaseBundle\Database;
  3. use ProjectBiz\DatabaseBundle\Service\RepositoryConfigurationManager;
  4. use ProjectBiz\UserBundle\Service\SecurityContextWrapper;
  5. use Symfony\Contracts\Translation\TranslatorInterface;
  6. class TableHelper implements TableHelperInterface
  7. {
  8.     public $securityContext;
  9.     protected $configManager;
  10.     protected $databaseSchemaCache;
  11.     protected $translator;
  12.     protected $tableAndViewList;
  13.     protected $cachedViewList;
  14.     protected $cachedTableLists = [];
  15.     protected $cachedInfo       = [];
  16.     public function __construct(
  17.         SecurityContextWrapper $securityContext,
  18.         RepositoryConfigurationManager $configManager,
  19.         DatabaseSchemaCache $databaseSchemaCache,
  20.         TranslatorInterface $translator
  21.     ) {
  22.         $this->securityContext     $securityContext;
  23.         $this->configManager       $configManager;
  24.         $this->databaseSchemaCache $databaseSchemaCache;
  25.         $this->translator          $translator;
  26.     }
  27.     /**
  28.      * @inheritdoc
  29.      */
  30.     public function getTableInfo($tablename)
  31.     {
  32.         if (!isset($this->cachedInfo[$tablename])) {
  33.             if ($this->isView($tablename)) {
  34.                 $this->cachedInfo[$tablename] = new ViewInfo(
  35.                     $tablename,
  36.                     $this->databaseSchemaCache,
  37.                     $this,
  38.                     $this->translator
  39.                 );
  40.             } else {
  41.                 $this->cachedInfo[$tablename] = new TableInfo(
  42.                     $this->getTableDescriptor($tablename),
  43.                     $this->databaseSchemaCache,
  44.                     $this,
  45.                     $this->translator
  46.                 );
  47.             }
  48.         }
  49.         return $this->cachedInfo[$tablename];
  50.     }
  51.     /**
  52.      * @inheritdoc
  53.      */
  54.     public function isView($tablename)
  55.     {
  56.         return in_array($tablename$this->getViews());
  57.     }
  58.     /**
  59.      * @return array List of views in database
  60.      */
  61.     protected function getViews()
  62.     {   
  63.         return $this->databaseSchemaCache->getViews();
  64.     }
  65.     /**
  66.      * @param $tablename
  67.      *
  68.      * @return TableDescriptor
  69.      */
  70.     protected function getTableDescriptor($tablename)
  71.     {
  72.         $tableDesciptor $this->configManager->lookupDescriptor($tablename);
  73.         if (!$tableDesciptor) {
  74.             $tableDesciptor = new TableDescriptor($tablename$tablename);
  75.         }
  76.         return $tableDesciptor;
  77.     }
  78.     /**
  79.      * @inheritdoc
  80.      */
  81.     public function getTables($withViews true$withSynTables true)
  82.     {
  83.         // Determine index for cached list:
  84.         // 0 = only tables
  85.         // 1 = tables and syn tables
  86.         // 2 = tables and views
  87.         // 3 = tables, syn tables and views
  88.         $index | ($withSynTables?1:0) | ($withViews?2:0);
  89.         if (!isset($this->cachedTableLists[$index])) {
  90.             // 1. Collect Database-Tables starting with prefix
  91.             $tableList $this->databaseSchemaCache->getTables();
  92.             // 2. merge the synthetic tables found in RepositoryConfigurationManager
  93.             if ($withSynTables) {
  94.                 $tableList array_merge($tableList$this->configManager->getTables());
  95.             }
  96.             // 3. Merge the views
  97.             if ($withViews) {
  98.                 $tableList array_merge($tableList$this->getViews());
  99.             }
  100.             $this->cachedTableLists[$index] = $tableList;
  101.         }
  102.         return $this->cachedTableLists[$index];
  103.     }
  104.     /**
  105.      * @inheritdoc
  106.      */
  107.     public function getColumnNameSubString($column)
  108.     {
  109.         return substr($columnstrpos($column'_') + 1);
  110.     }
  111. }