Doctrine2 存储库中返回实体的类型提示

Vas*_*ily 5 symfony doctrine-orm phpstorm

我有CustomRepository扩展Doctrine\ORM\EntityRepository. 该存储库与许多不同的实体相关联。存储库中有一个方法可以返回关联的实体。

class CustomRepository extends \Doctrine\ORM\EntityRepository
{
    function getEntity() { ... } // returns an instance of associated entity
}

/**
 * @ORM\Entity(repositoryClass="CustomRepository")
 */
class EntityClass1 { ... }    
/**
 * @ORM\Entity(repositoryClass="CustomRepository")
 */
class EntityClass2 { ... }

$repo1 = $entityManager->getRepository('Entity1');
$entity1 = $repo1->getEntity(); // will return an instance of EntityClass1

$repo2 = $entityManager->getRepository('Entity2');
$entity2 = $repo1->getEntity(); // will return an instance of EntityClass2
Run Code Online (Sandbox Code Playgroud)

我使用 Symfony 2 插件,它正确地将继承方法实体返回的类检测为find.
有没有办法通知插件该方法返回一个关联实体?

COi*_*Oil 3

你可以使用这样的东西:

/**
 * MyEntity repository.
 *
 * @method MyEntity[] find
 */
Run Code Online (Sandbox Code Playgroud)