|
|
|
@ -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) { |
|
|
|
|