Commit 06b00acf authored by Avris's avatar Avris

v4.0

parent 2db54908
......@@ -13,11 +13,13 @@ use Doctrine\ORM\EntityManager;
use Doctrine\ORM\Tools\Console\Helper\EntityManagerHelper;
use Doctrine\ORM\Tools\Setup;
use Psr\Log\LoggerInterface;
use Doctrine\ORM\Tools\Console\Command as ORMCommand;
use Doctrine\DBAL\Tools\Console\Command as DBALCommand;
class Doctrine implements EventSubscriberInterface
{
/** @var EntityManager */
protected $entityManager;
private $entityManager;
public function __construct(
Bag $configDatabase,
......@@ -25,6 +27,7 @@ class Doctrine implements EventSubscriberInterface
string $proxyDir,
array $modules,
LoggerInterface $logger,
DoctrineLogger $doctrineLogger,
Cache $cache = null
) {
$dirs = [];
......@@ -36,7 +39,7 @@ class Doctrine implements EventSubscriberInterface
}
$config = Setup::createAnnotationMetadataConfiguration($dirs, $envAppDebug, $proxyDir, $cache, false);
$config->setSQLLogger(new DoctrineLogger($logger));
$config->setSQLLogger($doctrineLogger);
$this->entityManager = EntityManager::create($configDatabase->all(), $config);
......@@ -96,15 +99,15 @@ class Doctrine implements EventSubscriberInterface
$helperSet->set(new ConnectionHelper($this->entityManager->getConnection()), 'db');
$helperSet->set(new EntityManagerHelper($this->entityManager), 'em');
$app->add((new \Doctrine\DBAL\Tools\Console\Command\RunSqlCommand())->setName('db:query:sql'));
$app->add((new \Doctrine\ORM\Tools\Console\Command\RunDqlCommand())->setName('db:query:dql'));
$app->add((new DBALCommand\RunSqlCommand())->setName('db:query:sql'));
$app->add((new ORMCommand\RunDqlCommand())->setName('db:query:dql'));
$app->add((new \Doctrine\ORM\Tools\Console\Command\SchemaTool\CreateCommand())->setName('db:schema:create'));
$app->add((new \Doctrine\ORM\Tools\Console\Command\SchemaTool\UpdateCommand())->setName('db:schema:update'));
$app->add((new \Doctrine\ORM\Tools\Console\Command\SchemaTool\DropCommand())->setName('db:schema:drop'));
$app->add((new \Doctrine\ORM\Tools\Console\Command\ValidateSchemaCommand())->setName('db:schema:validate'));
$app->add((new ORMCommand\SchemaTool\CreateCommand())->setName('db:schema:create'));
$app->add((new ORMCommand\SchemaTool\UpdateCommand())->setName('db:schema:update'));
$app->add((new ORMCommand\SchemaTool\DropCommand())->setName('db:schema:drop'));
$app->add((new ORMCommand\ValidateSchemaCommand())->setName('db:schema:validate'));
$app->add((new \Doctrine\ORM\Tools\Console\Command\GenerateProxiesCommand())->setName('db:generate:proxies'));
$app->add((new ORMCommand\GenerateProxiesCommand())->setName('db:generate:proxies'));
}
public function getSubscribedEvents(): iterable
......
......@@ -2,6 +2,7 @@
namespace Avris\Micrus\Doctrine;
use Doctrine\DBAL\Logging\SQLLogger;
use Monolog\Logger;
use Psr\Log\LoggerInterface;
class DoctrineLogger implements SQLLogger
......@@ -11,16 +12,15 @@ class DoctrineLogger implements SQLLogger
public function __construct(LoggerInterface $logger)
{
$this->logger = $logger;
$this->logger = $logger instanceof Logger ? $logger->withName('doctrine') : $logger;
}
public function startQuery($sql, array $params = null, array $types = null)
{
$this->logger->notice('[SQL] ' . $sql . ' | ' . @json_encode($params) . ' | ' . @json_encode($types));
$this->logger->notice($sql, $params ?: []);
}
public function stopQuery()
{
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment