src/Application/EventSubscriber/DoctrineViewsIgnoreSubscriber.php line 14

Open in your IDE?
  1. <?php
  2. namespace App\Application\EventSubscriber;
  3. use Doctrine\DBAL\Schema\SchemaException;
  4. use Doctrine\ORM\Tools\Event\GenerateSchemaEventArgs;
  5. use Symfony\Component\EventDispatcher\EventSubscriberInterface;
  6. /**
  7.  * Class DoctrineViewsIgnoreListener
  8.  *
  9.  * @package App\Application\EventSubscriber
  10.  */
  11. class DoctrineViewsIgnoreSubscriber implements EventSubscriberInterface
  12. {
  13.     public const DOCTRINE_IGNORED_TABLE = [
  14.         'v_person_stat',
  15.         'v_detail_person',
  16.         'v_ownership_request',
  17.         'v_promo_code',
  18.         'v_point_of_interest',
  19.         'v_point_of_interest_pictures',
  20.         'v_uncertified_comment',
  21.     ];
  22.     /**
  23.      * Returns an array of events this subscriber wants to listen to.
  24.      *
  25.      * @return string[]
  26.      */
  27.     public static function getSubscribedEvents(): array
  28.     {
  29.         return [
  30.             'postGenerateSchema' => 'onPostGenerateSchema',
  31.             'postDropSchema' => 'onPostGenerateSchema',
  32.             'postCreateSchema' => 'onPostGenerateSchema',
  33.             'postUpdateSchema' => 'onPostGenerateSchema',
  34.             'postPersistSchema' => 'onPostGenerateSchema',
  35.         ];
  36.     }
  37.     /**
  38.      * @param GenerateSchemaEventArgs $args
  39.      *
  40.      * @throws SchemaException
  41.      */
  42.     public function postGenerateSchema(GenerateSchemaEventArgs $args): void
  43.     {
  44.         $filteredIgnoredTables array_map(
  45.             static function ($item) {
  46.                 return $item;
  47.             },
  48.             self::DOCTRINE_IGNORED_TABLE,
  49.         );
  50.         $schema $args->getSchema();
  51.         $tableNames $schema->getTables();
  52.         foreach ($tableNames as $table) {
  53.             if (in_array($table->getName(), $filteredIgnoredTables)) {
  54.                 // remove table from schema
  55.                 $schema->dropTable($table->getName());
  56.             }
  57.         }
  58.     }
  59. }