Skip to content

Navigation Menu

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

[DependencyInjection] Fix ignore invalid_reference behavior param for the some services #57561

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: 5.4
Choose a base branch
Loading
from

Conversation

vtsykun
Copy link
Contributor

@vtsykun vtsykun commented Jun 27, 2024

Q A
Branch? 5.4
Bug fix? yes
New feature? -
Deprecations? -
Issues Fix #57560
License MIT

This bug has more than 5 years old, but it make possible to reproduce after introducing a new console command profiler.

PHP DI dumper may ignore invalid reference behavior in the some cases. See example.

    $container->services()
        ->set('data_collector.config', ConfigDataCollector::class)
            ->call('setKernel', [service('kernel')->ignoreOnInvalid()])
            ->tag('data_collector', ['template' => '@WebProfiler/Collector/config.html.twig', 'id' => 'config', 'priority' => -255])

As you can see ignoreOnInvalid option is dropped on this line

$container->get('kernel')
    protected static function get_Container_Private_ProfilerService($container)
    {
        $a = new \Symfony\Bridge\Monolog\Logger('profiler');
        $a->pushProcessor(($container->privates['oro_logger.processor.log_message'] ??= new \Monolog\Processor\PsrLogMessageProcessor()));
        $a->pushProcessor(($container->privates['oro_message_queue.log.processor.add_consumer_state'] ?? self::getOroMessageQueue_Log_Processor_AddConsumerStateService($container)));
        $a->pushHandler(($container->privates['monolog.handler.main'] ?? self::getMonolog_Handler_MainService($container)));
        $a->pushHandler(($container->privates['oro_message_queue.log.handler.console'] ?? self::getOroMessageQueue_Log_Handler_ConsoleService($container)));
        ($container->privates['debug.debug_logger_configurator'] ?? self::getDebug_DebugLoggerConfiguratorService($container))->pushDebugLogger($a);

        $container->services['.container.private.profiler'] = $instance = new \Oro\Bundle\PlatformBundle\Profiler\ConfigurableProfiler(new \Oro\Bundle\PlatformBundle\Profiler\RepeatableFileProfilerStorage(('file:'.$container->targetDir.''.'/profiler')), $a, true);

        $b = ($container->services['kernel'] ?? $container->get('kernel'));
        $c = ($container->services['.virtual_request_stack'] ?? self::get_VirtualRequestStackService($container));
        $d = new \Symfony\Component\HttpClient\DataCollector\HttpClientDataCollector();
        $d->registerClient('http_client', ($container->privates['.debug.http_client'] ?? self::get_Debug_HttpClientService($container)));
        $d->registerClient('hwi_oauth.http_client', ($container->privates['.debug.hwi_oauth.http_client'] ?? self::get_Debug_HwiOauth_HttpClientService($container)));
        $e = new \Doctrine\Bundle\DoctrineBundle\DataCollector\DoctrineDataCollector(($container->services['doctrine'] ?? self::getDoctrineService($container)), true, NULL);

        $f = ($container->privates['doctrine.dbal.logger.profiling.default'] ??= new \Doctrine\DBAL\Logging\DebugStack());
        $g = ($container->privates['doctrine.dbal.logger.profiling.sql_validator'] ??= new \Doctrine\DBAL\Logging\DebugStack());
        $h = ($container->privates['doctrine.dbal.logger.profiling.system'] ??= new \Doctrine\DBAL\Logging\DebugStack());

        $e->addLogger('default', $f);
        $e->addLogger('sql_validator', $g);
        $e->addLogger('system', $h);
        $i = new \Oro\Bundle\EntityBundle\DataCollector\DuplicateQueriesDataCollector();
        $i->addLogger('default', $f);
        $i->addLogger('sql_validator', $g);
        $i->addLogger('system', $h);
        $j = new \Symfony\Component\HttpKernel\DataCollector\ConfigDataCollector();
        if ($container->has('kernel')) {
            $j->setKernel($b);
        }

@carsonbot carsonbot added this to the 5.4 milestone Jun 27, 2024
@carsonbot carsonbot changed the title [Di] Fix ignore invalid_reference behavior param for the some services [DependencyInjection] Fix ignore invalid_reference behavior param for the some services Jun 27, 2024
@@ -1009,7 +1009,7 @@ private function addInlineReference(string $id, Definition $definition, string $
$name = $this->getNextVariableName();
$this->referenceVariables[$targetId] = new Variable($name);

$reference = ContainerInterface::EXCEPTION_ON_INVALID_REFERENCE >= $behavior ? new Reference($targetId, $behavior) : null;
$reference = ContainerInterface::EXCEPTION_ON_INVALID_REFERENCE !== $behavior ? new Reference($targetId, $behavior) : null;
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Perhaps, there was just a typo here and the author meant $behavior >= ContainerInterface::EXCEPTION_ON_INVALID_REFERENCE.

The bug was hidden for a long time because it can only be reproduced for "synthetic" services like kernel and in specific cases. But the other services replaced by null on optimization step before

@nicolas-grekas
Copy link
Member

So, this line:
$b = ($container->services['kernel'] ?? $container->get('kernel'));
should be actually
$b = ($container->services['kernel'] ?? $container->get('kernel', ContainerInterface::NULL_ON_INVALID_REFERENCE));

That's what you mean?

I think this comparison in PhpDumper is on purpose but it's quite possible that we forgot about synthetic services.
Can you please add a test case?

@nicolas-grekas
Copy link
Member

@vtsykun did you check my comment? WDYT?

@vtsykun
Copy link
Contributor Author

vtsykun commented Jul 26, 2024

So, this line $b = ($container->services['kernel'] ?? $container->get('kernel')); should be actually $b = ($container->services['kernel'] ?? $container->get('kernel', ContainerInterface::NULL_ON_INVALID_REFERENCE));

Yes, exactly.

Ok I'll create a test case

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants
Morty Proxy This is a proxified and sanitized view of the page, visit original site.