Skip to content

Commit 806927a

Browse files
committed
improve docs
1 parent af5c4bb commit 806927a

File tree

7 files changed

+101
-45
lines changed

7 files changed

+101
-45
lines changed

README.md

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
[![Type Coverage](https://shepherd.dev/github/patchlevel/laravel-event-sourcing/coverage.svg)](https://shepherd.dev/github/patchlevel/laravel-event-sourcing)
21
[![Latest Stable Version](https://poser.pugx.org/patchlevel/laravel-event-sourcing/v)](//packagist.org/packages/patchlevel/laravel-event-sourcing)
32
[![License](https://poser.pugx.org/patchlevel/laravel-event-sourcing/license)](//packagist.org/packages/patchlevel/laravel-event-sourcing)
43

@@ -20,7 +19,7 @@ for [event-sourcing](https://github.com/patchlevel/event-sourcing) library.
2019
* Safe usage of [Personal Data](https://laravel-event-sourcing.patchlevel.io/latest/personal_data/) with crypto-shredding
2120
* Smooth [upcasting](https://laravel-event-sourcing.patchlevel.io/latest/upcasting/) of old events
2221
* Simple setup with [scheme management](https://laravel-event-sourcing.patchlevel.io/latest/store/) and [doctrine migration](https://laravel-event-sourcing.patchlevel.io/latest/store/)
23-
* Built in [cli commands](https://laravel-event-sourcing.patchlevel.io/latest/cli/) with [symfony](https://symfony.com/)
22+
* Built in [cli commands](https://event-sourcing.patchlevel.io/latest/cli/)
2423
* and much more...
2524

2625
## Installation
@@ -32,13 +31,9 @@ composer require patchlevel/laravel-event-sourcing
3231
## Documentation
3332

3433
* [Package Documentation](https://laravel-event-sourcing.patchlevel.io/latest/)
35-
* [Library Documentation](https://laravel-event-sourcing.patchlevel.io/latest/)
34+
* [Library Documentation](https://event-sourcing.patchlevel.io/latest/)
3635
* [Related Blog](https://patchlevel.de/blog)
3736

38-
## Integration
39-
40-
* [Psalm](https://github.com/patchlevel/event-sourcing-psalm-plugin)
41-
4237
## Sponsors
4338

4439
[<img src="https://github.com/patchlevel/event-sourcing/assets/470138/d00b7459-23b7-431b-80b4-93cfc1b66216" alt="blackfire" width="200">](https://www.blackfire.io)

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
],
2020
"require": {
2121
"php": "~8.1.0 || ~8.2.0 || ~8.3.0",
22-
"patchlevel/event-sourcing": "3.5.x-dev",
22+
"patchlevel/event-sourcing": "^3.5",
2323
"illuminate/contracts": "^9.28|^10.0|^11.0"
2424
},
2525
"require-dev": {

config/event-sourcing.php

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,15 @@
7979
'enabled' => true,
8080
'ids' => null,
8181
'groups' => null,
82-
'limit' => null
82+
'limit' => null,
83+
],
84+
'rebuild_after_file_change' => [
85+
'enabled' => true,
86+
],
87+
'auto_setup' => [
88+
'enabled' => true,
89+
'ids' => null,
90+
'groups' => null,
8391
],
8492
],
8593

docs/pages/getting_started.md

Lines changed: 37 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ First we define the events that happen in our system.
1515
A hotel can be created with a `name` and an `id`:
1616

1717
```php
18-
namespace App\Hotel\Domain\Event;
18+
namespace App\Event;
1919

2020
use Patchlevel\EventSourcing\Aggregate\Uuid;
2121
use Patchlevel\EventSourcing\Attribute\Event;
@@ -33,7 +33,7 @@ final class HotelCreated
3333
A guest can check in by `name`:
3434

3535
```php
36-
namespace App\Hotel\Domain\Event;
36+
namespace App\Event;
3737

3838
use Patchlevel\EventSourcing\Attribute\Event;
3939

@@ -49,7 +49,7 @@ final class GuestIsCheckedIn
4949
And also check out again:
5050

5151
```php
52-
namespace App\Hotel\Domain\Event;
52+
namespace App\Event;
5353

5454
use Patchlevel\EventSourcing\Attribute\Event;
5555

@@ -75,11 +75,11 @@ In these methods the business checks are made and the events are recorded.
7575
Last but not least, we need the associated apply methods to change the state.
7676

7777
```php
78-
namespace App\Hotel\Domain;
78+
namespace App\Model;
7979

80-
use App\Hotel\Domain\Event\GuestIsCheckedIn;
81-
use App\Hotel\Domain\Event\GuestIsCheckedOut;
82-
use App\Hotel\Domain\Event\HotelCreated;
80+
use App\Event\GuestIsCheckedIn;
81+
use App\Event\GuestIsCheckedOut;
82+
use App\Event\HotelCreated;
8383
use Patchlevel\EventSourcing\Aggregate\Uuid;
8484
use Patchlevel\EventSourcing\Attribute\Aggregate;
8585
use Patchlevel\EventSourcing\Attribute\Apply;
@@ -173,11 +173,11 @@ we need a projection for it. To create a projection we need a projector.
173173
Each projector is then responsible for a specific projection.
174174

175175
```php
176-
namespace App\Hotel\Infrastructure\Projection;
176+
namespace App\Subscribers;
177177

178-
use App\Hotel\Domain\Event\GuestIsCheckedIn;
179-
use App\Hotel\Domain\Event\GuestIsCheckedOut;
180-
use App\Hotel\Domain\Event\HotelCreated;
178+
use App\Event\GuestIsCheckedIn;
179+
use App\Event\GuestIsCheckedOut;
180+
use App\Event\HotelCreated;
181181
use Illuminate\Database\Schema\Blueprint;
182182
use Illuminate\Support\Facades\DB;
183183
use Illuminate\Support\Facades\Schema;
@@ -251,9 +251,17 @@ final class HotelProjection
251251
}
252252
}
253253
```
254-
!!! warning
255254

256-
autoconfigure need to be enabled, otherwise you need add the `event_sourcing.subscriber` tag.
255+
You need to register the projector in the `event-sourcing.php` configuration file.
256+
257+
```php
258+
return [
259+
'subscribers' => [
260+
App\Subscribers\HotelProjector::class,
261+
],
262+
];
263+
264+
```
257265

258266
!!! note
259267

@@ -264,14 +272,14 @@ final class HotelProjection
264272
In our example we also want to send an email to the head office as soon as a guest is checked in.
265273

266274
```php
267-
namespace App\Hotel\Application\Processor;
275+
namespace App\Subscribers;
268276

269-
use App\Hotel\Domain\Event\GuestIsCheckedIn;
277+
use App\Event\GuestIsCheckedIn;
270278
use Illuminate\Support\Facades\Mail;
271279
use Patchlevel\EventSourcing\Attribute\Processor;
272280

273281
#[Processor('admin_emails')]
274-
final class SendCheckInEmailListener
282+
final class SendCheckInEmailProcessor
275283
{
276284
#[Subscribe(GuestIsCheckedIn::class)]
277285
public function onGuestIsCheckedIn(GuestIsCheckedIn $event): void
@@ -280,10 +288,18 @@ final class SendCheckInEmailListener
280288
}
281289
}
282290
```
283-
!!! warning
284291

285-
autoconfigure need to be enabled, otherwise you need add the `event_sourcing.subscriber` tag.
286-
292+
You need to register the processor in the `event-sourcing.php` configuration file.
293+
294+
```php
295+
return [
296+
'subscribers' => [
297+
App\Subscribers\SendCheckInEmailProcessor::class,
298+
],
299+
];
300+
301+
```
302+
287303
!!! note
288304

289305
You can find out more about processor in the [library](https://event-sourcing.patchlevel.io/latest/subscription/)
@@ -295,8 +311,8 @@ We are now ready to use the Event Sourcing System. We can load, change and save
295311
```php
296312
namespace App\Hotel\Infrastructure\Controller;
297313

298-
use App\Hotel\Domain\Hotel;
299-
use App\Hotel\Infrastructure\Projection\HotelProjection;
314+
use App\Model\Hotel;
315+
use App\Subscribers\HotelProjection;
300316
use Illuminate\Http\Request;
301317
use Illuminate\Http\Response;
302318
use Patchlevel\EventSourcing\Aggregate\Uuid;

docs/pages/installation.md

Lines changed: 5 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -33,26 +33,16 @@ And then run the migrations:
3333
```bash
3434
php artisan migrate
3535
```
36-
## Middlewares (optional)
36+
## Middlewares
3737

38-
If you want to use the provided middlewares, you can add them to your `config/app.php`:
39-
40-
### Auto Setup Middleware
41-
42-
```php
43-
use Patchlevel\LaravelEventSourcing\Middleware\AutoSetupMiddleware;
44-
45-
->withMiddleware(static function (Middleware $middleware): void {
46-
$middleware->append(AutoSetupMiddleware::class);
47-
})
48-
```
49-
### Subscription Rebuild After File Change Middleware
38+
Some features need a middleware to work properly.
39+
You should add the middleware to your `bootstrap/app.php` file.
5040

5141
```php
52-
use Patchlevel\LaravelEventSourcing\Middleware\SubscriptionRebuildAfterFileChangeMiddleware;
42+
use Patchlevel\LaravelEventSourcing\Middleware\EventSourcingMiddleware;
5343

5444
->withMiddleware(static function (Middleware $middleware): void {
55-
$middleware->append(SubscriptionRebuildAfterFileChangeMiddleware::class);
45+
$middleware->append(EventSourcingMiddleware::class);
5646
})
5747
```
5848
!!! success

src/EventSourcingServiceProvider.php

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,7 @@
9595
use Patchlevel\Hydrator\Metadata\AttributeMetadataFactory;
9696
use Patchlevel\Hydrator\MetadataHydrator;
9797
use Patchlevel\LaravelEventSourcing\Middleware\AutoSetupMiddleware;
98+
use Patchlevel\LaravelEventSourcing\Middleware\EventSourcingMiddleware;
9899
use Patchlevel\LaravelEventSourcing\Middleware\SubscriptionRebuildAfterFileChangeMiddleware;
99100

100101
use function app;
@@ -605,6 +606,16 @@ private function registerSubscription(): void
605606
);
606607
});
607608

609+
$this->app->singleton(EventSourcingMiddleware::class, static function () {
610+
$autoSetup = config('event-sourcing.subscription.auto_setup.enabled');
611+
$rebuildAfterFileChange = config('event-sourcing.subscription.rebuild_after_file_change.enabled');
612+
613+
return new EventSourcingMiddleware(
614+
$autoSetup ? app(AutoSetupMiddleware::class) : null,
615+
$rebuildAfterFileChange ? app(SubscriptionRebuildAfterFileChangeMiddleware::class) : null,
616+
);
617+
});
618+
608619
$this->app->singleton(SubscriptionSetupCommand::class, static function () {
609620
return new SubscriptionSetupCommand(
610621
app(SubscriptionEngine::class),
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace Patchlevel\LaravelEventSourcing\Middleware;
6+
7+
use Closure;
8+
use Illuminate\Http\Request;
9+
use Illuminate\Http\Response;
10+
11+
class EventSourcingMiddleware
12+
{
13+
public function __construct(
14+
private readonly AutoSetupMiddleware|null $autoSetupMiddleware = null,
15+
private readonly SubscriptionRebuildAfterFileChangeMiddleware|null $subscriptionRebuildAfterFileChangeMiddleware = null,
16+
) {
17+
}
18+
19+
/** @param Closure(Request): Response $next */
20+
public function handle(Request $request, Closure $next): Response
21+
{
22+
$dummyNext = static function () {
23+
return new Response();
24+
};
25+
26+
if ($this->autoSetupMiddleware !== null) {
27+
$this->autoSetupMiddleware->handle($request, $dummyNext);
28+
}
29+
30+
if ($this->subscriptionRebuildAfterFileChangeMiddleware !== null) {
31+
$this->subscriptionRebuildAfterFileChangeMiddleware->handle($request, $dummyNext);
32+
}
33+
34+
return $next($request);
35+
}
36+
}

0 commit comments

Comments
 (0)