From 2e2617e5b04138e474f04fb317510749ba992eaf Mon Sep 17 00:00:00 2001 From: Toby Zerner Date: Tue, 5 May 2015 14:28:40 +0930 Subject: [PATCH] Clean up post type API --- framework/core/src/Core/CoreServiceProvider.php | 4 ++-- framework/core/src/Core/Models/CommentPost.php | 7 +++++++ framework/core/src/Core/Models/DiscussionRenamedPost.php | 8 +++++++- framework/core/src/Core/Models/Post.php | 8 ++++---- 4 files changed, 20 insertions(+), 7 deletions(-) diff --git a/framework/core/src/Core/CoreServiceProvider.php b/framework/core/src/Core/CoreServiceProvider.php index f88cd2885..572a8bf1c 100644 --- a/framework/core/src/Core/CoreServiceProvider.php +++ b/framework/core/src/Core/CoreServiceProvider.php @@ -113,8 +113,8 @@ class CoreServiceProvider extends ServiceProvider public function registerPostTypes() { - Post::addType('comment', 'Flarum\Core\Models\CommentPost'); - Post::addType('discussionRenamed', 'Flarum\Core\Models\DiscussionRenamedPost'); + Post::addType('Flarum\Core\Models\CommentPost'); + Post::addType('Flarum\Core\Models\DiscussionRenamedPost'); CommentPost::setFormatter($this->app['flarum.formatter']); } diff --git a/framework/core/src/Core/Models/CommentPost.php b/framework/core/src/Core/Models/CommentPost.php index cb81e62e8..619d6bd0f 100755 --- a/framework/core/src/Core/Models/CommentPost.php +++ b/framework/core/src/Core/Models/CommentPost.php @@ -8,6 +8,13 @@ use Flarum\Core\Events\PostWasRestored; class CommentPost extends Post { + /** + * The type of post this is, to be stored in the posts table. + * + * @var string + */ + public static $type = 'comment'; + /** * The text formatter instance. * diff --git a/framework/core/src/Core/Models/DiscussionRenamedPost.php b/framework/core/src/Core/Models/DiscussionRenamedPost.php index d10231ee7..f02ee934c 100755 --- a/framework/core/src/Core/Models/DiscussionRenamedPost.php +++ b/framework/core/src/Core/Models/DiscussionRenamedPost.php @@ -2,6 +2,13 @@ class DiscussionRenamedPost extends ActivityPost { + /** + * The type of post this is, to be stored in the posts table. + * + * @var string + */ + public static $type = 'discussionRenamed'; + /** * Merge the post into another post of the same type. * @@ -35,7 +42,6 @@ class DiscussionRenamedPost extends ActivityPost $post->time = time(); $post->discussion_id = $discussionId; $post->user_id = $userId; - $post->type = 'discussionRenamed'; return $post; } diff --git a/framework/core/src/Core/Models/Post.php b/framework/core/src/Core/Models/Post.php index 1a48bc71b..24e63bebc 100755 --- a/framework/core/src/Core/Models/Post.php +++ b/framework/core/src/Core/Models/Post.php @@ -58,6 +58,7 @@ class Post extends Model parent::boot(); static::creating(function ($post) { + $post->type = $post::$type; $post->number = ++$post->discussion->number_index; $post->discussion->save(); }); @@ -161,13 +162,12 @@ class Post extends Model /** * Register a post type and its model class. * - * @param string $type - * @param string $class + * @param string $class * @return void */ - public static function addType($type, $class) + public static function addType($class) { - static::$types[$type] = $class; + static::$types[$class::$type] = $class; } public static function getTypes()