From c19d11993dbdc12d16811ef4fe06ef79399a6c4e Mon Sep 17 00:00:00 2001 From: Tian Khamez Date: Sat, 1 Jun 2024 21:44:03 +0200 Subject: [PATCH] Replace Doctrine DebugStack with Middleware. --- backend/src/Container.php | 28 ++++++++++------------------ 1 file changed, 10 insertions(+), 18 deletions(-) diff --git a/backend/src/Container.php b/backend/src/Container.php index 054e3671..a8948ffc 100644 --- a/backend/src/Container.php +++ b/backend/src/Container.php @@ -5,6 +5,7 @@ namespace Neucore; use Doctrine\DBAL\DriverManager; +use Doctrine\DBAL\Logging\Middleware; use Doctrine\ORM\EntityManager; use Doctrine\ORM\EntityManagerInterface; use Doctrine\ORM\ORMSetup; @@ -50,32 +51,23 @@ public static function getDefinitions(): array } else { $conf = $config['doctrine'] ?? []; // it should always be set } - $metaConfig = ORMSetup::createAttributeMetadataConfiguration( - $conf['meta']['entity_paths'], - $conf['meta']['dev_mode'], - $conf['meta']['proxy_dir'] - ); $options = $conf['driver_options']; - $caFile = (string) $options['mysql_ssl_ca']; - $verify = (bool) $options['mysql_verify_server_cert']; + $caFile = (string)$options['mysql_ssl_ca']; + $verify = (bool)$options['mysql_verify_server_cert']; if ($caFile !== '' && (!$verify || is_file($caFile))) { $conf['connection']['driverOptions'] = [ \PDO::MYSQL_ATTR_SSL_CA => $caFile, \PDO::MYSQL_ATTR_SSL_VERIFY_SERVER_CERT => $verify, ]; } + $metaConfig = ORMSetup::createAttributeMetadataConfiguration( + $conf['meta']['entity_paths'], + $conf['meta']['dev_mode'], + $conf['meta']['proxy_dir'] + ); + #$metaConfig->setMiddlewares([new Middleware($c->get(LoggerInterface::class))]); $connection = DriverManager::getConnection($conf['connection'], $metaConfig); - /** @noinspection PhpUnnecessaryLocalVariableInspection */ - $em = new EntityManager($connection, $metaConfig); - /*$logger = new class() extends \Doctrine\DBAL\Logging\DebugStack { - public function startQuery($sql, ?array $params = null, ?array $types = null) - { - error_log($sql); - #error_log(print_r($params, true)); - } - }; - $em->getConnection()->getConfiguration()->setSQLLogger($logger);*/ - return $em; + return new EntityManager($connection, $metaConfig); }, ObjectManager::class => function (ContainerInterface $c) { return $c->get(EntityManagerInterface::class);