Doctrine AnnotationRegistry registerLoader替换

问题描述 投票:1回答:1

要设置基于Symphoy Annotation的路由,我有这一行

AnnotationRegistry::registerLoader([$loader, 'loadClass']);

它工作正常但是不推荐使用的方法:

 * @return void
 *
 * @throws \InvalidArgumentException
 *
 * @deprecated this method is deprecated and will be removed in doctrine/annotations 2.0
 *             autoloading should be deferred to the globally registered autoloader by then. For now,
 *             use @example AnnotationRegistry::registerLoader('class_exists')
 */
public static function registerLoader(callable $callable)

由此我不明白我应该使用什么。

谢谢你的建议

php doctrine-orm
1个回答
0
投票

AnnotationRegistry已弃用,将在doctrine / annotations 2.0中删除,但现在仍然需要它。

如果你已经设置了自动加载器,他们建议的简单解决方法是通过传入'class_exists'来设置AnnotationRegistry,这是一个php callable函数,只检查类是否存在并返回true / false。

AnnotationRegistry::registerLoader('class_exists');
© www.soinside.com 2019 - 2024. All rights reserved.