Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 20 additions & 2 deletions DependencyInjection/Compiler/LoggerChannelPass.php
Original file line number Diff line number Diff line change
Expand Up @@ -47,15 +47,15 @@ public function process(ContainerBuilder $container)

foreach ($definition->getArguments() as $index => $argument) {
if ($argument instanceof Reference && 'logger' === (string) $argument) {
$definition->replaceArgument($index, new Reference($loggerId, $argument->getInvalidBehavior(), $argument->isStrict()));
$definition->replaceArgument($index, $this->changeReference($argument, $loggerId));
}
}

$calls = $definition->getMethodCalls();
foreach ($calls as $i => $call) {
foreach ($call[1] as $index => $argument) {
if ($argument instanceof Reference && 'logger' === (string) $argument) {
$calls[$i][1][$index] = new Reference($loggerId, $argument->getInvalidBehavior(), $argument->isStrict());
$calls[$i][1][$index] = $this->changeReference($argument, $loggerId);
}
}
}
Expand Down Expand Up @@ -112,4 +112,22 @@ protected function createLogger($channel, $loggerId, ContainerBuilder $container
$this->channels[] = $channel;
}
}

/**
* Creates a copy of a reference and alters the service ID.
*
* @param Reference $reference
* @param string $serviceId
*
* @return Reference
*/
private function changeReference(Reference $reference, $serviceId)
{
if (method_exists($reference, 'isStrict')) {
// Stay compatible with Symfony 2
return new Reference($serviceId, $reference->getInvalidBehavior(), $reference->isStrict());
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This still triggers alot of deprecation warnings when warming the cache in the standard edition. We need a different solution. We could just use $reference->isStrict(false) to prevent the deprecation warning. Or can we not ignore the strict flag completely? It's rather unlikely to have a scope problem with a logger...

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

$reference->isStrict(false) is probably the way to go. Ignoring the strict flag might cause problems with bundles that still rely on the deprecated behavior.

}

return new Reference($serviceId, $reference->getInvalidBehavior());
}
}