예제 #1
0
 public function savePost(PostEntity $post)
 {
     if ($post->hasId()) {
         $this->replacePost($post);
     } else {
         $this->insertPost($post);
     }
 }
예제 #2
0
 public function savePost(PostEntity $post)
 {
     if (!$post->hasId()) {
         $post = $post->withId(uniqid());
     }
     foreach ($this->posts as $idx => $existing) {
         if ($post->sameIdAs($existing)) {
             $this->posts[$idx] = $post;
             return;
         }
     }
     $this->posts[] = $post;
 }