doctrine2 autloader with cli must use AnnotationRegistry

前端 未结 2 2051
-上瘾入骨i
-上瘾入骨i 2021-02-06 11:20

I must use \\Doctrine\\Common\\Annotations\\AnnotationRegistry::registerFile to access the annotation registry in entity files.

This part is required to use

相关标签:
2条回答
  • 2021-02-06 11:47

    Thank you Samuel Herzog. It works perfect for me. I was generating the Vendors using composer.json. So When I added my autoload.php i just needed to add these sentences...

    <?php
    // autoload.php generated by Composer
    use Doctrine\Common\Annotations\AnnotationRegistry;
    
    require_once dirname( __DIR__ ).'/vendor/composer/autoload_real.php';
    
    $loader = ComposerAutoloaderInit0cf45a42473ebbcd4516460f93747271::getLoader();
    
    AnnotationRegistry::registerFile( dirname( __DIR__ ).'/vendor/doctrine/orm/lib/Doctrine/ORM/Mapping/Driver/DoctrineAnnotations.php' );
    
    return $loader;
    

    Just like that.

    0 讨论(0)
  • 2021-02-06 11:58

    It seems your AnnotationRegistry isn't set up.

    Add the following to your script:

    use Doctrine\Common\Annotations\AnnotationRegistry;  
    
    AnnotationRegistry::registerFile("/path/to/doctrine/lib/Doctrine/ORM/Mapping/Driver/DoctrineAnnotations.php");
    

    see Doctrine manual on Annotations for the detailed explanation.
    In short: to read the annotations PSR-0 and spl autoloading can't do the job, you have to use their solution.

    0 讨论(0)
提交回复
热议问题