1
0
mirror of https://github.com/flarum/core.git synced 2025-10-18 02:06:08 +02:00

Get rid of Repository interfaces

This commit is contained in:
Toby Zerner
2015-07-04 18:38:59 +09:30
parent f7b6d8a568
commit 86811c6508
43 changed files with 203 additions and 341 deletions

View File

@@ -1,6 +1,6 @@
<?php namespace Flarum\Core\Posts\Commands;
use Flarum\Core\Posts\PostRepositoryInterface;
use Flarum\Core\Posts\PostRepository;
use Flarum\Core\Posts\Events\PostWillBeDeleted;
use Flarum\Core\Support\DispatchesEvents;
@@ -9,14 +9,14 @@ class DeletePostHandler
use DispatchesEvents;
/**
* @var PostRepositoryInterface
* @var PostRepository
*/
protected $posts;
/**
* @param PostRepositoryInterface $posts
* @param PostRepository $posts
*/
public function __construct(PostRepositoryInterface $posts)
public function __construct(PostRepository $posts)
{
$this->posts = $posts;
}

View File

@@ -1,6 +1,6 @@
<?php namespace Flarum\Core\Posts\Commands;
use Flarum\Core\Posts\PostRepositoryInterface;
use Flarum\Core\Posts\PostRepository;
use Flarum\Core\Posts\Events\PostWillBeSaved;
use Flarum\Core\Support\DispatchesEvents;
use Flarum\Core\Posts\CommentPost;
@@ -10,14 +10,14 @@ class EditPostHandler
use DispatchesEvents;
/**
* @var PostRepositoryInterface
* @var PostRepository
*/
protected $posts;
/**
* @param PostRepositoryInterface $posts
* @param PostRepository $posts
*/
public function __construct(PostRepositoryInterface $posts)
public function __construct(PostRepository $posts)
{
$this->posts = $posts;
}

View File

@@ -1,7 +1,7 @@
<?php namespace Flarum\Core\Posts\Commands;
use Flarum\Core\Posts\Events\PostWillBeSaved;
use Flarum\Core\Discussions\DiscussionRepositoryInterface;
use Flarum\Core\Discussions\DiscussionRepository;
use Flarum\Core\Posts\CommentPost;
use Flarum\Core\Support\DispatchesEvents;
use Flarum\Core\Notifications\NotificationSyncer;
@@ -11,7 +11,7 @@ class PostReplyHandler
use DispatchesEvents;
/**
* @var DiscussionRepositoryInterface
* @var DiscussionRepository
*/
protected $discussions;
@@ -21,10 +21,10 @@ class PostReplyHandler
protected $notifications;
/**
* @param DiscussionRepositoryInterface $discussions
* @param DiscussionRepository $discussions
* @param NotificationSyncer $notifications
*/
public function __construct(DiscussionRepositoryInterface $discussions, NotificationSyncer $notifications)
public function __construct(DiscussionRepository $discussions, NotificationSyncer $notifications)
{
$this->discussions = $discussions;
$this->notifications = $notifications;

View File

@@ -26,7 +26,7 @@ use Flarum\Core\Discussions\Search\Fulltext\DriverInterface;
// 14. Api\Discussions\ShowAction: eager load mentions
// 14. Serializers\DiscussionSerializer: load discussion-user state
class EloquentPostRepository implements PostRepositoryInterface
class PostRepository
{
protected $fulltext;
@@ -36,7 +36,14 @@ class EloquentPostRepository implements PostRepositoryInterface
}
/**
* {@inheritdoc}
* Find a post by ID, optionally making sure it is visible to a certain
* user, or throw an exception.
*
* @param integer $id
* @param \Flarum\Core\Users\User $actor
* @return \Flarum\Core\Posts\Post
*
* @throws \Illuminate\Database\Eloquent\ModelNotFoundException
*/
public function findOrFail($id, User $actor = null)
{
@@ -50,7 +57,15 @@ class EloquentPostRepository implements PostRepositoryInterface
}
/**
* {@inheritdoc}
* Find posts that match certain conditions, optionally making sure they
* are visible to a certain user, and/or using other criteria.
*
* @param array $where
* @param \Flarum\Core\Users\User|null $actor
* @param array $sort
* @param integer $count
* @param integer $start
* @return \Illuminate\Database\Eloquent\Collection
*/
public function findWhere($where = [], User $actor = null, $sort = [], $count = null, $start = 0)
{
@@ -68,7 +83,12 @@ class EloquentPostRepository implements PostRepositoryInterface
}
/**
* {@inheritdoc}
* Find posts by their IDs, optionally making sure they are visible to a
* certain user.
*
* @param array $ids
* @param \Flarum\Core\Users\User|null $actor
* @return \Illuminate\Database\Eloquent\Collection
*/
public function findByIds(array $ids, User $actor = null)
{
@@ -80,7 +100,12 @@ class EloquentPostRepository implements PostRepositoryInterface
}
/**
* {@inheritdoc}
* Find posts by matching a string of words against their content,
* optionally making sure they are visible to a certain user.
*
* @param string $string
* @param \Flarum\Core\Users\User|null $actor
* @return \Illuminate\Database\Eloquent\Collection
*/
public function findByContent($string, User $actor = null)
{
@@ -100,7 +125,14 @@ class EloquentPostRepository implements PostRepositoryInterface
}
/**
* {@inheritdoc}
* Get the position within a discussion where a post with a certain number
* is. If the post with that number does not exist, the index of the
* closest post to it will be returned.
*
* @param integer $discussionId
* @param integer $number
* @param \Flarum\Core\Users\User|null $actor
* @return integer
*/
public function getIndexForNumber($discussionId, $number, User $actor = null)
{

View File

@@ -1,63 +0,0 @@
<?php namespace Flarum\Core\Posts;
use Flarum\Core\Users\User;
interface PostRepositoryInterface
{
/**
* Find a post by ID, optionally making sure it is visible to a certain
* user, or throw an exception.
*
* @param integer $id
* @param \Flarum\Core\Users\User $actor
* @return \Flarum\Core\Posts\Post
*
* @throws \Illuminate\Database\Eloquent\ModelNotFoundException
*/
public function findOrFail($id, User $actor = null);
/**
* Find posts that match certain conditions, optionally making sure they
* are visible to a certain user, and/or using other criteria.
*
* @param array $where
* @param \Flarum\Core\Users\User|null $actor
* @param array $sort
* @param integer $count
* @param integer $start
* @return \Illuminate\Database\Eloquent\Collection
*/
public function findWhere($where = [], User $actor = null, $sort = [], $count = null, $start = 0);
/**
* Find posts by their IDs, optionally making sure they are visible to a
* certain user.
*
* @param array $ids
* @param \Flarum\Core\Users\User|null $actor
* @return \Illuminate\Database\Eloquent\Collection
*/
public function findByIds(array $ids, User $actor = null);
/**
* Find posts by matching a string of words against their content,
* optionally making sure they are visible to a certain user.
*
* @param string $string
* @param \Flarum\Core\Users\User|null $actor
* @return \Illuminate\Database\Eloquent\Collection
*/
public function findByContent($string, User $actor = null);
/**
* Get the position within a discussion where a post with a certain number
* is. If the post with that number does not exist, the index of the
* closest post to it will be returned.
*
* @param integer $discussionId
* @param integer $number
* @param \Flarum\Core\Users\User|null $actor
* @return integer
*/
public function getIndexForNumber($discussionId, $number, User $actor = null);
}

View File

@@ -60,9 +60,5 @@ class PostsServiceProvider extends ServiceProvider
*/
public function register()
{
$this->app->bind(
'Flarum\Core\Posts\PostRepositoryInterface',
'Flarum\Core\Posts\EloquentPostRepository'
);
}
}