大佬教程收集整理的这篇文章主要介绍了Symfony 5:如何防止事件订阅者在 Profiler(Web 调试工具栏)处于活动状态时触发两次?,大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。
我创建了一个订阅者,它执行另一个类->方法,它创建一个数据库条目。我可以看到订阅者触发了两次,因为数据库条目总是输入两次。我停用了 Profiler(Web 调试工具栏)并解决了该问题。
这是我的订阅者:
<?php
namespace App\EventSubscriber;
use Psr\Log\LoggerInterface;
use Symfony\Component\Eventdispatcher\EventSubscriberInterface;
use Symfony\Component\httpKernel\Event\ResponseEvent;
use Symfony\Component\httpKernel\Event\requestEvent;
use Symfony\Component\httpKernel\KernelEvents;
use App\Repository\UserRepository;
class ExampleSubscriber implements EventSubscriberInterface
{
public static function getSubscribedEvents() {
return [
KernelEvents::rESPONSE => [
['onKernelResponsePre',10],['onKernelResponsePost',-10],],requestEvent::class => 'onKernelrequest',];
}
public function __construct(
LoggerInterface $logger,UserRepository $user
) {
$this->logger = $logger;
$this->user = $user;
}
public function onKernelResponsePre(ResponseEvent $event)
{
// ...
}
public function onKernelResponsePost(ResponseEvent $event)
{
// ...
}
public function onKernelrequest(requestEvent $event)
{
$db_data = $this->user->findUserByUsername($user_name);
$write_db_entry = $this->user->writeUserData($db_data['user_iD']);
$this->logger->info('Just checking if this message shows twice. It does not.');
}
}
如何让“onKernelrequest”中的代码只执行一次并且激活探查器?它可以在任何情况下发生,但应该在调用控制器之前执行。
预先感谢您的帮助。
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)
以上是大佬教程为你收集整理的Symfony 5:如何防止事件订阅者在 Profiler(Web 调试工具栏)处于活动状态时触发两次?全部内容,希望文章能够帮你解决Symfony 5:如何防止事件订阅者在 Profiler(Web 调试工具栏)处于活动状态时触发两次?所遇到的程序开发问题。
如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。
本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。