Skip to content

Commit

Permalink
Replace Doctrine DebugStack with Middleware.
Browse files Browse the repository at this point in the history
  • Loading branch information
tkhamez committed Jun 1, 2024
1 parent a613083 commit c19d119
Showing 1 changed file with 10 additions and 18 deletions.
28 changes: 10 additions & 18 deletions backend/src/Container.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
Expand Down

0 comments on commit c19d119

Please sign in to comment.