skar / laminas-doctrine-orm

Simple Laminas/Mezzio Doctrine ORM integration
BSD 3-Clause "New" or "Revised" License
12 stars 5 forks source link

DriverFactory add registerAnnotationLoader #1

Closed gam6itko closed 3 years ago

gam6itko commented 3 years ago

When I try to execute one of the commands I've got the error

The annotation "@%s" in %s was never imported. Did you maybe forget to add a "use" statement for this annotation?

Here is my solution

skar commented 3 years ago

Can you provide a code for yours Entity?

You should use something like this if i understand you correctly:

<?php
namespace App\Entity;

use Doctrine\ORM\Mapping as ORM; // Import doctrine mappings

/**
 * @ORM\Entity() // Use imported mappings
 */
class MyEntity {
    // ...
}
gam6itko commented 3 years ago

@skar my code example

<?php

declare(strict_types=1);

namespace App\Entity;

use App\Model\Email;
use App\Model\Phone;
use DateTime;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;
use Doctrine\ORM\Mapping as ORM;
use InvalidArgumentException;
use JsonSerializable;
use Mezzio\Authentication\UserInterface;
use OpenApi\Annotations as OA;
use Ramsey\Uuid\Doctrine\UuidGenerator;
use Ramsey\Uuid\UuidInterface;

/**
 *
 * @ORM\Entity(repositoryClass="App\Repository\AccountRepository")
 * @ORM\Table(name="account")
 */
class Account implements JsonSerializable, UserInterface
{

As you can see I have use Doctrine\ORM\Mapping as ORM;. But Doctrine Annotation reader can't load this class

skar commented 3 years ago

Ok, this code looks fine. Сan you provide annotations with which you are having problems (e.g. full error message)? I'll check it and fix because annotation loader is deprecated solution.

gam6itko commented 3 years ago

https://github.com/doctrine/annotations/issues/182

Looks like i need to add AnnotationRegistry::registerLoader('class_exists') somewhere in my bootstrap file. And this is not your lib issue