使用 Symfony Console 进行交互式调试
来源:dev.to
时间:2024-07-20 22:18:51 229浏览 收藏
在文章实战开发的过程中,我们经常会遇到一些这样那样的问题,然后要卡好半天,等问题解决了才发现原来一些细节知识点还是没有掌握好。今天golang学习网就整理分享《使用 Symfony Console 进行交互式调试》,聊聊,希望可以帮助到正在努力赚钱的你。
roundingwell 最重要的系统之一是评估引擎,或者我们通常所说的“评估”。该系统负责处理特定于客户的配置事件侦听器,这使我们能够为每个组织提供高度独特的用户体验。不用说,这个系统对我们的应用程序非常重要,并且能够准确地知道它做了什么、或将要做什么,对于给定的事件至关重要。
今天,我正在努力将我们的一位客户从一些旧事件转换为新事件,并且需要确保其中一个步骤能够正确处理事件。我们有很多关于评估的日志记录,我知道我需要的信息就在日志中。但拥有大量日志记录的问题是,有很多日志。另外,我只需要运行每个触发器的第一部分来验证迁移是否有效。
我心想,“如果我们能为评估引擎提供一个类似 xdebug 的单步调试器,这不是很聪明吗?我知道 symfony console 拥有我需要的所有功能......”
而这正是我所做的。因为我们的应用程序是完全依赖注入的,所以我能够创建一个新类来包装 stepfactory,它负责读取配置并创建构成评估的“步骤”。
use roundingwell\framework\debugvar; use runtimeexception; use symfony\component\console\style\symfonystyle; readonly class stepfactorywithconsoleconfirmation implements stepfactory { public function __construct( private stepfactory $stepfactory, private symfonystyle $style, private bool $confirmcreatedstep = true, private bool $showcreatedstep = true, private bool $showstepdefinition = false, ) { } public function create(object $subject, stepdefinition $definition): step { if ($this->showstepdefinition) { $debug = new debugvar($definition->parameters); $this->style->info( message: <<name with parameters: $debug text, ); } $step = $this->stepfactory->create($subject, $definition); if ($this->showcreatedstep) { $debug = new debugvar($step); $this->style->info( message: << name created as: $debug text, ); } if ($this->confirmcreatedstep && ! $this->style->confirm(question: "continue with evaluation?")) { throw new runtimeexception( message: "evaluation aborted at step {$definition->name}", ); } return $step; } }
并且,通过我的控制台命令中的一些容器操作,我们有一个交互式评估调试器:
use DI\Container; use RoundingWell\Common\Command\CommandBus; use RoundingWell\Common\Command\CommandBusComposed; use RoundingWell\Common\Command\Middleware\LoggingMiddleware; use RoundingWell\Evaluation\Command\EvaluateEvent; use RoundingWell\Evaluation\Command\EvaluateEventHandler; use RoundingWell\Evaluation\Step\StepFactory; use RoundingWell\Evaluation\Step\StepFactoryWithConsoleConfirmation; use Symfony\Component\Console\Style\SymfonyStyle; readonly class EvaluationDebug { public function __construct( private Container $container, ) { } public function __invoke( SymfonyStyle $symfonyStyle, string $eventType, string $eventId, string|null $evaluationId = null, ): void { // The command bus MUST ONLY log executed commands. $commandBus = new CommandBusComposed( $this->container->get(LoggingMiddleware::class), ); // The step factory MUST be wrapped to step through the evaluation. $stepFactory = new StepFactoryWithConsoleConfirmation( stepFactory: $this->container->get(StepFactory::class), style: $symfonyStyle, ); $this->container->set(CommandBus::class, $commandBus); $this->container->set(StepFactory::class, $stepFactory); $command = new EvaluateEvent( eventClass: $eventType, eventId: $eventId, evaluationId: $evaluationId, ); $this->container->get(EvaluateEventHandler::class)->handle($command); $symfonyStyle->success('Evaluation complete'); } }
今天就这样!
今天带大家了解了的相关知识,希望对你有所帮助;关于文章的技术知识我们会一点点深入介绍,欢迎大家关注golang学习网公众号,一起学习编程~
声明:本文转载于:dev.to 如有侵犯,请联系study_golang@163.com删除
相关阅读
更多>
-
501 收藏
-
501 收藏
-
501 收藏
-
501 收藏
-
501 收藏
最新阅读
更多>
-
463 收藏
-
451 收藏
-
284 收藏
-
224 收藏
-
450 收藏
-
266 收藏
-
409 收藏
-
320 收藏
-
291 收藏
-
500 收藏
-
245 收藏
-
117 收藏
课程推荐
更多>
-
- 前端进阶之JavaScript设计模式
- 设计模式是开发人员在软件开发过程中面临一般问题时的解决方案,代表了最佳的实践。本课程的主打内容包括JS常见设计模式以及具体应用场景,打造一站式知识长龙服务,适合有JS基础的同学学习。
- 立即学习 542次学习
-
- GO语言核心编程课程
- 本课程采用真实案例,全面具体可落地,从理论到实践,一步一步将GO核心编程技术、编程思想、底层实现融会贯通,使学习者贴近时代脉搏,做IT互联网时代的弄潮儿。
- 立即学习 508次学习
-
- 简单聊聊mysql8与网络通信
- 如有问题加微信:Le-studyg;在课程中,我们将首先介绍MySQL8的新特性,包括性能优化、安全增强、新数据类型等,帮助学生快速熟悉MySQL8的最新功能。接着,我们将深入解析MySQL的网络通信机制,包括协议、连接管理、数据传输等,让
- 立即学习 497次学习
-
- JavaScript正则表达式基础与实战
- 在任何一门编程语言中,正则表达式,都是一项重要的知识,它提供了高效的字符串匹配与捕获机制,可以极大的简化程序设计。
- 立即学习 487次学习
-
- 从零制作响应式网站—Grid布局
- 本系列教程将展示从零制作一个假想的网络科技公司官网,分为导航,轮播,关于我们,成功案例,服务流程,团队介绍,数据部分,公司动态,底部信息等内容区块。网站整体采用CSSGrid布局,支持响应式,有流畅过渡和展现动画。
- 立即学习 484次学习