Created
June 12, 2021 21:56
-
-
Save morrislaptop/e4972f083ae3675972f2c31567a3c47e to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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