From cf01c50b5ec798dd3c476d226890166957047f34 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jan=20Pavl=C3=AD=C4=8Dek?= Date: Thu, 26 Mar 2026 18:28:31 +0100 Subject: [PATCH] Added support for schmea tool filtering --- lib/Common/EntityManagerFactory.php | 23 ++++++++++++++++++++--- 1 file changed, 20 insertions(+), 3 deletions(-) diff --git a/lib/Common/EntityManagerFactory.php b/lib/Common/EntityManagerFactory.php index 52d6d0a..0677860 100755 --- a/lib/Common/EntityManagerFactory.php +++ b/lib/Common/EntityManagerFactory.php @@ -3,6 +3,7 @@ namespace Common; use Doctrine\Common\Proxy\AbstractProxyFactory; +use Doctrine\DBAL\Schema\AbstractNamedObject; use Doctrine\ORM\ORMSetup; use Doctrine\ORM\EntityManager; use Doctrine\DBAL\DriverManager; @@ -18,8 +19,14 @@ use RuntimeException; */ class EntityManagerFactory { - public static function create(array $params, bool $dev_mode = false, array $middlewares = [], array $filters = [], array $event_subscribers = []) : EntityManager - { + public static function create( + array $params, + bool $dev_mode = false, + array $middlewares = [], + array $filters = [], + array $event_subscribers = [], + array $skip_names_in_schema_tool = [] + ) : EntityManager { self::checkRequiredParams($params, ['paths', 'database', 'proxy_dir']); // workaround for doctrine console commands requiring active database connection - @@ -28,7 +35,7 @@ class EntityManagerFactory if (defined('STDIN') && @$_SERVER['argv'][1] == 'orm:generate-proxies') { $params['database']['serverVersion'] = '14'; } - +w $paths = $params['paths']; $connection = $params['database']; @@ -44,6 +51,16 @@ class EntityManagerFactory } $connection = DriverManager::getConnection($params['database'], $config); + + // add schema access filter, if passed - this allows for controlling which object in database are considered + // by doctrine when generating SQL scripts to sync with metadata + if ($skip_names_in_schema_tool) { + $connection->getConfiguration()->setSchemaAssetsFilter(function (AbstractNamedObject|string $object) use ($skip_names_in_schema_tool) { + $object_name = is_string($object) ? $object : $object->getObjectName()->toString(); + return !in_array($object_name, $skip_names_in_schema_tool); + }); + } + $em = new EntityManager($connection, $config); if ($event_subscribers) {