TYPO3 事件调度器接口

发布于 2025-01-13 09:11:19 字数 435 浏览 1 评论 0原文

我尝试在我的存储库中注入 $eventDispatcher

private EventDispatcherInterface $eventDispatcher;

public function injectEventDispatcher(EventDispatcherInterface $eventDispatcher): void
    {
        $this->eventDispatcher = $eventDispatcher;
    }

但从 PHP 7.4 开始,您必须进行初始化。但我无法初始化 EventDispatcherInterface 并收到此错误: 初始化之前不得访问类型化属性 $eventDispatcher

如何初始化 eventDispatcher?谢谢。

I try to inject the $eventDispatcher in my Repository

private EventDispatcherInterface $eventDispatcher;

public function injectEventDispatcher(EventDispatcherInterface $eventDispatcher): void
    {
        $this->eventDispatcher = $eventDispatcher;
    }

But since PHP 7.4 you have to be initialized. But I cant initialize the EventDispatcherInterface and get this error :
Typed property $eventDispatcher must not be accessed before initialization

How can I initialize the eventDispatcher? Thanks.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

愁杀 2025-01-20 09:11:19

也许,切换到 构造函数注入可以解决这个问题:

public function __construct(EventDispatcherInterface $eventDispatcher)
{
    $this->eventDispatcher = $eventDispatcher;
}

Maybe, switching to Constructor Injection can solve this:

public function __construct(EventDispatcherInterface $eventDispatcher)
{
    $this->eventDispatcher = $eventDispatcher;
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文