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'); } }
登录后复制
今天就这样!
以上就是使用 Symfony Console 进行交互式调试的详细内容,更多请关注至强加速其它相关文章!
本文来源于互联网,如若侵权,请联系管理员删除,本文链接:https://www.9969.net/26786.html