/** * @param mixed $content * @param array $options * * @return bool */ public function supports($content, array $options = []) { if (!is_array($content)) { return false; } return is_array_of($content, 'MyBB\\Core\\Database\\Models\\Post'); }
/** * @param Post[] $posts * * @return Post */ public function mergePosts(array $posts) { if (!is_array_of($posts, 'MyBB\\Core\\Database\\Models\\Post')) { throw new \InvalidArgumentException('$posts must be an array of Post objects'); } $collection = new Collection($posts); $collection = $collection->sortBy('created_at'); $firstPost = $collection->shift(); $firstPostContent = $firstPost->content; foreach ($collection as $post) { if ($post->author->id !== $firstPost->author->id) { throw new \InvalidArgumentException("All posts being merged must have the same author"); } $firstPostContent .= "\n[hr]\n" . $post->content; $this->deletePost($post); } $firstPost->content = $firstPostContent; $firstPost->content_parsed = $this->formatter->parse($firstPost->content); $firstPost->save(); return $firstPost; }