<?php
namespace App\Application\EventSubscriber;
use Doctrine\DBAL\Schema\SchemaException;
use Doctrine\ORM\Tools\Event\GenerateSchemaEventArgs;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
/**
* Class DoctrineViewsIgnoreListener
*
* @package App\Application\EventSubscriber
*/
class DoctrineViewsIgnoreSubscriber implements EventSubscriberInterface
{
public const DOCTRINE_IGNORED_TABLE = [
'v_person_stat',
'v_detail_person',
'v_ownership_request',
'v_promo_code',
'v_point_of_interest',
'v_point_of_interest_pictures',
'v_uncertified_comment',
];
/**
* Returns an array of events this subscriber wants to listen to.
*
* @return string[]
*/
public static function getSubscribedEvents(): array
{
return [
'postGenerateSchema' => 'onPostGenerateSchema',
'postDropSchema' => 'onPostGenerateSchema',
'postCreateSchema' => 'onPostGenerateSchema',
'postUpdateSchema' => 'onPostGenerateSchema',
'postPersistSchema' => 'onPostGenerateSchema',
];
}
/**
* @param GenerateSchemaEventArgs $args
*
* @throws SchemaException
*/
public function postGenerateSchema(GenerateSchemaEventArgs $args): void
{
$filteredIgnoredTables = array_map(
static function ($item) {
return $item;
},
self::DOCTRINE_IGNORED_TABLE,
);
$schema = $args->getSchema();
$tableNames = $schema->getTables();
foreach ($tableNames as $table) {
if (in_array($table->getName(), $filteredIgnoredTables)) {
// remove table from schema
$schema->dropTable($table->getName());
}
}
}
}