mirror of
https://github.com/flarum/core.git
synced 2025-08-17 22:01:44 +02:00
chore: update codebase to php8.1 (#3827)
* chore: set minimum php version to 8.1 Signed-off-by: Sami Mazouz <sychocouldy@gmail.com> * chore: update codebase to php8.1 Signed-off-by: Sami Mazouz <sychocouldy@gmail.com> * Apply fixes from StyleCI * chore: update workflow php version Signed-off-by: Sami Mazouz <sychocouldy@gmail.com> * fix: caught errors Signed-off-by: Sami Mazouz <sychocouldy@gmail.com> * fix: more caught errors Signed-off-by: Sami Mazouz <sychocouldy@gmail.com> * fix: phpstan caught errors Signed-off-by: Sami Mazouz <sychocouldy@gmail.com> * Apply fixes from StyleCI * fix: test-caught errors Signed-off-by: Sami Mazouz <sychocouldy@gmail.com> * fix: test-caught errors Signed-off-by: Sami Mazouz <sychocouldy@gmail.com> * fix: test-caught errors Signed-off-by: Sami Mazouz <sychocouldy@gmail.com> * fix: introduce `Flarum\Locale\TranslatorInterface` Signed-off-by: Sami Mazouz <sychocouldy@gmail.com> * Apply fixes from StyleCI * chore: remove mixin Signed-off-by: Sami Mazouz <sychocouldy@gmail.com> * fix: test-caught errors Signed-off-by: Sami Mazouz <sychocouldy@gmail.com> * fix: one last error Signed-off-by: Sami Mazouz <sychocouldy@gmail.com> --------- Signed-off-by: Sami Mazouz <sychocouldy@gmail.com> Co-authored-by: StyleCI Bot <bot@styleci.io>
This commit is contained in:
@@ -51,25 +51,25 @@ return [
|
||||
|
||||
(new Extend\ApiController(Controller\ShowDiscussionController::class))
|
||||
->addInclude('posts.likes')
|
||||
->loadWhere('posts.likes', [LoadLikesRelationship::class, 'mutateRelation'])
|
||||
->prepareDataForSerialization([LoadLikesRelationship::class, 'countRelation']),
|
||||
->loadWhere('posts.likes', LoadLikesRelationship::mutateRelation(...))
|
||||
->prepareDataForSerialization(LoadLikesRelationship::countRelation(...)),
|
||||
|
||||
(new Extend\ApiController(Controller\ListPostsController::class))
|
||||
->addInclude('likes')
|
||||
->loadWhere('likes', [LoadLikesRelationship::class, 'mutateRelation'])
|
||||
->prepareDataForSerialization([LoadLikesRelationship::class, 'countRelation']),
|
||||
->loadWhere('likes', LoadLikesRelationship::mutateRelation(...))
|
||||
->prepareDataForSerialization(LoadLikesRelationship::countRelation(...)),
|
||||
(new Extend\ApiController(Controller\ShowPostController::class))
|
||||
->addInclude('likes')
|
||||
->loadWhere('likes', [LoadLikesRelationship::class, 'mutateRelation'])
|
||||
->prepareDataForSerialization([LoadLikesRelationship::class, 'countRelation']),
|
||||
->loadWhere('likes', LoadLikesRelationship::mutateRelation(...))
|
||||
->prepareDataForSerialization(LoadLikesRelationship::countRelation(...)),
|
||||
(new Extend\ApiController(Controller\CreatePostController::class))
|
||||
->addInclude('likes')
|
||||
->loadWhere('likes', [LoadLikesRelationship::class, 'mutateRelation'])
|
||||
->prepareDataForSerialization([LoadLikesRelationship::class, 'countRelation']),
|
||||
->loadWhere('likes', LoadLikesRelationship::mutateRelation(...))
|
||||
->prepareDataForSerialization(LoadLikesRelationship::countRelation(...)),
|
||||
(new Extend\ApiController(Controller\UpdatePostController::class))
|
||||
->addInclude('likes')
|
||||
->loadWhere('likes', [LoadLikesRelationship::class, 'mutateRelation'])
|
||||
->prepareDataForSerialization([LoadLikesRelationship::class, 'countRelation']),
|
||||
->loadWhere('likes', LoadLikesRelationship::mutateRelation(...))
|
||||
->prepareDataForSerialization(LoadLikesRelationship::countRelation(...)),
|
||||
|
||||
(new Extend\Event())
|
||||
->listen(PostWasLiked::class, Listener\SendNotificationWhenPostIsLiked::class)
|
||||
|
@@ -16,14 +16,9 @@ use Flarum\User\User;
|
||||
|
||||
class LikePostPolicy extends AbstractPolicy
|
||||
{
|
||||
/**
|
||||
* @var SettingsRepositoryInterface
|
||||
*/
|
||||
protected $settings;
|
||||
|
||||
public function __construct(SettingsRepositoryInterface $settings)
|
||||
{
|
||||
$this->settings = $settings;
|
||||
public function __construct(
|
||||
protected SettingsRepositoryInterface $settings
|
||||
) {
|
||||
}
|
||||
|
||||
public function like(User $actor, Post $post)
|
||||
|
@@ -9,6 +9,7 @@
|
||||
|
||||
namespace Flarum\Likes\Api;
|
||||
|
||||
use Flarum\Api\Controller\AbstractSerializeController;
|
||||
use Flarum\Discussion\Discussion;
|
||||
use Flarum\Http\RequestUtil;
|
||||
use Flarum\Post\Post;
|
||||
@@ -19,15 +20,15 @@ use Psr\Http\Message\ServerRequestInterface;
|
||||
|
||||
class LoadLikesRelationship
|
||||
{
|
||||
public static $maxLikes = 4;
|
||||
public static int $maxLikes = 4;
|
||||
|
||||
public static function mutateRelation(BelongsToMany $query, ServerRequestInterface $request): BelongsToMany
|
||||
public static function mutateRelation(BelongsToMany $query, ServerRequestInterface $request): void
|
||||
{
|
||||
$actor = RequestUtil::getActor($request);
|
||||
|
||||
$grammar = $query->getQuery()->getGrammar();
|
||||
|
||||
return $query
|
||||
$query
|
||||
// So that we can tell if the current user has liked the post.
|
||||
->orderBy(new Expression($grammar->wrap('user_id').' = '.$actor->id), 'desc')
|
||||
// Limiting a relationship results is only possible because
|
||||
@@ -39,12 +40,14 @@ class LoadLikesRelationship
|
||||
/**
|
||||
* Called using the @see ApiController::prepareDataForSerialization extender.
|
||||
*/
|
||||
public static function countRelation($controller, $data): void
|
||||
public static function countRelation(AbstractSerializeController $controller, mixed $data): array
|
||||
{
|
||||
$loadable = null;
|
||||
|
||||
if ($data instanceof Discussion) {
|
||||
$loadable = $data->newCollection($data->posts)->filter(function ($post) {
|
||||
// We do this because the ShowDiscussionController manipulates the posts
|
||||
// in a way that some of them are just ids.
|
||||
$loadable = $data->posts->filter(function ($post) {
|
||||
return $post instanceof Post;
|
||||
});
|
||||
} elseif ($data instanceof Collection) {
|
||||
@@ -56,5 +59,7 @@ class LoadLikesRelationship
|
||||
if ($loadable) {
|
||||
$loadable->loadCount('likes');
|
||||
}
|
||||
|
||||
return [];
|
||||
}
|
||||
}
|
||||
|
@@ -14,23 +14,9 @@ use Flarum\User\User;
|
||||
|
||||
class PostWasLiked
|
||||
{
|
||||
/**
|
||||
* @var Post
|
||||
*/
|
||||
public $post;
|
||||
|
||||
/**
|
||||
* @var User
|
||||
*/
|
||||
public $user;
|
||||
|
||||
/**
|
||||
* @param Post $post
|
||||
* @param User $user
|
||||
*/
|
||||
public function __construct(Post $post, User $user)
|
||||
{
|
||||
$this->post = $post;
|
||||
$this->user = $user;
|
||||
public function __construct(
|
||||
public Post $post,
|
||||
public User $user
|
||||
) {
|
||||
}
|
||||
}
|
||||
|
@@ -14,23 +14,9 @@ use Flarum\User\User;
|
||||
|
||||
class PostWasUnliked
|
||||
{
|
||||
/**
|
||||
* @var Post
|
||||
*/
|
||||
public $post;
|
||||
|
||||
/**
|
||||
* @var User
|
||||
*/
|
||||
public $user;
|
||||
|
||||
/**
|
||||
* @param Post $post
|
||||
* @param User $user
|
||||
*/
|
||||
public function __construct(Post $post, User $user)
|
||||
{
|
||||
$this->post = $post;
|
||||
$this->user = $user;
|
||||
public function __construct(
|
||||
public Post $post,
|
||||
public User $user
|
||||
) {
|
||||
}
|
||||
}
|
||||
|
@@ -17,19 +17,13 @@ use Illuminate\Contracts\Events\Dispatcher;
|
||||
|
||||
class SaveLikesToDatabase
|
||||
{
|
||||
/**
|
||||
* @param Dispatcher $events
|
||||
*/
|
||||
public function subscribe(Dispatcher $events)
|
||||
public function subscribe(Dispatcher $events): void
|
||||
{
|
||||
$events->listen(Saving::class, [$this, 'whenPostIsSaving']);
|
||||
$events->listen(Deleted::class, [$this, 'whenPostIsDeleted']);
|
||||
$events->listen(Saving::class, $this->whenPostIsSaving(...));
|
||||
$events->listen(Deleted::class, $this->whenPostIsDeleted(...));
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Saving $event
|
||||
*/
|
||||
public function whenPostIsSaving(Saving $event)
|
||||
public function whenPostIsSaving(Saving $event): void
|
||||
{
|
||||
$post = $event->post;
|
||||
$data = $event->data;
|
||||
@@ -54,10 +48,7 @@ class SaveLikesToDatabase
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Deleted $event
|
||||
*/
|
||||
public function whenPostIsDeleted(Deleted $event)
|
||||
public function whenPostIsDeleted(Deleted $event): void
|
||||
{
|
||||
$event->post->likes()->detach();
|
||||
}
|
||||
|
@@ -15,20 +15,12 @@ use Flarum\Notification\NotificationSyncer;
|
||||
|
||||
class SendNotificationWhenPostIsLiked
|
||||
{
|
||||
/**
|
||||
* @var NotificationSyncer
|
||||
*/
|
||||
protected $notifications;
|
||||
|
||||
/**
|
||||
* @param NotificationSyncer $notifications
|
||||
*/
|
||||
public function __construct(NotificationSyncer $notifications)
|
||||
{
|
||||
$this->notifications = $notifications;
|
||||
public function __construct(
|
||||
protected NotificationSyncer $notifications
|
||||
) {
|
||||
}
|
||||
|
||||
public function handle(PostWasLiked $event)
|
||||
public function handle(PostWasLiked $event): void
|
||||
{
|
||||
if ($event->post->user && $event->post->user->id != $event->user->id) {
|
||||
$this->notifications->sync(
|
||||
|
@@ -15,20 +15,12 @@ use Flarum\Notification\NotificationSyncer;
|
||||
|
||||
class SendNotificationWhenPostIsUnliked
|
||||
{
|
||||
/**
|
||||
* @var NotificationSyncer
|
||||
*/
|
||||
protected $notifications;
|
||||
|
||||
/**
|
||||
* @param NotificationSyncer $notifications
|
||||
*/
|
||||
public function __construct(NotificationSyncer $notifications)
|
||||
{
|
||||
$this->notifications = $notifications;
|
||||
public function __construct(
|
||||
protected NotificationSyncer $notifications
|
||||
) {
|
||||
}
|
||||
|
||||
public function handle(PostWasUnliked $event)
|
||||
public function handle(PostWasUnliked $event): void
|
||||
{
|
||||
if ($event->post->user && $event->post->user->id != $event->user->id) {
|
||||
$this->notifications->sync(
|
||||
|
@@ -9,67 +9,40 @@
|
||||
|
||||
namespace Flarum\Likes\Notification;
|
||||
|
||||
use Flarum\Database\AbstractModel;
|
||||
use Flarum\Notification\Blueprint\BlueprintInterface;
|
||||
use Flarum\Post\Post;
|
||||
use Flarum\User\User;
|
||||
|
||||
class PostLikedBlueprint implements BlueprintInterface
|
||||
{
|
||||
/**
|
||||
* @var Post
|
||||
*/
|
||||
public $post;
|
||||
|
||||
/**
|
||||
* @var User
|
||||
*/
|
||||
public $user;
|
||||
|
||||
/**
|
||||
* @param Post $post
|
||||
* @param User $user
|
||||
*/
|
||||
public function __construct(Post $post, User $user)
|
||||
{
|
||||
$this->post = $post;
|
||||
$this->user = $user;
|
||||
public function __construct(
|
||||
public Post $post,
|
||||
public User $user
|
||||
) {
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function getSubject()
|
||||
public function getSubject(): ?AbstractModel
|
||||
{
|
||||
return $this->post;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function getFromUser()
|
||||
public function getFromUser(): ?User
|
||||
{
|
||||
return $this->user;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function getData()
|
||||
public function getData(): mixed
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public static function getType()
|
||||
public static function getType(): string
|
||||
{
|
||||
return 'postLiked';
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public static function getSubjectModel()
|
||||
public static function getSubjectModel(): string
|
||||
{
|
||||
return Post::class;
|
||||
}
|
||||
|
@@ -22,7 +22,7 @@ class LikedByFilter implements FilterInterface
|
||||
return 'likedBy';
|
||||
}
|
||||
|
||||
public function filter(FilterState $filterState, $filterValue, bool $negate)
|
||||
public function filter(FilterState $filterState, string|array $filterValue, bool $negate): void
|
||||
{
|
||||
$likedId = $this->asInt($filterValue);
|
||||
|
||||
|
@@ -11,17 +11,20 @@ namespace Flarum\Likes\Query;
|
||||
|
||||
use Flarum\Filter\FilterInterface;
|
||||
use Flarum\Filter\FilterState;
|
||||
use Flarum\Filter\ValidateFilterTrait;
|
||||
|
||||
class LikedFilter implements FilterInterface
|
||||
{
|
||||
use ValidateFilterTrait;
|
||||
|
||||
public function getFilterKey(): string
|
||||
{
|
||||
return 'liked';
|
||||
}
|
||||
|
||||
public function filter(FilterState $filterState, string $filterValue, bool $negate)
|
||||
public function filter(FilterState $filterState, string|array $filterValue, bool $negate): void
|
||||
{
|
||||
$likedId = trim($filterValue, '"');
|
||||
$likedId = $this->asString($filterValue);
|
||||
|
||||
$filterState
|
||||
->getQuery()
|
||||
|
Reference in New Issue
Block a user