@@ -13,36 +13,57 @@ composer require patchlevel/event-sourcing-psr-container
13
13
14
14
## Documentation
15
15
16
+ ### Config Builder
17
+
18
+ To create a configuration array, you can use the ConfigBuilder.
19
+ This offers methods to adjust the configuration.
20
+
21
+ ``` php
22
+ $eventSourcingConfig = (new ConfigBuilder())
23
+ ->singleTable()
24
+ ->databaseUrl('mysql://user:secret@localhost/app')
25
+ ->addAggregatePath(__DIR__ . '/Aggregate')
26
+ ->addEventPath(__DIR__ . '/Events')
27
+ ->addProcessor(SendEmailProcessor::class)
28
+ ->addProjector(ProfileProjection::class)
29
+ ->build();
30
+ ```
31
+
16
32
### Default Build-In Container
17
33
34
+ The own PSR container implementation already integrates all necessary factories.
35
+ So we only have to pass the configuration.
36
+
18
37
``` php
19
38
use Patchlevel\EventSourcing\Container\ConfigBuilder;
20
39
use Patchlevel\EventSourcing\Container\DefaultContainer;
21
40
22
- $config = (new ConfigBuilder())
23
- ->singleTable()
24
- ->databaseUrl('mysql://user:secret@localhost/app')
25
- ->addAggregatePath('src/Domain/Hotel')
26
- ->addEventPath('src/Domain/Hotel/Event')
27
- ->addProjector(HotelProjection::class)
28
- ->addProcessor(SendCheckInEmailProcessor::class)
29
- ->build();
30
-
31
41
$container = new DefaultContainer(
32
- $config ,
42
+ $eventSourcingConfig ,
33
43
[
34
44
HotelProjection::class => fn(DefaultContainer $container)
35
45
=> new HotelProjection($container->connection()),
36
- SendCheckInEmailProcessor ::class => fn(DefaultContainer $container)
37
- => new SendCheckInEmailProcessor ($container->get('mailer')),
46
+ SendEmailProcessor ::class => fn(DefaultContainer $container)
47
+ => new SendEmailProcessor ($container->get('mailer')),
38
48
]
39
49
);
40
50
51
+ $container->get(SchemaDirector::class)->create();
52
+
41
53
$hotelRepository = $container->repository(Hotel::class);
42
54
```
43
55
44
56
### Laminas Service Manager
45
57
58
+ Factories can also be used with other PSR-11 compatible libraries.
59
+ Here is an example with [ Laminas] ( https://docs.laminas.dev/laminas-servicemanager/ ) .
60
+
61
+ ``` bash
62
+ composer require laminas/laminas-servicemanager
63
+ ```
64
+
65
+ We only have to specify the factories and pass the configuration.
66
+
46
67
``` php
47
68
use Laminas\ServiceManager\ServiceManager;
48
69
use Patchlevel\EventSourcing\Repository\RepositoryManager;
@@ -52,29 +73,23 @@ use Patchlevel\EventSourcingPsrContainer\Factory\ConnectionFactory;
52
73
use Patchlevel\EventSourcingPsrContainer\Factory\RepositoryManagerFactory;
53
74
use Patchlevel\EventSourcingPsrContainer\Factory\SchemaDirectorFactory;
54
75
55
- $config = (new ConfigBuilder())
56
- ->singleTable()
57
- ->databaseUrl('sqlite:///:memory:')
58
- ->addAggregatePath(__DIR__ . '/Aggregate')
59
- ->addEventPath(__DIR__ . '/Events')
60
- ->addProcessor(SendEmailProcessor::class)
61
- ->addProjector(ProfileProjection::class)
62
- ->build();
63
-
64
76
$serviceManager = new ServiceManager([
65
77
'services' => [
66
78
'config' => [
67
- 'event_sourcing' => $config
79
+ 'event_sourcing' => $eventSourcingConfig
68
80
],
69
81
SendEmailProcessor::class => new SendEmailProcessor()
70
82
],
71
83
'factories' => [
72
84
'event_sourcing.connection' => new ConnectionFactory(),
73
85
RepositoryManager::class => new RepositoryManagerFactory(),
74
86
SchemaDirector::class => new SchemaDirectorFactory(),
75
- ProfileProjection ::class => static fn (ServiceManager $container) => new ProfileProjection ($container->get('event_sourcing.connection')),
87
+ HotelProjection ::class => static fn (ServiceManager $container) => new HotelProjection ($container->get('event_sourcing.connection')),
76
88
],
77
89
]);
78
90
91
+ $serviceManager->get(SchemaDirector::class)->create();
92
+
79
93
$repositoryManager = $serviceManager->get(RepositoryManager::class);
94
+ $hotelRepository = $repositoryManager->get(Hotel::class);
80
95
```
0 commit comments