Skip to content
Permalink
Browse files

Flexible service syntax for sqlLogger

  • Loading branch information
mabar authored and f3l1x committed Dec 4, 2019
1 parent 4c41e69 commit d37aa133406139528d58a37e4727d5aef9942b8c
Showing with 12 additions and 4 deletions.
  1. +12 −4 src/DI/DbalExtension.php
@@ -39,7 +39,7 @@ public function getConfigSchema(): Schema
'sourcePaths' => Expect::arrayOf('string'),
]),
'configuration' => Expect::structure([
'sqlLogger' => Expect::type('string|' . Statement::class),
'sqlLogger' => Expect::anyOf(Expect::string(), Expect::array(), Expect::type(Statement::class)),
'resultCache' => Expect::anyOf(Expect::string(), Expect::array(), Expect::type(Statement::class)),
'filterSchemaAssetsExpression' => Expect::string()->nullable(),
'autoCommit' => Expect::bool(true),
@@ -70,18 +70,26 @@ public function loadDoctrineConfiguration(): void
$config = $this->config->configuration;
$definitionsHelper = new ExtensionDefinitionsHelper($this->compiler);

$logger = $builder->addDefinition($this->prefix('logger'))
$loggerDefinition = $builder->addDefinition($this->prefix('logger'))
->setType(LoggerChain::class)
->setAutowired('self');

$configuration = $builder->addDefinition($this->prefix('configuration'));
$configuration->setFactory(Configuration::class)
->setAutowired(false)
->addSetup('setSQLLogger', [$this->prefix('@logger')]);
->addSetup('setSQLLogger', [$loggerDefinition]);

// SqlLogger (append to chain)
if ($config->sqlLogger !== null) {
$logger->addSetup('addLogger', [$config->sqlLogger]);
$configLoggerName = $this->prefix('logger.config');
$configLoggerDefinition = $definitionsHelper->getDefinitionFromConfig($config->sqlLogger, $configLoggerName);

// If service is extension specific, then disable autowiring
if ($configLoggerDefinition instanceof Definition && $configLoggerDefinition->getName() === $configLoggerName) {
$configLoggerDefinition->setAutowired(false);
}

$loggerDefinition->addSetup('addLogger', [$configLoggerDefinition]);
}

// ResultCache

0 comments on commit d37aa13

Please sign in to comment.
You can’t perform that action at this time.