DASPRiD / container-interop-doctrine

Doctrine factories for container-interop
107 stars 25 forks source link

[CLI] [Semantical Error] The annotation "@Doctrine\ORM\Mapping\Entity" in class App\Entity\User does not exist, or could not be auto-loaded. #33

Closed guillaumemaka closed 6 years ago

guillaumemaka commented 6 years ago

Hi,

I try to use the doctrine orm:validate-schema cli command and I got this error:

[Semantical Error] The annotation "@Doctrine\ORM\Mapping\Entity" in class App\Entity\User does not exist, or could not be auto-loaded.

My cli-config.php

// with or without I got the sam error
// require_once __DIR__ .'/vendor/autoload.php';

$container = require 'config/container.php';
$container->setAlias('Config', 'config');

return new \Symfony\Component\Console\Helper\HelperSet([
    'em' => new \Doctrine\ORM\Tools\Console\Helper\EntityManagerHelper(
        $container->get('doctrine.entity_manager.orm_default')
    ),
    'db' => new \Doctrine\DBAL\Tools\Console\Helper\ConnectionHelper(
        $container->get('doctrine.entity_manager.orm_default')->getConnection()
    )
]);

// alterntive

// return \Doctrine\ORM\Tools\Console\ConsoleRunner::createHelperSet(
//    $container->get('doctrine.entity_manager.orm_default')
// );

My doctrine.local.php

return [
    'doctrine' => [
        'connection' => [
            'orm_default' => [
                'driver_class' => \Doctrine\DBAL\Driver\PDOPgSql\Driver::class,
                'params' => [
                    'driver' => 'pdo_pgsql',
                    'dbname' => getenv('DB_NAME'),
                    'host' => getenv("DB_HOST"),
                    'user' => getenv("DB_USERNAME"),
                    'password' => getenv("DB_PASSWORD"),
                    'charset' => 'UTF8'
                ],
            ],
        ],
        'driver' => [
            'orm_default' => [
                'class' => \Doctrine\Common\Persistence\Mapping\Driver\MappingDriverChain::class,
                'drivers' => [
                    'App\Entity' => 'entities',
                ],
            ],
            'entities' => [
                'class' => \Doctrine\ORM\Mapping\Driver\AnnotationDriver::class,
                'cache' => 'array',
                'paths' => __DIR__ . '/../../src/App/src/Entity',
            ],
        ],
    ],
];

Any idea to resolve this issue?

PS: I google it but I only found answers on symfony

guillaumemaka commented 6 years ago

I found a workaround I added:

\Doctrine\Common\Annotations\AnnotationRegistry::registerLoader('class_exists');
asgrim commented 6 years ago

Yes, that's a requirement here to register a loader of sorts for your AnnotationRegistry :+1: