Пример #1
0
 private function replacePost(PostEntity $post)
 {
     $this->init();
     $sql = "REPLACE INTO posts (\n            id, title, content, excerpt\n        ) VALUES (\n            :id, :title, :content, :excerpt\n        )";
     $sth = $this->dbh->prepare($sql);
     $sth->execute(['id' => $post->getId(), 'title' => $post->getTitle(), 'content' => $post->getContent(), 'excerpt' => $post->getExcerpt()]);
 }
Пример #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;
 }