Skip to content

Instantly share code, notes, and snippets.

@morrislaptop
Created June 12, 2021 21:56
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save morrislaptop/e4972f083ae3675972f2c31567a3c47e to your computer and use it in GitHub Desktop.
Save morrislaptop/e4972f083ae3675972f2c31567a3c47e to your computer and use it in GitHub Desktop.
<?php
class PostAggregateRoot
{
public function applyPostPublished(PostPublished $event) {
$this->status = 'future';
$this->publishDate = $event->publishDate;
}
public function timeElapsed(DateTime $now) {
if ($this->status == 'future' && $now->greaterThan($this->publishDate)) {
$this->recordThat(new PostPublished());
}
// other time events to execute..
return $this;
}
}
class PublishPostsConsole
{
public function run() {
$posts = StoredEvents::postUuids(); // get all posts
foreach ($posts as $post) {
PostAggregateRoot::retrieve($post->id)
->timeElapsed(now())
->persist();
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment