【发布时间】:2018-04-15 05:13:54
【问题描述】:
我的自动装配不适用于基本文件实体侦听器。
我有一个 File 实体类,它使用注释来指定侦听器,例如:
/**
@Orm\Entity(repositoryClass="root\CoreBundle\Repository\FileRepository")
@Orm\EntityListeners({"root\CoreBundle\EventListener\Entity\FileEntityListener"})
@Orm\Table(
etc...
FileEntityListener 类开始如下:
class FileEntityListener
{
private $encoderFactory;
private $logger;
public function __construct(FilesystemMap $filesystemMap, LoggerInterface $logger)
{
$this->setFilesystemMap($filesystemMap);
$this->logger = $logger;
}
当监听器启动时,依赖项没有注入到监听器的构造函数中,构造函数出现错误,说:
Type error: Too few arguments to function Epcvip\CoreBundle\EventListener\Entity\FileEntityListener::__construct(), 0 passed in /var/www/html/accounting/vendor/doctrine/doctrine-bundle/Mapping/ContainerAwareEntityListenerResolver.php on line 83 and exactly 2 expected
包是自动装配的,但依赖项没有被注入。
有人知道为什么这不起作用吗?也许我缺少一个轻微的配置步骤?
【问题讨论】:
-
通过注解分配实体监听器适用于旧版本的 Doctrine。使用此处描述的方法:symfony.com/doc/current/bundles/DoctrineBundle/…
标签: php symfony dependencies code-injection autowired