panda
panda

Reputation: 1344

Annotation loading of Doctrine

I have defined an entity

use Doctrine\ORM\Mapping as ORM;

/**
 * UmMemberSectionInfo
 *
 * @Table(name="um_member_section_info")
 * @Annotations\CharDependent(reflect="TbContentcharset")
 * @Entity
 */
class UmMemberSectionInfo extends \DoctrineHelper
{
//some code
}

And an annotation

namespace Annotations;
use Doctrine\Common\Annotations\Annotation;
/**
 * @Annotation
 * @Target("CLASS")
 */
final class CharDependent extends Annotation{
    public $reflect;
}

And read it as

$reader = new AnnotationReader();        
$reflectionObj = new \ReflectionObject(new $entity);
$annot = $reader->getClassAnnotation($reflectionObj, '\\Annotations\\CharDependent');
var_dump($annot->reflect);
if ($annot instanceof \Annotations\CharDependent) {}

However, it just pom an error says, The annotation "@Table" in class UmMemberSectionInfo was never imported. which will not be shown when I let the CharDependent annotation off and use it as original. What is the problem? Why it's fine when I use the original?

Upvotes: 0

Views: 182

Answers (1)

Damian Polac
Damian Polac

Reputation: 934

You must use full annotation name with namespace:

@Doctrine\ORM\Mapping\Table

but you imported use Doctrine\ORM\Mapping as ORM;, so you can use that alias:

@ORM\Table

If you want to use short @Table, you must import Table class:

use Doctrine\ORM\Mapping\Table;

You must do the same for @Entity.

Upvotes: 1

Related Questions