Skip to content

Commit

Permalink
removed serialize() on Event body
Browse files Browse the repository at this point in the history
  • Loading branch information
Mauro Cassani committed Aug 17, 2017
1 parent 6be299b commit a1b9892
Show file tree
Hide file tree
Showing 10 changed files with 15 additions and 17 deletions.
12 changes: 5 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -48,9 +48,8 @@ use SimpleEventStoreManager\Application\EventManager;
use SimpleEventStoreManager\Domain\Model\EventId;
use SimpleEventStoreManager\Domain\Model\Event;

$myEventId = new EventId();
$myEvent = new Event(
$myEventId,
new EventId(),
'Fully\\Qualified\\Event\\Name',
[
'key' => 'value',
Expand All @@ -59,9 +58,8 @@ $myEvent = new Event(
]
);

$myEventId2 = new EventId();
$myEvent2 = new Event(
$myEventId2,
new EventId(),
'Fully\\Qualified\\Event\\Name2',
[
'key' => 'value',
Expand Down Expand Up @@ -136,7 +134,7 @@ Array
'name' => 'Mauro',
'email' => '[email protected]'
...
] // Full event body
] // Full event body
)
```

Expand Down Expand Up @@ -210,7 +208,7 @@ class DummyEntityWasCreated implements EventInterface
) {
$this->id = $id;
$this->name = get_class($this);
$this->body = serialize($body);
$this->body = $body;
$this->occurred_on = ($occurred_on) ? new \DateTimeImmutable($occurred_on) : new \DateTimeImmutable();
}

Expand Down Expand Up @@ -250,7 +248,7 @@ $releasedEvents = $dummyEntity->releaseEvents();

```

## API Implementation
## Get Event Streams

You can use `EventQuery` to easily create a simple API endpoint to get event streams.

Expand Down
2 changes: 1 addition & 1 deletion src/Domain/Model/Event.php
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ public function __construct(
) {
$this->id = $id;
$this->name = $name;
$this->body = serialize($body);
$this->body = $body;
$this->occurred_on = ($occurred_on) ? new \DateTimeImmutable($occurred_on) : new \DateTimeImmutable();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ function (EventInterface $event) {
return [
'id' => $event->id(),
'name' => $event->name(),
'body' => unserialize($event->body()),
'body' => $event->body(),
'occurred_on' => $event->occurredOn(),
];
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ public function __construct(EventInterface $event)
{
$this->id = $event->id();
$this->name = $event->name();
$this->body = unserialize($event->body());
$this->body = $event->body();
$this->occurred_on = $event->occurredOn();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ private function buildAggregateAsArray(Aggregate $aggregate)
$returnArray['events'][] = [
'id' => (string) $event->id(),
'name' => $event->name(),
'body' => unserialize($event->body()),
'body' => $event->body(),
'occurred_on' => $event->occurredOn()->format('Y-m-d H:i:s.u'),
];
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ private function saveEvent(EventInterface $event, Aggregate $aggregate)
{
$eventId = (string) $event->id();
$eventName = $event->name();
$eventBody = $event->body();
$eventBody = serialize($event->body());
$eventOccurredOn = $event->occurredOn()->format('Y-m-d H:i:s.u');

$this->events->insertOne([
Expand Down
2 changes: 1 addition & 1 deletion src/Infrastructure/Persistence/PdoAggregateRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,7 @@ private function saveEvent(EventInterface $event, Aggregate $aggregate)
$eventAggregateId = (string) $aggregate->id();
$eventAggregateName = $aggregate->name();
$eventName = $event->name();
$eventBody = $event->body();
$eventBody = serialize($event->body());
$eventOccurredOn = $event->occurredOn()->format('Y-m-d H:i:s.u');

$sql = 'INSERT INTO `events` (`id`, `aggregate_id`, `aggregate_name`, `name`, `body`, `occurred_on`) VALUES (:id, :aggregate_id, :aggregate_name, :name, :body, :occurred_on)';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ private function saveEvent(EventInterface $event, Aggregate $aggregate)
$eventId = (string) $event->id();
$eventAggregate = $aggregate;
$eventName = $event->name();
$eventBody = $event->body();
$eventBody = serialize($event->body());
$eventOccurredOn = $event->occurredOn()->format('Y-m-d H:i:s.u');
$redisKey = 'event:'.$eventId;

Expand Down
2 changes: 1 addition & 1 deletion src/Infrastructure/Services/ElasticService.php
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ private function manageAggregateIndex($aggregate)
*/
private function buildEventBody(EventInterface $event)
{
$body = (array) unserialize($event->body());
$body = (array) $event->body();
$body['class'] = (new \ReflectionClass($event))->getShortName();
$body['occurred_on'] = $event->occurredOn()->format('Y-m-d H:i:s.u');

Expand Down
4 changes: 2 additions & 2 deletions tests/Domain/AggregateTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ public function create_an_aggregate_with_some_events_and_record_them_with_EventR
$this->assertEquals($eventId, $event->id());
$this->assertEquals($aggregate->name(), 'dummy-aggregate');
$this->assertEquals($name, $event->name());
$this->assertEquals($body, unserialize($event->body()));
$this->assertEquals($body, $event->body());
$this->assertInstanceOf(DateTimeImmutable::class, $event->occurredOn());
$this->assertCount(1, $eventRecorder->releaseEvents());

Expand All @@ -79,7 +79,7 @@ public function create_an_aggregate_with_some_events_and_record_them_with_EventR

foreach ($releasedEvents as $event){
$this->assertInstanceOf(DummyEntityWasCreated::class, $event);
$this->assertInstanceOf(DummyEntity::class, unserialize($event->body()));
$this->assertInstanceOf(DummyEntity::class, $event->body());
}
}
}
Expand Down

0 comments on commit a1b9892

Please sign in to comment.