
roundingwell 最重要的系统之一是评估引擎,或者我们通常所说的“评估”。该系统负责处理特定于客户的配置事件侦听器,这使我们能够为每个组织提供高度独特的用户体验。不用说,这个系统对我们的应用程序非常重要,并且能够准确地知道它做了什么、或将要做什么,对于给定的事件至关重要。
今天,我正在努力将我们的一位客户从一些旧事件转换为新事件,并且需要确保其中一个步骤能够正确处理事件。我们有很多关于评估的日志记录,我知道我需要的信息就在日志中。但拥有大量日志记录的问题是,有很多日志。另外,我只需要运行每个触发器的第一部分来验证迁移是否有效。
我心想,“如果我们能为评估引擎提供一个类似 xdebug 的单步调试器,这不是很聪明吗?我知道 symfony console 拥有我需要的所有功能......”
而这正是我所做的。因为我们的应用程序是完全依赖注入的,所以我能够创建一个新类来包装 stepfactory,它负责读取配置并创建构成评估的“步骤”。
农业园林门户网适用于农业垂直电商门户网站建设。上传到服务器/虚拟主机空间即可使用,也可使用简易ASP调试软件或IIS测试。本系统是基于asp+access/SQLServer生成html的垂直电商行业门户系统,是典型的互联网+电商模式的应用,主要定位于农、林、牧、副、鱼等周边产业领域,提供商家网上发布信息、开店、报价、交易等。
118
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: <<<text
next step is $definition->name with parameters:
$debug
text,
);
}
$step = $this->stepfactory->create($subject, $definition);
if ($this->showcreatedstep) {
$debug = new debugvar($step);
$this->style->info(
message: <<<text
step $definition->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 进行交互式调试的详细内容,更多请关注php中文网其它相关文章!
每个人都需要一台速度更快、更稳定的 PC。随着时间的推移,垃圾文件、旧注册表数据和不必要的后台进程会占用资源并降低性能。幸运的是,许多工具可以让 Windows 保持平稳运行。
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号