sbooker/command-bus

Command bus

1.0.0 2023-06-15 06:27 UTC

This package is auto-updated.

Last update: 2024-04-15 08:14:39 UTC


README

Latest Version Software License PHP Version Total Downloads Build Status codecov

And persistent via Doctrine ORM implementation

Installation

Install via Composer:

composer require sbooker/command-bus

Nested transactions

Enpoints may use transactions. Strongly recommends use Sbooker/TransactionManager for it.

You need to make sure that firstly do all checks are and throws exceptions.

And only then mutates state of entities.

Example usage with Symfony and Doctrine (while bundle not written)

Install suggest libraries:

composer require sbooker/doctrine-enumerable-type sbooker/doctrine-transaction-handler ramsey/uuid-doctrine

To use default configuration configure as bellow:

### config/packages/sbooker_command_bus.yaml
doctrine:
  dbal:
    types:
      command_status: Sbooker\CommandBus\Infrastructure\Persistence\Mapping\StatusType
  orm:
    mappings:
      SbookerCommands:
        type: xml
        prefix: Sbooker\CommandBus
        dir: '%kernel.project_dir%/vendor/sbooker/command-bus/src/Infrastructure/Persistence/Mapping'
        is_bundle: false

services:
  Sbooker\CommandBus\CommandBus:
    class: Sbooker\CommandBus\PersistentCommandCommandBus
    arguments:
      - '@Sbooker\CommandBus\Normalizer'
      - '@Sbooker\TransactionManager\TransactionManager'
      - '@Sbooker\CommandBus\ReadStorage'

  Sbooker\CommandBus\Normalizer:
    class: Sbooker\CommandBus\Normalization\SymfonySerializerNormalizer
    arguments:
      - '@Sbooker\CommandBus\NameGiver'
      - '@serializer'

  Sbooker\CommandBus\Denormalizer:
    class: Sbooker\CommandBus\Normalization\SymfonySerializerDenormalizer
    arguments:
      - '@Sbooker\CommandBus\NameGiver'
      - '@serializer'

  Sbooker\CommandBus\Registry:
    class: Sbooker\CommandBus\Registry\Containerized\ContainerizedRegistry
    arguments:
      - '@command_bus.registry.endpoint_container'
      - '@command_bus.registry.timeout_calculator_container'

  command_bus.registry.endpoint_container:
    class: Sbooker\CommandBus\Registry\Containerized\ContainerAdapter
    arguments:
      - '@service_container'
      - ~
      -
        ## command name to endpoint map

  command_bus.registry.timeout_calculator_container:
    class: Sbooker\CommandBus\Registry\Containerized\ContainerAdapter
    arguments:
      - '@service_container'
      - 'command_bus.timeout_calculator.default'
      -
        ## command name to timeout calculator map

  command_bus.timeout_calculator.default:
    public: true
    class: Sbooker\CommandBus\TimeoutCalculator\Fix
    arguments:
      - 1
      - 3

  command_bus.timeout_calculator.external:
    public: true
    class: Sbooker\CommandBus\TimeoutCalculator\BinExp
    arguments:
      - 10

  Sbooker\CommandBus\NameGiver:
    class: Sbooker\CommandBus\NameGiver\ClassNameMap
    arguments:
      -
        ## FQCN to command name map

  Sbooker\CommandBus\ReadStorage:
    alias: Sbooker\CommandBus\Infrastructure\Persistence\DoctrineRepository

  Sbooker\CommandBus\Infrastructure\Persistence\DoctrineRepository:
    class: Sbooker\CommandBus\Infrastructure\Persistence\DoctrineRepository
    factory: [ '@doctrine', getRepository ]
    arguments:
      - Sbooker\CommandBus\Command

License

See LICENSE file.