Skip to content

Commit

Permalink
revert & fix again
Browse files Browse the repository at this point in the history
  • Loading branch information
DavidBadura committed Mar 22, 2024
1 parent 644d450 commit a9e61ec
Show file tree
Hide file tree
Showing 10 changed files with 59 additions and 44 deletions.
4 changes: 4 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,10 @@ docs-inject-php:
.PHONY: docs-format
docs-format: docs-phpcs docs-inject-php

.PHONY: docs-php-lint
docs-php-lint: docs-extract-php
php -l docs_php/*.php | grep 'Parse error: '

.PHONY: docs-phpcs
docs-phpcs: docs-extract-php
vendor/bin/phpcbf docs_php --exclude=SlevomatCodingStandard.TypeHints.DeclareStrictTypes || true
Expand Down
14 changes: 9 additions & 5 deletions docs/pages/cli.md
Original file line number Diff line number Diff line change
Expand Up @@ -62,10 +62,11 @@ use Patchlevel\EventSourcing\Console\DoctrineHelper;
use Patchlevel\EventSourcing\Schema\DoctrineSchemaManager;
use Symfony\Component\Console\Application;

$store;
/* define your doctrine store */
$projectionist;
$store;

/* create projectionist */
$projectionist;

$cli = new Application('Event-Sourcing CLI');
$cli->setCatchExceptions(true);
Expand Down Expand Up @@ -103,15 +104,18 @@ use Doctrine\Migrations\Tools\Console\Command;
use Patchlevel\EventSourcing\Schema\DoctrineMigrationSchemaProvider;
use Patchlevel\EventSourcing\Schema\DoctrineSchemaDirector;

$connection; /* create connection */
$store; /* define your doctrine store */
/* create connection */
$connection;
/* define your doctrine store */
$store;

$schemaDirector = new DoctrineSchemaDirector(
$store,
$connection,
);

$migrationConfig; /* define your migration config */
/* define your migration config */
$migrationConfig;


$dependencyFactory = DependencyFactory::fromConnection(
Expand Down
12 changes: 6 additions & 6 deletions docs/pages/clock.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ $clock = new SystemClock();
$date = $clock->now(); // get the actual datetime
$date2 = $clock->now();

$date === $date2; // false
$date === $date2; // false
// $date == $date2 => false
// $date === $date2 => false
```
## FrozenClock

Expand All @@ -32,8 +32,8 @@ $date = new DateTimeImmutable();
$clock = new FrozenClock($date);
$frozenDate = $clock->now(); // gets the date provided before

$date === $frozenDate; // true
$date === $frozenDate; // false
// $date == $frozenDate => true
// $date === $frozenDate => false
```
The `FrozenClock` can also be updated with a new date, so you can test a jump in time.

Expand All @@ -48,8 +48,8 @@ $clock->update($secondDate);

$frozenDate = $clock->now();

$firstDate === $frozenDate; // false
$secondDate === $frozenDate; // true
// $firstDate == $frozenDate => false
// $secondDate == $frozenDate => true
```
Or you can use the `sleep` method to simulate a time jump.

Expand Down
3 changes: 1 addition & 2 deletions docs/pages/event_bus.md
Original file line number Diff line number Diff line change
Expand Up @@ -65,8 +65,7 @@ $message->customHeaders(); // ['application-id' => 'app']
If you want *all* the headers you can also retrieve them.

```php
$message->headers();

$headers = $message->headers();
/*
[
'aggregateName' => 'profile',
Expand Down
1 change: 1 addition & 0 deletions docs/pages/getting_started.md
Original file line number Diff line number Diff line change
Expand Up @@ -279,6 +279,7 @@ $connection = DriverManager::getConnection(['url' => 'mysql://user:secret@localh

$projectionConnection = DriverManager::getConnection(['url' => 'mysql://user:secret@localhost/projection']);

/* your own mailer */
$mailer;

$serializer = DefaultEventSerializer::createFromPaths(['src/Domain/Hotel/Event']);
Expand Down
29 changes: 25 additions & 4 deletions docs/pages/normalizer.md
Original file line number Diff line number Diff line change
Expand Up @@ -288,12 +288,33 @@ You also need to implement a `normalize` and `denormalize` method.
Finally, you have to allow the normalizer to be used as an attribute.

```php
use Patchlevel\Hydrator\Normalizer\DateTimeImmutableNormalizer;
use Patchlevel\Hydrator\Normalizer\InvalidArgument;
use Patchlevel\Hydrator\Normalizer\Normalizer;

final class DTO
#[Attribute(Attribute::TARGET_PROPERTY)]
class NameNormalizer implements Normalizer
{
#[DateTimeImmutableNormalizer]
public DateTimeImmutable $date;
public function normalize(mixed $value): string
{
if (!$value instanceof Name) {
throw InvalidArgument::withWrongType(Name::class, $value);
}

return $value->toString();
}

public function denormalize(mixed $value): Name|null
{
if ($value === null) {
return null;
}

if (!is_string($value)) {
throw InvalidArgument::withWrongType('string', $value);
}

return new Name($value);
}
}
```
!!! warning
Expand Down
19 changes: 2 additions & 17 deletions docs/pages/pipeline.md
Original file line number Diff line number Diff line change
Expand Up @@ -245,24 +245,9 @@ $middleware = new FilterEventMiddleware(static function (AggregateChanged $event
With this middleware you can exclude archived events.

```php
use Patchlevel\EventSourcing\Pipeline\Middleware\ExcludeEventMiddleware;
use Patchlevel\EventSourcing\Pipeline\Middleware\RecalculatePlayheadMiddleware;
use Patchlevel\EventSourcing\Pipeline\Middleware\ReplaceEventMiddleware;
use Patchlevel\EventSourcing\Pipeline\Pipeline;
use Patchlevel\EventSourcing\Pipeline\Source\StoreSource;
use Patchlevel\EventSourcing\Pipeline\Target\StoreTarget;
use Patchlevel\EventSourcing\Pipeline\Middleware\ExcludeArchivedEventMiddleware;

$pipeline = new Pipeline(
new StoreSource($oldStore),
new StoreTarget($newStore),
[
new ExcludeEventMiddleware([PrivacyAdded::class]),
new ReplaceEventMiddleware(OldVisited::class, static function (OldVisited $oldVisited) {
return new NewVisited($oldVisited->profileId());
}),
new RecalculatePlayheadMiddleware(),
],
);
$middleware = new ExcludeArchivedEventMiddleware();
```
!!! warning

Expand Down
11 changes: 9 additions & 2 deletions docs/pages/store.md
Original file line number Diff line number Diff line change
Expand Up @@ -275,7 +275,14 @@ There is also the possibility of executing a function in a transaction.
Then dbal takes care of starting a transaction, committing it and then possibly rollback it again.

```php
use Doctrine\DBAL\DriverManager;
$store->transactional(static function () use ($command, $bankAccountRepository): void {
$accountFrom = $bankAccountRepository->get($command->from());
$accountTo = $bankAccountRepository->get($command->to());

$connection = DriverManager::getConnection(['url' => 'mysql://user:secret@localhost/app']);
$accountFrom->transferMoney($command->to(), $command->amount());
$accountTo->receiveMoney($command->from(), $command->amount());

$bankAccountRepository->save($accountFrom);
$bankAccountRepository->save($accountTo);
});
```
8 changes: 1 addition & 7 deletions docs/pages/subscription.md
Original file line number Diff line number Diff line change
Expand Up @@ -572,13 +572,7 @@ All booting subscriptions will catch up to the current event stream.
After the boot process, the subscription is set to active or finished.

```php
use Patchlevel\EventSourcing\Attribute\Subscriber;
use Patchlevel\EventSourcing\Subscription\RunMode;

#[Subscriber('do_stuff', RunMode::Once)]
final class DoStuffSubscriber
{
}
$subscriptionEngine->boot($criteria);
```
### Run

Expand Down
2 changes: 1 addition & 1 deletion docs/pages/upcasting.md
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ final class EventStreamCleanupCommand extends Command

$pipeline->run();

return 0;
return Command::SUCCESS;
}
}
```
Expand Down

0 comments on commit a9e61ec

Please sign in to comment.