Skip to content

Commit cb4a10e

Browse files
authored
factorize domain messages (#57)
1 parent 6255f9e commit cb4a10e

32 files changed

Lines changed: 154 additions & 89 deletions
Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
1-
# Entity factory
1+
# Entity aware factory
22

3-
An entity factory is a domain object factory and is bound to `MsgPhp\Domain\Factory\EntityFactoryInterface`.
4-
Besides initializing the entity via `create()` it can also initialize an identifier using either `identify()` or
5-
`nextIdentifier()`.
3+
An entity aware factory is a domain object factory and is bound to `MsgPhp\Domain\Factory\EntityAwareFactoryInterface`.
4+
Besides initializing any domain object via `create()` it can also initialize an entity identifier using either
5+
`identify()` or `nextIdentifier()`.
66

77
## Implementations
88

9-
### `MsgPhp\Domain\Factory\EntityFactory`
9+
### `MsgPhp\Domain\Factory\EntityAwareFactory`
1010

11-
Generic entity factory and decorates any object factory. Additionally it must be provided with the identifier class
12-
mapping.
11+
Generic entity factory and decorates any object factory. Additionally it must be provided with an entity to identifier
12+
class mapping.
1313

1414
## API
1515

‎docs/event-sourcing/domain-event-handlers.md‎

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
# Domain event handlers
22

3-
A domain event handler is bound to `MsgPhp\Domain\Event\DomainEventHandlerInterface`. Its purpose is to handle domain
4-
events. By convention a trait implementation is provided to map concrete events to specialized handling methods.
3+
A domain event handler is bound to `MsgPhp\Domain\Event\DomainEventHandlerInterface`. Its purpose is to handle
4+
[domain events](domain-events.md). By convention a trait implementation is provided to map concrete events to
5+
specialized handling methods.
56

67
## Implementations
78

‎docs/message-driven/cqrs.md‎

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,9 @@ Usually a command handler is designed, but not limited, to handle one specific c
1313

1414
### `MsgPhp\Domain\Command\EventSourcingCommandHandlerTrait`
1515

16-
Sources a domain event from a command message.
16+
Handles a command message by sourcing a domain event.
1717

18-
- `doHandle(object $command, callable $onHandled = null): void`
19-
- Invokes the domain event for the given command message
18+
- `handle(object $command, callable $onHandled = null): void`
2019
- If the domain event is handled `$onHandled` will be invoked (if given), receiving the handler as first argument
2120
- `abstract getDomainEvent(object $command): DomainEventInterface`
2221
- The [domain event](../event-sourcing/domain-events.md) to be handled

‎docs/message-driven/domain-message-bus.md‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# Domain message bus
22

3-
A domain message bus is bound to `MsgPhp\Domain\DomainMessageBusInterface`. Its purpose is to dispatch any type of
4-
message object and helps you to use CQRS and event sourcing.
3+
A domain message bus is bound to `MsgPhp\Domain\Message\DomainMessageBusInterface`. Its purpose is to dispatch any type
4+
of message object and helps you to use [CQRS](cqrs.md) and [event sourcing](../event-sourcing/domain-event-handlers.md).
55

66
## Implementations
77

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
# Domain message dispatcher
2+
3+
The domain message dispatcher is a utility trait. Its purpose is to dispatch a message, factorized by a
4+
[object factory](../ddd/factory/object.md), using any [message bus](domain-message-bus.md).
5+
6+
## API
7+
8+
> Exposed `private` as a trait. You can decide to [change method visibility](https://secure.php.net/manual/en/language.oop5.traits.php#language.oop5.traits.visibility)
9+
on a per case basis.
10+
11+
### `dispatch(string $class, array $context = []): mixed`
12+
13+
Dispatches the given message object. The dispatcher can return a value coming from handlers, but is not required to do
14+
so.
15+
16+
## Basic example
17+
18+
```php
19+
<?php
20+
21+
use MsgPhp\Domain\Message\DomainMessageDispatchingTrait;
22+
23+
class MyClass
24+
{
25+
use DomainMessageDispatchingTrait;
26+
27+
public function doSomething(): void
28+
{
29+
$this->dispatch(SomeMessage::class, ['arg' => 'value']);
30+
}
31+
}
32+
```

‎mkdocs.yml‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ pages:
1919
- Collections: ddd/collections.md
2020
- Factories:
2121
- Object factory: ddd/factory/object.md
22-
- Entity factory: ddd/factory/entity.md
22+
- Entity aware factory: ddd/factory/entity_aware.md
2323
- Static factory: ddd/factory/static.md
2424
- Repositories: ddd/repositories.md
2525
- Entities: ddd/entities.md
@@ -28,4 +28,5 @@ pages:
2828
- Domain event handlers: event-sourcing/domain-event-handlers.md
2929
- Message driven:
3030
- Domain message bus: message-driven/domain-message-bus.md
31+
- Domain message dispatcher: message-driven/domain-message-dispatcher.md
3132
- CQRS: message-driven/cqrs.md

‎src/Domain/Command/EventSourcingCommandHandlerTrait.php‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ trait EventSourcingCommandHandlerTrait
1414
/**
1515
* @param object $command
1616
*/
17-
protected function doHandle($command, callable $onHandled = null): void
17+
private function handle($command, callable $onHandled = null): void
1818
{
1919
$event = $this->getDomainEvent($command);
2020
$handler = $this->getDomainEventHandler($command);

‎src/Domain/Event/ConfirmDomainEvent.php‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,6 @@
77
/**
88
* @author Roland Franssen <franssen.roland@gmail.com>
99
*/
10-
final class ConfirmDomainEvent implements DomainEventInterface
10+
class ConfirmDomainEvent implements DomainEventInterface
1111
{
1212
}

‎src/Domain/Event/DisableDomainEvent.php‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,6 @@
77
/**
88
* @author Roland Franssen <franssen.roland@gmail.com>
99
*/
10-
final class DisableDomainEvent implements DomainEventInterface
10+
class DisableDomainEvent implements DomainEventInterface
1111
{
1212
}

‎src/Domain/Event/EnableDomainEvent.php‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,6 @@
77
/**
88
* @author Roland Franssen <franssen.roland@gmail.com>
99
*/
10-
final class EnableDomainEvent implements DomainEventInterface
10+
class EnableDomainEvent implements DomainEventInterface
1111
{
1212
}

0 commit comments

Comments
 (0)