nepada/phpstan-message-bus

PHPStan 扩展,用于 nepada/message-bus。

安装次数: 1,521

依赖关系: 0

建议者: 0

安全性: 0

星标: 1

关注者: 3

分支: 0

开放问题: 0

类型:phpstan-extension

v3.2.0 2024-04-01 22:41 UTC

This package is auto-updated.

Last update: 2024-09-01 23:00:28 UTC


README

Build Status Coverage Status Downloads this Month Latest stable

安装

通过 Composer

composer require --dev nepada/phpstan-mesasge-bus

除非您还安装了 phpstan/extension-installer,否则您需要手动在您的配置中启用该扩展

includes:
    - vendor/nepada/phpstan-message-bus/extension.neon

无论如何,您需要指定包含您的命令处理器所在的目录

parameters:
    commandHandlerDirectories:
        - app
        - src

描述

该软件包目前仅提供一种扩展 - DynamicMethodThrowTypeExtension。该扩展将命令处理器抛出的异常传播到命令总线调用者。

final class FooService
{

    private \Nepada\MessageBus\Commands\CommandBus $commandBus;

    public function __construct(\Nepada\MessageBus\Commands\CommandBus $commandBus)
    {
        $this->commandBus = $commandBus;
    }

    public function placeOrder(): void
    {
        try {
            $command = new PlaceOrderCommand();
            $this->commandBus->handle($command);
        } catch (FailedToPlaceOrderException $exception) {
            // FailedToPlaceOrderException may be thrown and needs to handled
        }
    }

}

final class PlaceOrderCommand implements \Nepada\MessageBus\Commands\Command
{

}

final class PlaceOrderHandler implements \Nepada\MessageBus\Commands\CommandHandler
{

    /**
     * @param PlaceOrderCommand $command
     * @throws FailedToPlaceOrderException
     */
    public function __invoke(PlaceOrderCommand $command): void
    {
        throw new FailedToPlaceOrderException('Failed to place order');
    }

}

class FailedToPlaceOrderException extends \RuntimeException
{

}