Skip to content

Installing the bundle without Doctrine causes an error #248

@maitre-hibou

Description

@maitre-hibou

Hello there,

I'm trying to install the bundle on a Symfony 6.4 project.

Following the documentation, I would like to install oauth2-server-bundle with a custom persistence layer as I do not want to use Doctrine. However, when I ran the command :

composer require league/oauth2-server-bundle

I get the following error :

!!  Symfony\Component\ErrorHandler\Error\ClassNotFoundError {#322
!!    #message: """
!!      Attempted to load class "DoctrineOrmMappingsPass" from namespace "Doctrine\Bundle\DoctrineBundle\DependencyInjection\Compiler".\n
!!      Did you forget a "use" statement for another namespace?
!!      """
!!    #code: 0
!!    #file: "./vendor/league/oauth2-server-bundle/src/LeagueOAuth2ServerBundle.php"
!!    #line: 47
!!    trace: {
!!      ./vendor/league/oauth2-server-bundle/src/LeagueOAuth2ServerBundle.php:47 { …}
!!      ./vendor/league/oauth2-server-bundle/src/LeagueOAuth2ServerBundle.php:27 { …}
!!      ./vendor/symfony/http-kernel/Kernel.php:643 { …}
!!      ./vendor/symfony/http-kernel/Kernel.php:616 { …}
!!      ./vendor/symfony/http-kernel/Kernel.php:506 { …}
!!      ./vendor/symfony/http-kernel/Kernel.php:772 { …}
!!      ./vendor/symfony/http-kernel/Kernel.php:126 { …}
!!      ./vendor/symfony/framework-bundle/Console/Application.php:190 { …}
!!      ./vendor/symfony/framework-bundle/Console/Application.php:72 { …}
!!      ./vendor/symfony/console/Application.php:175 { …}
!!      ./vendor/symfony/runtime/Runner/Symfony/ConsoleApplicationRunner.php:49 { …}
!!      ./vendor/autoload_runtime.php:29 { …}
!!      ./bin/console:15 {
!!        ›
!!        › require_once dirname(__DIR__).'/vendor/autoload_runtime.php';
!!        ›
!!        arguments: {
!!          "/home/xpr/Code/api/vendor/autoload_runtime.php"
!!        }
!!      }
!!    }
!!  }
!!  2025-09-01T13:48:01+00:00 [critical] Uncaught Error: Class "Doctrine\Bundle\DoctrineBundle\DependencyInjection\Compiler\DoctrineOrmMappingsPass" not found

I tried to look at the bundle and it seems that it assumes that doctrine is enabled by default :

// vendor/league/oauth2-server-bundle/src/LeagueOAuth2ServerBundle.php

public function build(ContainerBuilder $container)
{
    parent::build($container);

    $this->configureDoctrineExtension($container);
    $this->configureSecurityExtension($container);
}

//...

private function configureDoctrineExtension(ContainerBuilder $container): void
{
    $container->addCompilerPass(
        new DoctrineOrmMappingsPass(
            new Reference(Driver::class),
            ['League\Bundle\OAuth2ServerBundle\Model'],
            ['league.oauth2_server.persistence.doctrine.manager'],
            'league.oauth2_server.persistence.doctrine.enabled'
        )
    );

    $container->addCompilerPass(new EncryptionKeyPass());
}

Digging more, I also found that the bundle assumes Doctrine is installed when the configuration league_oauth2_server.persistence.doctrine is set (this is the default).

// vendor/league/oauth2-server-bundle/src/DependencyInjection/LeagueOAuth2ServerExtension.php

private function assertRequiredBundlesAreEnabled(ContainerBuilder $container): void
{
    $requiredBundles = [
        'security' => SecurityBundle::class,
    ];

    if ($container->hasParameter('league.oauth2_server.persistence.doctrine.enabled')) {
        $requiredBundles['doctrine'] = DoctrineBundle::class;
    }

    foreach ($requiredBundles as $bundleAlias => $requiredBundle) {
        if (!$container->hasExtension($bundleAlias)) {
            throw new \LogicException(\sprintf('Bundle \'%s\' needs to be enabled in your application kernel.', $requiredBundle));
        }
    }
}

What should I do next ? Anyone already had this issue ?

Thanks !

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions