You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+90-10Lines changed: 90 additions & 10 deletions
Original file line number
Diff line number
Diff line change
@@ -1,6 +1,6 @@
1
1
# Symfony Bundle for DDD
2
2
3
-
Various additions for [domain driven development](https://martinfowler.com/tags/domain%20driven%20design.html)inside Symfony.
3
+
This Symfony bundle augments [geekcell/php-ddd](https://github.com/geekcell/php-ddd) with framework-specific implementations to enable seamless [domain driven design](https://martinfowler.com/tags/domain%20driven%20design.html)in a familiar environment.
4
4
5
5
## Installation
6
6
@@ -10,48 +10,128 @@ To use this bundle, require it in Composer
10
10
composer require geekcell/ddd-bundle
11
11
```
12
12
13
+
## Quickstart
14
+
15
+
-[Aggregate Root](#aggregate-root)
16
+
-[Repositories](#repositories)
17
+
-[Command & Query Bus](#command--query-bus)
18
+
-[Supporting Tools](#supporting-tools)
19
+
13
20
## Aggregate Root
14
21
15
22
Extend from `AggregateRoot` to record and commit domain events. Domain events must implement the (marker) interface `DomainEvent`. Events will be dispatched via the currently configured Symfony event dispatcher.
16
23
17
24
### Example Usage
18
25
19
26
```php
20
-
use GeekCell\DDDBundle\Domain\Event\DomainEvent;
21
-
use GeekCell\DDDBundle\Domain\Model\AggregateRoot;
27
+
use GeekCell\Ddd\Contracts\Domain\Event as DomainEvent;
28
+
use GeekCell\DddBundle\Domain\AggregateRoot;
22
29
23
30
class OrderPlacedEvent implements DomainEvent
24
31
{
25
-
...
32
+
public function __construct(
33
+
private readonly Order $order,
34
+
) {
35
+
}
36
+
37
+
// Getters etc.
26
38
}
27
39
28
40
class Order extends AggregateRoot
29
41
{
30
42
public function save(): void
31
43
{
32
-
$this->record(new OrderPlacedEvent());
44
+
$this->record(new OrderPlacedEvent($this));
33
45
}
34
46
35
-
...
47
+
// ...
36
48
}
37
49
38
-
$order = new Order();
50
+
$order = new Order( /* ... */ );
39
51
$order->save();
40
-
$order->commit(); // <-Eventswillbedispatched
52
+
$order->commit(); // All recorded events will be dispatched and released
41
53
```
42
54
43
55
_Hint: If you want to dispatch an event directly, use `AggregateRoot::dispatch()` instead of `AggregateRoot::record()`._
44
56
45
57
If you cannot (or don't want to) extend from `AggregateRoot`, you can alternative use `DispatchableTrait` to add dispatching capabilities to any class. The former is however the recommended way.
46
58
59
+
## Repositories
60
+
61
+
_coming soon..._
62
+
63
+
## Command & Query Bus
64
+
65
+
You can use `CommandBus` and `QueryBus` as services to implement [CQRS](https://martinfowler.com/bliki/CQRS.html). Internally, both buses will use the [Symfony messenger](https://symfony.com/doc/current/messenger.html) as "backend".
Facades are heavily inspired by [Laravel's Facades](https://laravel.com/docs/facades) and are more or less singletons on steroids. They are basically a shortcut to services inside the DIC.
0 commit comments