Last active
June 12, 2021 21:38
-
-
Save morrislaptop/4619cd66ebf69c152dd70af3a367bd8d to your computer and use it in GitHub Desktop.
This file contains 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 publishPost(DateTime $when) { | |
$this->recordThat(new PostPublishScheduled($when)); | |
if ($when < now()) { | |
$this->recordThat(new PostPublished()); | |
} | |
return $this; | |
} | |
public function publishPostNow() { | |
$this->recordThat(new PostPublished()); | |
return $this; | |
} | |
} | |
class PublishPostsConsole | |
{ | |
public function run() { | |
$posts = Post::toBePublished(); // query in the model | |
foreach ($posts as $post) { | |
PostAggregateRoot::retrieve($post->id) | |
->publishPostNow() | |
->persist(); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment