【发布时间】:2017-11-08 13:46:50
【问题描述】:
我正在尝试制作一个自定义用户提供程序,它使用自定义的类似 Doctrine 的捆绑包。这个包使用实体,就像 Doctrine 一样:
/**
* @EntityMeta(table="MY_TABLE")
*/
class MyTable extends AbstractEntity
{
/**
* @var int
* @EntityColumnMeta(column="Code", isKey=true)
*/
protected $code;
/**
* @var int
* @EntityColumnMeta(column="Name")
*/
protected $name;
当我使用我的包提供的类似教条的管理器时,这些注释工作得很好。这段代码运行良好:
public function indexAction(DoctrineLikeManager $manager)
{
$lines = $manager->getRepository('MyTable')->findBy(array(
'email' => 'test@test.com'
));
// do something with these
}
所以我知道注释是有效的。但是当我在用户提供程序类中使用相同的代码和相同的实体时,我收到以下错误:
[Semantical Error] The annotation "@NameSpace\DoctrineLikeBundle\EntityColumnMeta" in property AppBundle\MyTable::$code does not exist, or could not be auto-loaded.
用户提供者:
class HanaUserProvider implements UserProviderInterface
{
private $manager;
public function __construct(DoctrineLikeManager $manager)
{
$this->manager = $manager;
}
public function loadUserByUsername($username)
{
// this is where it fails :(
$lines = $this->manager->getRepository('MyTable')->findBy(array(
'email' => 'test@test.com'
));
// return user or throw UsernameNotFoundException
}
}
是否可以在该上下文中使用自定义注释?也许我应该特别做一些事情,以便可以成功加载自定义注释?
提前致谢!
【问题讨论】:
-
你有
use My\Annotation\Custom;吗? -
@goto :是的,我没有在这里写它们以保持代码简洁。我找到了解决方案,见下文。还是谢谢!
标签: php symfony symfony-3.3