Skip to content

Navigation Menu

Sign in
Appearance settings

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] ContainerInterface cause ClassNotFoundException #52596

Copy link
Copy link
Closed
@connorhu

Description

@connorhu
Issue body actions

Symfony version(s) affected

6.0

Description

This code is generated by DI and cause ClassNotFoundException for me:

<?php

namespace ContainerSF7xQsW;

use Symfony\Component\DependencyInjection\Argument\RewindableGenerator;
use Symfony\Component\DependencyInjection\Exception\RuntimeException;

/**
 * @internal This class has been auto-generated by the Symfony Dependency Injection Component.
 */
class getMailer_TransportFactory_NativeService extends App_KernelDevDebugContainer
{
    /**
     * Gets the private 'mailer.transport_factory.native' shared service.
     *
     * @return \Symfony\Component\Mailer\Transport\NativeTransportFactory
     */
    public static function do($container, $lazyLoad = true)
    {
        include_once \dirname(__DIR__, 4).'/vendor/symfony/mailer/Transport/TransportFactoryInterface.php';
        include_once \dirname(__DIR__, 4).'/vendor/symfony/mailer/Transport/AbstractTransportFactory.php';
        include_once \dirname(__DIR__, 4).'/vendor/symfony/mailer/Transport/NativeTransportFactory.php';

        $a = ($container->services['event_dispatcher'] ?? self::getEventDispatcherService($container));

        if (isset($container->privates['mailer.transport_factory.native'])) {
            return $container->privates['mailer.transport_factory.native'];
        }

        return $container->privates['mailer.transport_factory.native'] = new \Symfony\Component\Mailer\Transport\NativeTransportFactory($a, ($container->privates['.debug.http_client'] ?? self::get_Debug_HttpClientService($container)), ($container->services['monolog.logger.mailer'] ?? $container->get('monolog.logger.mailer', ContainerInterface::NULL_ON_INVALID_REFERENCE)));
    }
}

And the exception is:
Attempted to load class "ContainerInterface" from namespace "ContainerSF7xQsW". Did you forget a "use" statement for e.g. "Symfony\Component\DependencyInjection\ContainerInterface" or "Psr\Container\ContainerInterface"?

The PhpDumper does generates wrong code:

$code = sprintf('$container->get(%s, ContainerInterface::NULL_ON_INVALID_REFERENCE)', $this->doExport($id));

This patch cause the regression: 16fcdda

How to reproduce

To be honest, I don't know how to reproduce this. I also don't fully understand why it only happened to me and not to others.

Possible Solution

Either of the two example codes will generate working code.

$code = sprintf('$container->get(%s, \\%s::NULL_ON_INVALID_REFERENCE)', $this->doExport($id), ContainerInterface::class);

or

$code = sprintf('$container->get(%s, \Symfony\Component\DependencyInjection\ContainerInterface::NULL_ON_INVALID_REFERENCE)', $this->doExport($id));

Additional Context

No response

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

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