mirror of
https://github.com/flarum/framework.git
synced 2024-11-22 04:56:37 +08: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:
parent
34a04b0746
commit
6f11e044a7
2
.github/workflows/REUSABLE_backend.yml
vendored
2
.github/workflows/REUSABLE_backend.yml
vendored
|
@ -25,7 +25,7 @@ on:
|
|||
description: Versions of PHP to test with. Should be array of strings encoded as JSON array
|
||||
type: string
|
||||
required: false
|
||||
default: '["7.3", "7.4", "8.0", "8.1", "8.2"]'
|
||||
default: '["8.1", "8.2"]'
|
||||
|
||||
php_extensions:
|
||||
description: PHP extensions to install.
|
||||
|
|
|
@ -85,7 +85,7 @@
|
|||
"flarum/testing": "self.version"
|
||||
},
|
||||
"require": {
|
||||
"php": ">=7.3",
|
||||
"php": "^8.1",
|
||||
"ext-json": "*",
|
||||
"components/font-awesome": "^5.14.0",
|
||||
"composer/composer": "^2.0",
|
||||
|
|
|
@ -14,17 +14,12 @@ use Flarum\Approval\Event\PostWasApproved;
|
|||
|
||||
class SubmitHam
|
||||
{
|
||||
/**
|
||||
* @var Akismet
|
||||
*/
|
||||
protected $akismet;
|
||||
|
||||
public function __construct(Akismet $akismet)
|
||||
{
|
||||
$this->akismet = $akismet;
|
||||
public function __construct(
|
||||
protected Akismet $akismet
|
||||
) {
|
||||
}
|
||||
|
||||
public function handle(PostWasApproved $event)
|
||||
public function handle(PostWasApproved $event): void
|
||||
{
|
||||
if (! $this->akismet->isConfigured()) {
|
||||
return;
|
||||
|
|
|
@ -14,17 +14,12 @@ use Flarum\Post\Event\Hidden;
|
|||
|
||||
class SubmitSpam
|
||||
{
|
||||
/**
|
||||
* @var Akismet
|
||||
*/
|
||||
protected $akismet;
|
||||
|
||||
public function __construct(Akismet $akismet)
|
||||
{
|
||||
$this->akismet = $akismet;
|
||||
public function __construct(
|
||||
protected Akismet $akismet
|
||||
) {
|
||||
}
|
||||
|
||||
public function handle(Hidden $event)
|
||||
public function handle(Hidden $event): void
|
||||
{
|
||||
if (! $this->akismet->isConfigured()) {
|
||||
return;
|
||||
|
|
|
@ -18,22 +18,13 @@ use Flarum\Settings\SettingsRepositoryInterface;
|
|||
|
||||
class ValidatePost
|
||||
{
|
||||
/**
|
||||
* @var Akismet
|
||||
*/
|
||||
protected $akismet;
|
||||
/**
|
||||
* @var SettingsRepositoryInterface
|
||||
*/
|
||||
private $settings;
|
||||
|
||||
public function __construct(Akismet $akismet, SettingsRepositoryInterface $settings)
|
||||
{
|
||||
$this->akismet = $akismet;
|
||||
$this->settings = $settings;
|
||||
public function __construct(
|
||||
protected Akismet $akismet,
|
||||
protected SettingsRepositoryInterface $settings
|
||||
) {
|
||||
}
|
||||
|
||||
public function handle(Saving $event)
|
||||
public function handle(Saving $event): void
|
||||
{
|
||||
if (! $this->akismet->isConfigured()) {
|
||||
return;
|
||||
|
|
|
@ -20,7 +20,7 @@ use Illuminate\Container\Container;
|
|||
|
||||
class AkismetProvider extends AbstractServiceProvider
|
||||
{
|
||||
public function register()
|
||||
public function register(): void
|
||||
{
|
||||
$this->container->bind(Akismet::class, function (Container $container) {
|
||||
/** @var SettingsRepositoryInterface $settings */
|
||||
|
|
|
@ -37,7 +37,7 @@ return [
|
|||
->cast('is_approved', 'bool'),
|
||||
|
||||
(new Extend\ApiSerializer(BasicDiscussionSerializer::class))
|
||||
->attribute('isApproved', function ($serializer, Discussion $discussion) {
|
||||
->attribute('isApproved', function (BasicDiscussionSerializer $serializer, Discussion $discussion): bool {
|
||||
return $discussion->is_approved;
|
||||
}),
|
||||
|
||||
|
@ -65,8 +65,8 @@ return [
|
|||
->scope(Access\ScopePrivateDiscussionVisibility::class, 'viewPrivate'),
|
||||
|
||||
(new Extend\ModelPrivate(Discussion::class))
|
||||
->checker([Listener\UnapproveNewContent::class, 'markUnapprovedContentAsPrivate']),
|
||||
->checker(Listener\UnapproveNewContent::markUnapprovedContentAsPrivate(...)),
|
||||
|
||||
(new Extend\ModelPrivate(CommentPost::class))
|
||||
->checker([Listener\UnapproveNewContent::class, 'markUnapprovedContentAsPrivate']),
|
||||
->checker(Listener\UnapproveNewContent::markUnapprovedContentAsPrivate(...)),
|
||||
];
|
||||
|
|
|
@ -14,11 +14,7 @@ use Illuminate\Database\Eloquent\Builder;
|
|||
|
||||
class ScopePrivateDiscussionVisibility
|
||||
{
|
||||
/**
|
||||
* @param Builder $query
|
||||
* @param User $actor
|
||||
*/
|
||||
public function __invoke(User $actor, Builder $query)
|
||||
public function __invoke(User $actor, Builder $query): void
|
||||
{
|
||||
// All statements need to be wrapped in an orWhere, since we're adding a
|
||||
// subset of private discussions that should be visible, not restricting the visible
|
||||
|
|
|
@ -16,11 +16,7 @@ use Illuminate\Database\Eloquent\Builder;
|
|||
|
||||
class ScopePrivatePostVisibility
|
||||
{
|
||||
/**
|
||||
* @param Builder $query
|
||||
* @param User $actor
|
||||
*/
|
||||
public function __invoke(User $actor, Builder $query)
|
||||
public function __invoke(User $actor, Builder $query): void
|
||||
{
|
||||
// All statements need to be wrapped in an orWhere, since we're adding a
|
||||
// subset of private posts that should be visible, not restricting the visible
|
||||
|
|
|
@ -15,10 +15,7 @@ use Flarum\User\User;
|
|||
|
||||
class TagPolicy extends AbstractPolicy
|
||||
{
|
||||
/**
|
||||
* @return bool|null
|
||||
*/
|
||||
public function addToDiscussion(User $actor, Tag $tag)
|
||||
public function addToDiscussion(User $actor, Tag $tag): bool
|
||||
{
|
||||
return $actor->can('discussion.startWithoutApproval', $tag);
|
||||
}
|
||||
|
|
|
@ -14,25 +14,9 @@ use Flarum\User\User;
|
|||
|
||||
class PostWasApproved
|
||||
{
|
||||
/**
|
||||
* The post that was approved.
|
||||
*
|
||||
* @var Post
|
||||
*/
|
||||
public $post;
|
||||
|
||||
/**
|
||||
* @var User
|
||||
*/
|
||||
public $actor;
|
||||
|
||||
/**
|
||||
* @param Post $post
|
||||
* @param User $actor
|
||||
*/
|
||||
public function __construct(Post $post, User $actor)
|
||||
{
|
||||
$this->post = $post;
|
||||
$this->actor = $actor;
|
||||
public function __construct(
|
||||
public Post $post,
|
||||
public User $actor
|
||||
) {
|
||||
}
|
||||
}
|
||||
|
|
|
@ -15,15 +15,12 @@ use Illuminate\Contracts\Events\Dispatcher;
|
|||
|
||||
class ApproveContent
|
||||
{
|
||||
/**
|
||||
* @param Dispatcher $events
|
||||
*/
|
||||
public function subscribe(Dispatcher $events)
|
||||
public function subscribe(Dispatcher $events): void
|
||||
{
|
||||
$events->listen(Saving::class, [$this, 'approvePost']);
|
||||
$events->listen(Saving::class, $this->approvePost(...));
|
||||
}
|
||||
|
||||
public function approvePost(Saving $event)
|
||||
public function approvePost(Saving $event): void
|
||||
{
|
||||
$attributes = $event->data['attributes'];
|
||||
$post = $event->post;
|
||||
|
|
|
@ -18,18 +18,12 @@ use Illuminate\Contracts\Events\Dispatcher;
|
|||
|
||||
class UnapproveNewContent
|
||||
{
|
||||
/**
|
||||
* @param Dispatcher $events
|
||||
*/
|
||||
public function subscribe(Dispatcher $events)
|
||||
public function subscribe(Dispatcher $events): void
|
||||
{
|
||||
$events->listen(Saving::class, [$this, 'unapproveNewPosts']);
|
||||
$events->listen(Saving::class, $this->unapproveNewPosts(...));
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Saving $event
|
||||
*/
|
||||
public function unapproveNewPosts(Saving $event)
|
||||
public function unapproveNewPosts(Saving $event): void
|
||||
{
|
||||
$post = $event->post;
|
||||
|
||||
|
@ -63,14 +57,12 @@ class UnapproveNewContent
|
|||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Discussion|CommentPost $instance
|
||||
* @return bool|null
|
||||
*/
|
||||
public static function markUnapprovedContentAsPrivate($instance)
|
||||
public static function markUnapprovedContentAsPrivate(Discussion|CommentPost $instance): ?bool
|
||||
{
|
||||
if (! $instance->is_approved) {
|
||||
return true;
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -13,7 +13,7 @@ use Flarum\Approval\Event\PostWasApproved;
|
|||
|
||||
class UpdateDiscussionAfterPostApproval
|
||||
{
|
||||
public function handle(PostWasApproved $event)
|
||||
public function handle(PostWasApproved $event): void
|
||||
{
|
||||
$post = $event->post;
|
||||
$discussion = $post->discussion;
|
||||
|
|
|
@ -13,7 +13,7 @@ use s9e\TextFormatter\Configurator;
|
|||
|
||||
class Configure
|
||||
{
|
||||
public function __invoke(Configurator $config)
|
||||
public function __invoke(Configurator $config): void
|
||||
{
|
||||
$this->addTagsFromRepositories($config);
|
||||
$this->adaptHighlightJs($config);
|
||||
|
|
|
@ -9,19 +9,14 @@
|
|||
|
||||
namespace Flarum\BBCode;
|
||||
|
||||
use Flarum\Locale\TranslatorInterface;
|
||||
use s9e\TextFormatter\Renderer;
|
||||
use Symfony\Contracts\Translation\TranslatorInterface;
|
||||
|
||||
class Render
|
||||
{
|
||||
/**
|
||||
* @var TranslatorInterface
|
||||
*/
|
||||
protected $translator;
|
||||
|
||||
public function __construct(TranslatorInterface $translator)
|
||||
{
|
||||
$this->translator = $translator;
|
||||
public function __construct(
|
||||
protected TranslatorInterface $translator
|
||||
) {
|
||||
}
|
||||
|
||||
public function __invoke(Renderer $renderer, $context, string $xml): string
|
||||
|
|
|
@ -16,17 +16,12 @@ use Illuminate\Database\Eloquent\Builder;
|
|||
|
||||
class ScopeFlagVisibility
|
||||
{
|
||||
/**
|
||||
* @var ExtensionManager
|
||||
*/
|
||||
protected $extensions;
|
||||
|
||||
public function __construct(ExtensionManager $extensions)
|
||||
{
|
||||
$this->extensions = $extensions;
|
||||
public function __construct(
|
||||
protected ExtensionManager $extensions
|
||||
) {
|
||||
}
|
||||
|
||||
public function __invoke(User $actor, Builder $query)
|
||||
public function __invoke(User $actor, Builder $query): void
|
||||
{
|
||||
if ($this->extensions->isEnabled('flarum-tags')) {
|
||||
$query
|
||||
|
|
|
@ -16,20 +16,12 @@ use Flarum\User\User;
|
|||
|
||||
class AddCanFlagAttribute
|
||||
{
|
||||
/**
|
||||
* @var SettingsRepositoryInterface
|
||||
*/
|
||||
protected $settings;
|
||||
|
||||
/**
|
||||
* @param SettingsRepositoryInterface $settings
|
||||
*/
|
||||
public function __construct(SettingsRepositoryInterface $settings)
|
||||
{
|
||||
$this->settings = $settings;
|
||||
public function __construct(
|
||||
protected SettingsRepositoryInterface $settings
|
||||
) {
|
||||
}
|
||||
|
||||
public function __invoke(PostSerializer $serializer, Post $post)
|
||||
public function __invoke(PostSerializer $serializer, Post $post): bool
|
||||
{
|
||||
return $serializer->getActor()->can('flag', $post) && $this->checkFlagOwnPostSetting($serializer->getActor(), $post);
|
||||
}
|
||||
|
|
|
@ -15,20 +15,12 @@ use Flarum\User\User;
|
|||
|
||||
class AddFlagsApiAttributes
|
||||
{
|
||||
/**
|
||||
* @var SettingsRepositoryInterface
|
||||
*/
|
||||
protected $settings;
|
||||
|
||||
/**
|
||||
* @param SettingsRepositoryInterface $settings
|
||||
*/
|
||||
public function __construct(SettingsRepositoryInterface $settings)
|
||||
{
|
||||
$this->settings = $settings;
|
||||
public function __construct(
|
||||
protected SettingsRepositoryInterface $settings
|
||||
) {
|
||||
}
|
||||
|
||||
public function __invoke(ForumSerializer $serializer)
|
||||
public function __invoke(ForumSerializer $serializer): array
|
||||
{
|
||||
$attributes = [
|
||||
'canViewFlags' => $serializer->getActor()->hasPermissionLike('discussion.viewFlags')
|
||||
|
@ -41,11 +33,7 @@ class AddFlagsApiAttributes
|
|||
return $attributes;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param User $actor
|
||||
* @return int
|
||||
*/
|
||||
protected function getFlagCount(User $actor)
|
||||
protected function getFlagCount(User $actor): int
|
||||
{
|
||||
return Flag::whereVisibleTo($actor)->distinct()->count('flags.post_id');
|
||||
}
|
||||
|
|
|
@ -14,16 +14,12 @@ use Flarum\User\User;
|
|||
|
||||
class AddNewFlagCountAttribute
|
||||
{
|
||||
public function __invoke(CurrentUserSerializer $serializer, User $user)
|
||||
public function __invoke(CurrentUserSerializer $serializer, User $user): int
|
||||
{
|
||||
return (int) $this->getNewFlagCount($user);
|
||||
return $this->getNewFlagCount($user);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param User $actor
|
||||
* @return int
|
||||
*/
|
||||
protected function getNewFlagCount(User $actor)
|
||||
protected function getNewFlagCount(User $actor): int
|
||||
{
|
||||
$query = Flag::whereVisibleTo($actor);
|
||||
|
||||
|
|
|
@ -12,6 +12,7 @@ namespace Flarum\Flags\Api\Controller;
|
|||
use Flarum\Api\Controller\AbstractCreateController;
|
||||
use Flarum\Flags\Api\Serializer\FlagSerializer;
|
||||
use Flarum\Flags\Command\CreateFlag;
|
||||
use Flarum\Flags\Flag;
|
||||
use Flarum\Http\RequestUtil;
|
||||
use Illuminate\Contracts\Bus\Dispatcher;
|
||||
use Illuminate\Support\Arr;
|
||||
|
@ -20,37 +21,20 @@ use Tobscure\JsonApi\Document;
|
|||
|
||||
class CreateFlagController extends AbstractCreateController
|
||||
{
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public $serializer = FlagSerializer::class;
|
||||
public ?string $serializer = FlagSerializer::class;
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public $include = [
|
||||
public array $include = [
|
||||
'post',
|
||||
'post.flags',
|
||||
'user'
|
||||
];
|
||||
|
||||
/**
|
||||
* @var Dispatcher
|
||||
*/
|
||||
protected $bus;
|
||||
|
||||
/**
|
||||
* @param Dispatcher $bus
|
||||
*/
|
||||
public function __construct(Dispatcher $bus)
|
||||
{
|
||||
$this->bus = $bus;
|
||||
public function __construct(
|
||||
protected Dispatcher $bus
|
||||
) {
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function data(ServerRequestInterface $request, Document $document)
|
||||
protected function data(ServerRequestInterface $request, Document $document): Flag
|
||||
{
|
||||
return $this->bus->dispatch(
|
||||
new CreateFlag(RequestUtil::getActor($request), Arr::get($request->getParsedBody(), 'data', []))
|
||||
|
|
|
@ -18,23 +18,12 @@ use Psr\Http\Message\ServerRequestInterface;
|
|||
|
||||
class DeleteFlagsController extends AbstractDeleteController
|
||||
{
|
||||
/**
|
||||
* @var Dispatcher
|
||||
*/
|
||||
protected $bus;
|
||||
|
||||
/**
|
||||
* @param Dispatcher $bus
|
||||
*/
|
||||
public function __construct(Dispatcher $bus)
|
||||
{
|
||||
$this->bus = $bus;
|
||||
public function __construct(
|
||||
protected Dispatcher $bus
|
||||
) {
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function delete(ServerRequestInterface $request)
|
||||
protected function delete(ServerRequestInterface $request): void
|
||||
{
|
||||
$this->bus->dispatch(
|
||||
new DeleteFlags(Arr::get($request->getQueryParams(), 'id'), RequestUtil::getActor($request), $request->getParsedBody())
|
||||
|
|
|
@ -19,25 +19,16 @@ use Tobscure\JsonApi\Document;
|
|||
|
||||
class ListFlagsController extends AbstractListController
|
||||
{
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public $serializer = FlagSerializer::class;
|
||||
public ?string $serializer = FlagSerializer::class;
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public $include = [
|
||||
public array $include = [
|
||||
'user',
|
||||
'post',
|
||||
'post.user',
|
||||
'post.discussion'
|
||||
];
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function data(ServerRequestInterface $request, Document $document)
|
||||
protected function data(ServerRequestInterface $request, Document $document): iterable
|
||||
{
|
||||
$actor = RequestUtil::getActor($request);
|
||||
$include = $this->extractInclude($request);
|
||||
|
|
|
@ -14,42 +14,34 @@ use Flarum\Api\Serializer\BasicUserSerializer;
|
|||
use Flarum\Api\Serializer\PostSerializer;
|
||||
use Flarum\Flags\Flag;
|
||||
use InvalidArgumentException;
|
||||
use Tobscure\JsonApi\Relationship;
|
||||
|
||||
class FlagSerializer extends AbstractSerializer
|
||||
{
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected $type = 'flags';
|
||||
|
||||
protected function getDefaultAttributes($flag)
|
||||
protected function getDefaultAttributes(object|array $model): array
|
||||
{
|
||||
if (! ($flag instanceof Flag)) {
|
||||
if (! ($model instanceof Flag)) {
|
||||
throw new InvalidArgumentException(
|
||||
get_class($this).' can only serialize instances of '.Flag::class
|
||||
);
|
||||
}
|
||||
|
||||
return [
|
||||
'type' => $flag->type,
|
||||
'reason' => $flag->reason,
|
||||
'reasonDetail' => $flag->reason_detail,
|
||||
'createdAt' => $this->formatDate($flag->created_at),
|
||||
'type' => $model->type,
|
||||
'reason' => $model->reason,
|
||||
'reasonDetail' => $model->reason_detail,
|
||||
'createdAt' => $this->formatDate($model->created_at),
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* @return \Tobscure\JsonApi\Relationship
|
||||
*/
|
||||
protected function post($flag)
|
||||
protected function post(Flag $flag): ?Relationship
|
||||
{
|
||||
return $this->hasOne($flag, PostSerializer::class);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return \Tobscure\JsonApi\Relationship
|
||||
*/
|
||||
protected function user($flag)
|
||||
protected function user(Flag $flag): ?Relationship
|
||||
{
|
||||
return $this->hasOne($flag, BasicUserSerializer::class);
|
||||
}
|
||||
|
|
|
@ -13,27 +13,9 @@ use Flarum\User\User;
|
|||
|
||||
class CreateFlag
|
||||
{
|
||||
/**
|
||||
* The user performing the action.
|
||||
*
|
||||
* @var User
|
||||
*/
|
||||
public $actor;
|
||||
|
||||
/**
|
||||
* The attributes of the new flag.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
public $data;
|
||||
|
||||
/**
|
||||
* @param User $actor The user performing the action.
|
||||
* @param array $data The attributes of the new flag.
|
||||
*/
|
||||
public function __construct(User $actor, array $data)
|
||||
{
|
||||
$this->actor = $actor;
|
||||
$this->data = $data;
|
||||
public function __construct(
|
||||
public User $actor,
|
||||
public array $data
|
||||
) {
|
||||
}
|
||||
}
|
||||
|
|
|
@ -13,58 +13,26 @@ use Carbon\Carbon;
|
|||
use Flarum\Flags\Event\Created;
|
||||
use Flarum\Flags\Flag;
|
||||
use Flarum\Foundation\ValidationException;
|
||||
use Flarum\Locale\TranslatorInterface;
|
||||
use Flarum\Post\CommentPost;
|
||||
use Flarum\Post\PostRepository;
|
||||
use Flarum\Settings\SettingsRepositoryInterface;
|
||||
use Flarum\User\Exception\PermissionDeniedException;
|
||||
use Illuminate\Events\Dispatcher;
|
||||
use Illuminate\Support\Arr;
|
||||
use Symfony\Contracts\Translation\TranslatorInterface;
|
||||
use Tobscure\JsonApi\Exception\InvalidParameterException;
|
||||
|
||||
class CreateFlagHandler
|
||||
{
|
||||
/**
|
||||
* @var PostRepository
|
||||
*/
|
||||
protected $posts;
|
||||
|
||||
/**
|
||||
* @var TranslatorInterface
|
||||
*/
|
||||
protected $translator;
|
||||
|
||||
/**
|
||||
* @var SettingsRepositoryInterface
|
||||
*/
|
||||
protected $settings;
|
||||
|
||||
/**
|
||||
* @var Dispatcher
|
||||
*/
|
||||
protected $events;
|
||||
|
||||
/**
|
||||
* @param PostRepository $posts
|
||||
* @param TranslatorInterface $translator
|
||||
* @param SettingsRepositoryInterface $settings
|
||||
* @param Dispatcher $events
|
||||
*/
|
||||
public function __construct(PostRepository $posts, TranslatorInterface $translator, SettingsRepositoryInterface $settings, Dispatcher $events)
|
||||
{
|
||||
$this->posts = $posts;
|
||||
$this->translator = $translator;
|
||||
$this->settings = $settings;
|
||||
$this->events = $events;
|
||||
public function __construct(
|
||||
protected PostRepository $posts,
|
||||
protected TranslatorInterface $translator,
|
||||
protected SettingsRepositoryInterface $settings,
|
||||
protected Dispatcher $events
|
||||
) {
|
||||
}
|
||||
|
||||
/**
|
||||
* @param CreateFlag $command
|
||||
* @return Flag
|
||||
* @throws InvalidParameterException
|
||||
* @throws ValidationException
|
||||
*/
|
||||
public function handle(CreateFlag $command)
|
||||
public function handle(CreateFlag $command): Flag
|
||||
{
|
||||
$actor = $command->actor;
|
||||
$data = $command->data;
|
||||
|
|
|
@ -13,34 +13,10 @@ use Flarum\User\User;
|
|||
|
||||
class DeleteFlags
|
||||
{
|
||||
/**
|
||||
* The ID of the post to delete flags for.
|
||||
*
|
||||
* @var int
|
||||
*/
|
||||
public $postId;
|
||||
|
||||
/**
|
||||
* The user performing the action.
|
||||
*
|
||||
* @var User
|
||||
*/
|
||||
public $actor;
|
||||
|
||||
/**
|
||||
* @var array
|
||||
*/
|
||||
public $data;
|
||||
|
||||
/**
|
||||
* @param int $postId The ID of the post to delete flags for.
|
||||
* @param User $actor The user performing the action.
|
||||
* @param array $data
|
||||
*/
|
||||
public function __construct($postId, User $actor, array $data = [])
|
||||
{
|
||||
$this->postId = $postId;
|
||||
$this->actor = $actor;
|
||||
$this->data = $data;
|
||||
public function __construct(
|
||||
public int $postId,
|
||||
public User $actor,
|
||||
public array $data = []
|
||||
) {
|
||||
}
|
||||
}
|
||||
|
|
|
@ -17,31 +17,13 @@ use Illuminate\Events\Dispatcher;
|
|||
|
||||
class DeleteFlagsHandler
|
||||
{
|
||||
/**
|
||||
* @var PostRepository
|
||||
*/
|
||||
protected $posts;
|
||||
|
||||
/**
|
||||
* @var Dispatcher
|
||||
*/
|
||||
protected $events;
|
||||
|
||||
/**
|
||||
* @param PostRepository $posts
|
||||
* @param Dispatcher $events
|
||||
*/
|
||||
public function __construct(PostRepository $posts, Dispatcher $events)
|
||||
{
|
||||
$this->posts = $posts;
|
||||
$this->events = $events;
|
||||
public function __construct(
|
||||
protected PostRepository $posts,
|
||||
protected Dispatcher $events
|
||||
) {
|
||||
}
|
||||
|
||||
/**
|
||||
* @param DeleteFlags $command
|
||||
* @return Post
|
||||
*/
|
||||
public function handle(DeleteFlags $command)
|
||||
public function handle(DeleteFlags $command): Post
|
||||
{
|
||||
$actor = $command->actor;
|
||||
|
||||
|
|
|
@ -14,30 +14,10 @@ use Flarum\User\User;
|
|||
|
||||
class Created
|
||||
{
|
||||
/**
|
||||
* @var Flag
|
||||
*/
|
||||
public $flag;
|
||||
|
||||
/**
|
||||
* @var User
|
||||
*/
|
||||
public $actor;
|
||||
|
||||
/**
|
||||
* @var array
|
||||
*/
|
||||
public $data;
|
||||
|
||||
/**
|
||||
* @param Flag $flag
|
||||
* @param User $actor
|
||||
* @param array $data
|
||||
*/
|
||||
public function __construct(Flag $flag, User $actor, array $data = [])
|
||||
{
|
||||
$this->flag = $flag;
|
||||
$this->actor = $actor;
|
||||
$this->data = $data;
|
||||
public function __construct(
|
||||
public Flag $flag,
|
||||
public User $actor,
|
||||
public array $data = []
|
||||
) {
|
||||
}
|
||||
}
|
||||
|
|
|
@ -14,30 +14,10 @@ use Flarum\User\User;
|
|||
|
||||
class Deleting
|
||||
{
|
||||
/**
|
||||
* @var Flag
|
||||
*/
|
||||
public $flag;
|
||||
|
||||
/**
|
||||
* @var User
|
||||
*/
|
||||
public $actor;
|
||||
|
||||
/**
|
||||
* @var array
|
||||
*/
|
||||
public $data;
|
||||
|
||||
/**
|
||||
* @param Flag $flag
|
||||
* @param User $actor
|
||||
* @param array $data
|
||||
*/
|
||||
public function __construct(Flag $flag, User $actor, array $data = [])
|
||||
{
|
||||
$this->flag = $flag;
|
||||
$this->actor = $actor;
|
||||
$this->data = $data;
|
||||
public function __construct(
|
||||
public Flag $flag,
|
||||
public User $actor,
|
||||
public array $data = []
|
||||
) {
|
||||
}
|
||||
}
|
||||
|
|
|
@ -18,30 +18,10 @@ use Flarum\User\User;
|
|||
*/
|
||||
class FlagsWillBeDeleted
|
||||
{
|
||||
/**
|
||||
* @var Post
|
||||
*/
|
||||
public $post;
|
||||
|
||||
/**
|
||||
* @var User
|
||||
*/
|
||||
public $actor;
|
||||
|
||||
/**
|
||||
* @var array
|
||||
*/
|
||||
public $data;
|
||||
|
||||
/**
|
||||
* @param Post $post
|
||||
* @param User $actor
|
||||
* @param array $data
|
||||
*/
|
||||
public function __construct(Post $post, User $actor, array $data = [])
|
||||
{
|
||||
$this->post = $post;
|
||||
$this->actor = $actor;
|
||||
$this->data = $data;
|
||||
public function __construct(
|
||||
public Post $post,
|
||||
public User $actor,
|
||||
public array $data = []
|
||||
) {
|
||||
}
|
||||
}
|
||||
|
|
|
@ -14,6 +14,7 @@ use Flarum\Database\AbstractModel;
|
|||
use Flarum\Database\ScopeVisibilityTrait;
|
||||
use Flarum\Post\Post;
|
||||
use Flarum\User\User;
|
||||
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
||||
|
||||
/**
|
||||
* @property int $post_id
|
||||
|
@ -30,23 +31,14 @@ class Flag extends AbstractModel
|
|||
{
|
||||
use ScopeVisibilityTrait;
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected $dates = ['created_at'];
|
||||
|
||||
/**
|
||||
* @return \Illuminate\Database\Eloquent\Relations\BelongsTo
|
||||
*/
|
||||
public function post()
|
||||
public function post(): BelongsTo
|
||||
{
|
||||
return $this->belongsTo(Post::class);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return \Illuminate\Database\Eloquent\Relations\BelongsTo
|
||||
*/
|
||||
public function user()
|
||||
public function user(): BelongsTo
|
||||
{
|
||||
return $this->belongsTo(User::class);
|
||||
}
|
||||
|
|
|
@ -13,10 +13,7 @@ use Flarum\Post\Event\Deleted;
|
|||
|
||||
class DeleteFlags
|
||||
{
|
||||
/**
|
||||
* @param Deleted $event
|
||||
*/
|
||||
public function handle(Deleted $event)
|
||||
public function handle(Deleted $event): void
|
||||
{
|
||||
$event->post->flags()->delete();
|
||||
}
|
||||
|
|
|
@ -17,7 +17,7 @@ use Psr\Http\Message\ServerRequestInterface;
|
|||
|
||||
class PrepareFlagsApiData
|
||||
{
|
||||
public function __invoke(Controller\AbstractSerializeController $controller, $data, ServerRequestInterface $request)
|
||||
public function __invoke(Controller\AbstractSerializeController $controller, mixed $data, ServerRequestInterface $request): void
|
||||
{
|
||||
// For any API action that allows the 'flags' relationship to be
|
||||
// included, we need to preload this relationship onto the data (Post
|
||||
|
|
|
@ -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()
|
||||
|
|
|
@ -15,11 +15,6 @@ use Flarum\User\User;
|
|||
|
||||
class DiscussionPolicy extends AbstractPolicy
|
||||
{
|
||||
/**
|
||||
* @param User $actor
|
||||
* @param Discussion $discussion
|
||||
* @return string|void
|
||||
*/
|
||||
public function reply(User $actor, Discussion $discussion)
|
||||
{
|
||||
if ($discussion->is_locked && $actor->cannot('lock', $discussion)) {
|
||||
|
|
|
@ -14,23 +14,9 @@ use Flarum\User\User;
|
|||
|
||||
class DiscussionWasLocked
|
||||
{
|
||||
/**
|
||||
* @var Discussion
|
||||
*/
|
||||
public $discussion;
|
||||
|
||||
/**
|
||||
* @var User
|
||||
*/
|
||||
public $user;
|
||||
|
||||
/**
|
||||
* @param Discussion $discussion
|
||||
* @param User $user
|
||||
*/
|
||||
public function __construct(Discussion $discussion, User $user)
|
||||
{
|
||||
$this->discussion = $discussion;
|
||||
$this->user = $user;
|
||||
public function __construct(
|
||||
public Discussion $discussion,
|
||||
public User $user
|
||||
) {
|
||||
}
|
||||
}
|
||||
|
|
|
@ -14,23 +14,9 @@ use Flarum\User\User;
|
|||
|
||||
class DiscussionWasUnlocked
|
||||
{
|
||||
/**
|
||||
* @var Discussion
|
||||
*/
|
||||
public $discussion;
|
||||
|
||||
/**
|
||||
* @var User
|
||||
*/
|
||||
public $user;
|
||||
|
||||
/**
|
||||
* @param Discussion $discussion
|
||||
* @param User $user
|
||||
*/
|
||||
public function __construct(Discussion $discussion, User $user)
|
||||
{
|
||||
$this->discussion = $discussion;
|
||||
$this->user = $user;
|
||||
public function __construct(
|
||||
public Discussion $discussion,
|
||||
public User $user
|
||||
) {
|
||||
}
|
||||
}
|
||||
|
|
|
@ -16,17 +16,12 @@ use Flarum\Notification\NotificationSyncer;
|
|||
|
||||
class CreatePostWhenDiscussionIsLocked
|
||||
{
|
||||
/**
|
||||
* @var NotificationSyncer
|
||||
*/
|
||||
protected $notifications;
|
||||
|
||||
public function __construct(NotificationSyncer $notifications)
|
||||
{
|
||||
$this->notifications = $notifications;
|
||||
public function __construct(
|
||||
protected NotificationSyncer $notifications
|
||||
) {
|
||||
}
|
||||
|
||||
public function handle(DiscussionWasLocked $event)
|
||||
public function handle(DiscussionWasLocked $event): void
|
||||
{
|
||||
$post = DiscussionLockedPost::reply(
|
||||
$event->discussion->id,
|
||||
|
|
|
@ -16,17 +16,12 @@ use Flarum\Notification\NotificationSyncer;
|
|||
|
||||
class CreatePostWhenDiscussionIsUnlocked
|
||||
{
|
||||
/**
|
||||
* @var NotificationSyncer
|
||||
*/
|
||||
protected $notifications;
|
||||
|
||||
public function __construct(NotificationSyncer $notifications)
|
||||
{
|
||||
$this->notifications = $notifications;
|
||||
public function __construct(
|
||||
protected NotificationSyncer $notifications
|
||||
) {
|
||||
}
|
||||
|
||||
public function handle(DiscussionWasUnlocked $event)
|
||||
public function handle(DiscussionWasUnlocked $event): void
|
||||
{
|
||||
$post = DiscussionLockedPost::reply(
|
||||
$event->discussion->id,
|
||||
|
|
|
@ -15,7 +15,7 @@ use Flarum\Lock\Event\DiscussionWasUnlocked;
|
|||
|
||||
class SaveLockedToDatabase
|
||||
{
|
||||
public function handle(Saving $event)
|
||||
public function handle(Saving $event): void
|
||||
{
|
||||
if (isset($event->data['attributes']['isLocked'])) {
|
||||
$isLocked = (bool) $event->data['attributes']['isLocked'];
|
||||
|
|
|
@ -9,61 +9,40 @@
|
|||
|
||||
namespace Flarum\Lock\Notification;
|
||||
|
||||
use Flarum\Database\AbstractModel;
|
||||
use Flarum\Discussion\Discussion;
|
||||
use Flarum\Lock\Post\DiscussionLockedPost;
|
||||
use Flarum\Notification\Blueprint\BlueprintInterface;
|
||||
use Flarum\User\User;
|
||||
|
||||
class DiscussionLockedBlueprint implements BlueprintInterface
|
||||
{
|
||||
/**
|
||||
* @var DiscussionLockedPost
|
||||
*/
|
||||
protected $post;
|
||||
|
||||
/**
|
||||
* @param DiscussionLockedPost $post
|
||||
*/
|
||||
public function __construct(DiscussionLockedPost $post)
|
||||
{
|
||||
$this->post = $post;
|
||||
public function __construct(
|
||||
protected DiscussionLockedPost $post
|
||||
) {
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function getFromUser()
|
||||
public function getFromUser(): ?User
|
||||
{
|
||||
return $this->post->user;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function getSubject()
|
||||
public function getSubject(): ?AbstractModel
|
||||
{
|
||||
return $this->post->discussion;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function getData()
|
||||
public function getData(): array
|
||||
{
|
||||
return ['postNumber' => (int) $this->post->number];
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public static function getType()
|
||||
public static function getType(): string
|
||||
{
|
||||
return 'discussionLocked';
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public static function getSubjectModel()
|
||||
public static function getSubjectModel(): string
|
||||
{
|
||||
return Discussion::class;
|
||||
}
|
||||
|
|
|
@ -16,15 +16,9 @@ use Flarum\Post\Post;
|
|||
|
||||
class DiscussionLockedPost extends AbstractEventPost implements MergeableInterface
|
||||
{
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public static $type = 'discussionLocked';
|
||||
public static string $type = 'discussionLocked';
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function saveAfter(Post $previous = null)
|
||||
public function saveAfter(Post $previous = null): static
|
||||
{
|
||||
// If the previous post is another 'discussion locked' post, and it's
|
||||
// by the same user, then we can merge this post into it. If we find
|
||||
|
@ -47,15 +41,7 @@ class DiscussionLockedPost extends AbstractEventPost implements MergeableInterfa
|
|||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a new instance in reply to a discussion.
|
||||
*
|
||||
* @param int $discussionId
|
||||
* @param int $userId
|
||||
* @param bool $isLocked
|
||||
* @return static
|
||||
*/
|
||||
public static function reply($discussionId, $userId, $isLocked)
|
||||
public static function reply(int $discussionId, int $userId, bool $isLocked): static
|
||||
{
|
||||
$post = new static;
|
||||
|
||||
|
@ -67,14 +53,8 @@ class DiscussionLockedPost extends AbstractEventPost implements MergeableInterfa
|
|||
return $post;
|
||||
}
|
||||
|
||||
/**
|
||||
* Build the content attribute.
|
||||
*
|
||||
* @param bool $isLocked Whether or not the discussion is locked.
|
||||
* @return array
|
||||
*/
|
||||
public static function buildContent($isLocked)
|
||||
public static function buildContent(bool $isLocked): array
|
||||
{
|
||||
return ['locked' => (bool) $isLocked];
|
||||
return ['locked' => $isLocked];
|
||||
}
|
||||
}
|
||||
|
|
|
@ -17,14 +17,14 @@ use Illuminate\Database\Query\Builder;
|
|||
|
||||
class LockedFilterGambit extends AbstractRegexGambit implements FilterInterface
|
||||
{
|
||||
protected function getGambitPattern()
|
||||
protected function getGambitPattern(): string
|
||||
{
|
||||
return 'is:locked';
|
||||
}
|
||||
|
||||
protected function conditions(SearchState $searchState, array $matches, $negate)
|
||||
protected function conditions(SearchState $search, array $matches, bool $negate): void
|
||||
{
|
||||
$this->constrain($searchState->getQuery(), $negate);
|
||||
$this->constrain($search->getQuery(), $negate);
|
||||
}
|
||||
|
||||
public function getFilterKey(): string
|
||||
|
@ -32,12 +32,12 @@ class LockedFilterGambit extends AbstractRegexGambit implements FilterInterface
|
|||
return 'locked';
|
||||
}
|
||||
|
||||
public function filter(FilterState $filterState, $filterValue, bool $negate)
|
||||
public function filter(FilterState $filterState, string|array $filterValue, bool $negate): void
|
||||
{
|
||||
$this->constrain($filterState->getQuery(), $negate);
|
||||
}
|
||||
|
||||
protected function constrain(Builder $query, bool $negate)
|
||||
protected function constrain(Builder $query, bool $negate): void
|
||||
{
|
||||
$query->where('is_locked', ! $negate);
|
||||
}
|
||||
|
|
|
@ -80,8 +80,8 @@ return [
|
|||
'posts.mentionsUsers', 'posts.mentionsPosts', 'posts.mentionsPosts.user',
|
||||
'posts.mentionsGroups'
|
||||
])
|
||||
->loadWhere('posts.mentionedBy', [LoadMentionedByRelationship::class, 'mutateRelation'])
|
||||
->prepareDataForSerialization([LoadMentionedByRelationship::class, 'countRelation']),
|
||||
->loadWhere('posts.mentionedBy', LoadMentionedByRelationship::mutateRelation(...))
|
||||
->prepareDataForSerialization(LoadMentionedByRelationship::countRelation(...)),
|
||||
|
||||
(new Extend\ApiController(Controller\ListDiscussionsController::class))
|
||||
->load([
|
||||
|
@ -93,14 +93,14 @@ return [
|
|||
->addInclude(['mentionedBy', 'mentionedBy.user', 'mentionedBy.discussion'])
|
||||
// We wouldn't normally need to eager load on a single model,
|
||||
// but we do so here for visibility scoping.
|
||||
->loadWhere('mentionedBy', [LoadMentionedByRelationship::class, 'mutateRelation'])
|
||||
->prepareDataForSerialization([LoadMentionedByRelationship::class, 'countRelation']),
|
||||
->loadWhere('mentionedBy', LoadMentionedByRelationship::mutateRelation(...))
|
||||
->prepareDataForSerialization(LoadMentionedByRelationship::countRelation(...)),
|
||||
|
||||
(new Extend\ApiController(Controller\ListPostsController::class))
|
||||
->addInclude(['mentionedBy', 'mentionedBy.user', 'mentionedBy.discussion'])
|
||||
->load(['mentionsUsers', 'mentionsPosts', 'mentionsPosts.user', 'mentionsGroups'])
|
||||
->loadWhere('mentionedBy', [LoadMentionedByRelationship::class, 'mutateRelation'])
|
||||
->prepareDataForSerialization([LoadMentionedByRelationship::class, 'countRelation']),
|
||||
->loadWhere('mentionedBy', LoadMentionedByRelationship::mutateRelation(...))
|
||||
->prepareDataForSerialization(LoadMentionedByRelationship::countRelation(...)),
|
||||
|
||||
(new Extend\Settings)
|
||||
->serializeToForum('allowUsernameMentionFormat', 'flarum-mentions.allow_username_format', 'boolval'),
|
||||
|
|
|
@ -9,6 +9,7 @@
|
|||
|
||||
namespace Flarum\Mentions\Api;
|
||||
|
||||
use Flarum\Api\Controller\AbstractSerializeController;
|
||||
use Flarum\Discussion\Discussion;
|
||||
use Flarum\Http\RequestUtil;
|
||||
use Flarum\Post\Post;
|
||||
|
@ -22,13 +23,13 @@ use Psr\Http\Message\ServerRequestInterface;
|
|||
*/
|
||||
class LoadMentionedByRelationship
|
||||
{
|
||||
public static $maxMentionedBy = 4;
|
||||
public static int $maxMentionedBy = 4;
|
||||
|
||||
public static function mutateRelation(BelongsToMany $query, ServerRequestInterface $request)
|
||||
public static function mutateRelation(BelongsToMany $query, ServerRequestInterface $request): void
|
||||
{
|
||||
$actor = RequestUtil::getActor($request);
|
||||
|
||||
return $query
|
||||
$query
|
||||
->with(['mentionsPosts', 'mentionsPosts.user', 'mentionsUsers'])
|
||||
->whereVisibleTo($actor)
|
||||
->oldest()
|
||||
|
@ -41,13 +42,15 @@ class LoadMentionedByRelationship
|
|||
/**
|
||||
* Called using the @see ApiController::prepareDataForSerialization extender.
|
||||
*/
|
||||
public static function countRelation($controller, $data, ServerRequestInterface $request): void
|
||||
public static function countRelation(AbstractSerializeController $controller, mixed $data, ServerRequestInterface $request): array
|
||||
{
|
||||
$actor = RequestUtil::getActor($request);
|
||||
$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) {
|
||||
|
@ -63,5 +66,7 @@ class LoadMentionedByRelationship
|
|||
}
|
||||
]);
|
||||
}
|
||||
|
||||
return [];
|
||||
}
|
||||
}
|
||||
|
|
|
@ -30,23 +30,13 @@ class ConfigureMentions
|
|||
public const GROUP_MENTION_WITH_NAME_REGEX = '/\B@["“](?<groupname>((?!"#[a-z]{0,3}[0-9]+).)+)["|”]#g(?<id>[0-9]+)\b/';
|
||||
public const TAG_MENTION_WITH_SLUG_REGEX = '/(?:[^“"]|^)\B#(?<slug>[-_\p{L}\p{N}\p{M}]+)\b/ui';
|
||||
|
||||
/**
|
||||
* @var UrlGenerator
|
||||
*/
|
||||
protected $url;
|
||||
|
||||
/**
|
||||
* @var ExtensionManager
|
||||
*/
|
||||
protected $extensions;
|
||||
|
||||
public function __construct(UrlGenerator $url, ExtensionManager $extensions)
|
||||
{
|
||||
$this->url = $url;
|
||||
$this->extensions = $extensions;
|
||||
public function __construct(
|
||||
protected UrlGenerator $url,
|
||||
protected ExtensionManager $extensions
|
||||
) {
|
||||
}
|
||||
|
||||
public function __invoke(Configurator $config)
|
||||
public function __invoke(Configurator $config): void
|
||||
{
|
||||
$this->configureUserMentions($config);
|
||||
$this->configurePostMentions($config);
|
||||
|
|
|
@ -22,7 +22,7 @@ class MentionedFilter implements FilterInterface
|
|||
return 'mentioned';
|
||||
}
|
||||
|
||||
public function filter(FilterState $filterState, $filterValue, bool $negate)
|
||||
public function filter(FilterState $filterState, string|array $filterValue, bool $negate): void
|
||||
{
|
||||
$mentionedId = $this->asInt($filterValue);
|
||||
|
||||
|
|
|
@ -19,7 +19,7 @@ class MentionedPostFilter implements FilterInterface
|
|||
return 'mentionedPost';
|
||||
}
|
||||
|
||||
public function filter(FilterState $filterState, string $filterValue, bool $negate)
|
||||
public function filter(FilterState $filterState, string|array $filterValue, bool $negate): void
|
||||
{
|
||||
$mentionedId = trim($filterValue, '"');
|
||||
|
||||
|
|
|
@ -20,38 +20,15 @@ use s9e\TextFormatter\Parser;
|
|||
|
||||
class EagerLoadMentionedModels
|
||||
{
|
||||
/**
|
||||
* @var ExtensionManager
|
||||
*/
|
||||
protected $extensions;
|
||||
|
||||
/**
|
||||
* @var PostRepository
|
||||
*/
|
||||
protected $posts;
|
||||
|
||||
/**
|
||||
* @var GroupRepository
|
||||
*/
|
||||
protected $groups;
|
||||
|
||||
/**
|
||||
* @var TagRepository
|
||||
*/
|
||||
protected $tags;
|
||||
|
||||
public function __construct(ExtensionManager $extensions, PostRepository $posts, GroupRepository $groups, TagRepository $tags)
|
||||
{
|
||||
$this->extensions = $extensions;
|
||||
$this->posts = $posts;
|
||||
$this->groups = $groups;
|
||||
$this->tags = $tags;
|
||||
public function __construct(
|
||||
protected ExtensionManager $extensions,
|
||||
protected PostRepository $posts,
|
||||
protected GroupRepository $groups,
|
||||
protected TagRepository $tags
|
||||
) {
|
||||
}
|
||||
|
||||
/**
|
||||
* @param mixed|\Flarum\Post\CommentPost|null $context
|
||||
*/
|
||||
public function __invoke(Parser $parser, $context, string $text, ?User $actor): string
|
||||
public function __invoke(Parser $parser, mixed $context, string $text, ?User $actor): string
|
||||
{
|
||||
$callables = $this->getEagerLoaders();
|
||||
|
||||
|
|
|
@ -10,32 +10,19 @@
|
|||
namespace Flarum\Mentions\Formatter;
|
||||
|
||||
use Flarum\Group\Group;
|
||||
use Flarum\Locale\TranslatorInterface;
|
||||
use Flarum\Post\Post;
|
||||
use s9e\TextFormatter\Renderer;
|
||||
use s9e\TextFormatter\Utils;
|
||||
use Symfony\Contracts\Translation\TranslatorInterface;
|
||||
|
||||
class FormatGroupMentions
|
||||
{
|
||||
/**
|
||||
* @var TranslatorInterface
|
||||
*/
|
||||
private $translator;
|
||||
|
||||
public function __construct(TranslatorInterface $translator)
|
||||
{
|
||||
$this->translator = $translator;
|
||||
public function __construct(
|
||||
private readonly TranslatorInterface $translator
|
||||
) {
|
||||
}
|
||||
|
||||
/**
|
||||
* Configure rendering for group mentions.
|
||||
*
|
||||
* @param \s9e\TextFormatter\Renderer $renderer
|
||||
* @param mixed $context
|
||||
* @param string $xml
|
||||
* @return string
|
||||
*/
|
||||
public function __invoke(Renderer $renderer, $context, string $xml): string
|
||||
public function __invoke(Renderer $renderer, mixed $context, string $xml): string
|
||||
{
|
||||
return Utils::replaceAttributes($xml, 'GROUPMENTION', function ($attributes) use ($context) {
|
||||
$group = (($context && isset($context->getRelations()['mentionsGroups'])) || $context instanceof Post)
|
||||
|
|
|
@ -9,33 +9,19 @@
|
|||
|
||||
namespace Flarum\Mentions\Formatter;
|
||||
|
||||
use Flarum\Locale\TranslatorInterface;
|
||||
use Psr\Http\Message\ServerRequestInterface as Request;
|
||||
use s9e\TextFormatter\Renderer;
|
||||
use s9e\TextFormatter\Utils;
|
||||
use Symfony\Contracts\Translation\TranslatorInterface;
|
||||
|
||||
class FormatPostMentions
|
||||
{
|
||||
/**
|
||||
* @var TranslatorInterface
|
||||
*/
|
||||
private $translator;
|
||||
|
||||
public function __construct(TranslatorInterface $translator)
|
||||
{
|
||||
$this->translator = $translator;
|
||||
public function __construct(
|
||||
private readonly TranslatorInterface $translator
|
||||
) {
|
||||
}
|
||||
|
||||
/**
|
||||
* Configure rendering for post mentions.
|
||||
*
|
||||
* @param \s9e\TextFormatter\Renderer $renderer
|
||||
* @param mixed $context
|
||||
* @param string|null $xml
|
||||
* @param \Psr\Http\Message\ServerRequestInterface $request
|
||||
* @return string
|
||||
*/
|
||||
public function __invoke(Renderer $renderer, $context, $xml, Request $request = null)
|
||||
public function __invoke(Renderer $renderer, mixed $context, ?string $xml, Request $request = null): string
|
||||
{
|
||||
$post = $context;
|
||||
|
||||
|
|
|
@ -17,7 +17,7 @@ use s9e\TextFormatter\Utils;
|
|||
|
||||
class FormatTagMentions
|
||||
{
|
||||
public function __invoke(Renderer $renderer, $context, ?string $xml, Request $request = null): string
|
||||
public function __invoke(Renderer $renderer, mixed $context, ?string $xml, Request $request = null): string
|
||||
{
|
||||
return Utils::replaceAttributes($xml, 'TAGMENTION', function ($attributes) use ($context) {
|
||||
/** @var Tag|null $tag */
|
||||
|
|
|
@ -10,39 +10,21 @@
|
|||
namespace Flarum\Mentions\Formatter;
|
||||
|
||||
use Flarum\Http\SlugManager;
|
||||
use Flarum\Locale\TranslatorInterface;
|
||||
use Flarum\Post\Post;
|
||||
use Flarum\User\User;
|
||||
use s9e\TextFormatter\Renderer;
|
||||
use s9e\TextFormatter\Utils;
|
||||
use Symfony\Contracts\Translation\TranslatorInterface;
|
||||
|
||||
class FormatUserMentions
|
||||
{
|
||||
/**
|
||||
* @var SlugManager
|
||||
*/
|
||||
private $slugManager;
|
||||
|
||||
/**
|
||||
* @var TranslatorInterface
|
||||
*/
|
||||
private $translator;
|
||||
|
||||
public function __construct(SlugManager $slugManager, TranslatorInterface $translator)
|
||||
{
|
||||
$this->slugManager = $slugManager;
|
||||
$this->translator = $translator;
|
||||
public function __construct(
|
||||
private readonly TranslatorInterface $translator,
|
||||
private readonly SlugManager $slugManager
|
||||
) {
|
||||
}
|
||||
|
||||
/**
|
||||
* Configure rendering for user mentions.
|
||||
*
|
||||
* @param \s9e\TextFormatter\Renderer $renderer
|
||||
* @param mixed $context
|
||||
* @param string $xml
|
||||
* @return string $xml to be rendered
|
||||
*/
|
||||
public function __invoke(Renderer $renderer, $context, string $xml)
|
||||
public function __invoke(Renderer $renderer, mixed $context, string $xml): string
|
||||
{
|
||||
return Utils::replaceAttributes($xml, 'USERMENTION', function ($attributes) use ($context) {
|
||||
$user = (($context && isset($context->getRelations()['mentionsUsers'])) || $context instanceof Post)
|
||||
|
|
|
@ -9,42 +9,25 @@
|
|||
|
||||
namespace Flarum\Mentions\Formatter;
|
||||
|
||||
use Flarum\Locale\TranslatorInterface;
|
||||
use s9e\TextFormatter\Utils;
|
||||
use Symfony\Contracts\Translation\TranslatorInterface;
|
||||
|
||||
class UnparsePostMentions
|
||||
{
|
||||
/**
|
||||
* @var TranslatorInterface
|
||||
*/
|
||||
private $translator;
|
||||
|
||||
public function __construct(TranslatorInterface $translator)
|
||||
{
|
||||
$this->translator = $translator;
|
||||
public function __construct(
|
||||
private readonly TranslatorInterface $translator
|
||||
) {
|
||||
}
|
||||
|
||||
/**
|
||||
* Configure rendering for user mentions.
|
||||
*
|
||||
* @param string $xml
|
||||
* @param mixed $context
|
||||
* @return string $xml to be unparsed
|
||||
*/
|
||||
public function __invoke($context, string $xml)
|
||||
public function __invoke(mixed $context, string $xml): string
|
||||
{
|
||||
$xml = $this->updatePostMentionTags($context, $xml);
|
||||
$xml = $this->unparsePostMentionTags($xml);
|
||||
|
||||
return $xml;
|
||||
return $this->unparsePostMentionTags(
|
||||
$this->updatePostMentionTags($context, $xml)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Updates XML post mention tags before unparsing so that unparsing uses new display names.
|
||||
*
|
||||
* @param mixed $context
|
||||
* @param string $xml : Parsed text.
|
||||
* @return string $xml : Updated XML tags;
|
||||
*/
|
||||
protected function updatePostMentionTags($context, string $xml): string
|
||||
{
|
||||
|
@ -74,9 +57,6 @@ class UnparsePostMentions
|
|||
|
||||
/**
|
||||
* Transforms post mention tags from XML to raw unparsed content with updated format and display name.
|
||||
*
|
||||
* @param string $xml : Parsed text.
|
||||
* @return string : Unparsed text.
|
||||
*/
|
||||
protected function unparsePostMentionTags(string $xml): string
|
||||
{
|
||||
|
|
|
@ -15,29 +15,17 @@ use s9e\TextFormatter\Utils;
|
|||
|
||||
class UnparseTagMentions
|
||||
{
|
||||
/**
|
||||
* Configure rendering for user mentions.
|
||||
*
|
||||
* @param string $xml
|
||||
* @param mixed $context
|
||||
* @return string $xml to be unparsed
|
||||
*/
|
||||
public function __invoke($context, string $xml)
|
||||
public function __invoke(mixed $context, string $xml): string
|
||||
{
|
||||
$xml = $this->updateTagMentionTags($context, $xml);
|
||||
$xml = $this->unparseTagMentionTags($xml);
|
||||
|
||||
return $xml;
|
||||
return $this->unparseTagMentionTags(
|
||||
$this->updateTagMentionTags($context, $xml)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Updates XML user mention tags before unparsing so that unparsing uses new tag names.
|
||||
*
|
||||
* @param mixed $context
|
||||
* @param string $xml : Parsed text.
|
||||
* @return string $xml : Updated XML tags;
|
||||
*/
|
||||
protected function updateTagMentionTags($context, string $xml): string
|
||||
protected function updateTagMentionTags(mixed $context, string $xml): string
|
||||
{
|
||||
return Utils::replaceAttributes($xml, 'TAGMENTION', function (array $attributes) use ($context) {
|
||||
/** @var Tag|null $tag */
|
||||
|
@ -56,9 +44,6 @@ class UnparseTagMentions
|
|||
|
||||
/**
|
||||
* Transforms tag mention tags from XML to raw unparsed content with updated name.
|
||||
*
|
||||
* @param string $xml : Parsed text.
|
||||
* @return string : Unparsed text.
|
||||
*/
|
||||
protected function unparseTagMentionTags(string $xml): string
|
||||
{
|
||||
|
|
|
@ -9,46 +9,29 @@
|
|||
|
||||
namespace Flarum\Mentions\Formatter;
|
||||
|
||||
use Flarum\Locale\TranslatorInterface;
|
||||
use Flarum\Post\Post;
|
||||
use Flarum\User\User;
|
||||
use s9e\TextFormatter\Utils;
|
||||
use Symfony\Contracts\Translation\TranslatorInterface;
|
||||
|
||||
class UnparseUserMentions
|
||||
{
|
||||
/**
|
||||
* @var TranslatorInterface
|
||||
*/
|
||||
private $translator;
|
||||
|
||||
public function __construct(TranslatorInterface $translator)
|
||||
{
|
||||
$this->translator = $translator;
|
||||
public function __construct(
|
||||
private readonly TranslatorInterface $translator
|
||||
) {
|
||||
}
|
||||
|
||||
/**
|
||||
* Configure rendering for user mentions.
|
||||
*
|
||||
* @param string $xml
|
||||
* @param mixed $context
|
||||
* @return string $xml to be unparsed
|
||||
*/
|
||||
public function __invoke($context, string $xml)
|
||||
public function __invoke(mixed $context, string $xml): string
|
||||
{
|
||||
$xml = $this->updateUserMentionTags($context, $xml);
|
||||
$xml = $this->unparseUserMentionTags($xml);
|
||||
|
||||
return $xml;
|
||||
return $this->unparseUserMentionTags(
|
||||
$this->updateUserMentionTags($context, $xml)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Updates XML user mention tags before unparsing so that unparsing uses new display names.
|
||||
*
|
||||
* @param mixed $context
|
||||
* @param string $xml : Parsed text.
|
||||
* @return string $xml : Updated XML tags;
|
||||
*/
|
||||
protected function updateUserMentionTags($context, string $xml): string
|
||||
protected function updateUserMentionTags(mixed $context, string $xml): string
|
||||
{
|
||||
return Utils::replaceAttributes($xml, 'USERMENTION', function ($attributes) use ($context) {
|
||||
$user = (($context && isset($context->getRelations()['mentionsUsers'])) || $context instanceof Post)
|
||||
|
@ -71,9 +54,6 @@ class UnparseUserMentions
|
|||
|
||||
/**
|
||||
* Transforms user mention tags from XML to raw unparsed content with updated format and display name.
|
||||
*
|
||||
* @param string $xml : Parsed text.
|
||||
* @return string : Unparsed text.
|
||||
*/
|
||||
protected function unparseUserMentionTags(string $xml): string
|
||||
{
|
||||
|
|
|
@ -20,37 +20,14 @@ use Flarum\User\User;
|
|||
|
||||
class SendMentionsNotificationsJob extends AbstractJob
|
||||
{
|
||||
/**
|
||||
* @var CommentPost
|
||||
*/
|
||||
protected $post;
|
||||
private NotificationSyncer $notifications;
|
||||
|
||||
/**
|
||||
* @var array
|
||||
*/
|
||||
protected $userMentions;
|
||||
|
||||
/**
|
||||
* @var array
|
||||
*/
|
||||
protected $postMentions;
|
||||
|
||||
/**
|
||||
* @var array
|
||||
*/
|
||||
protected $groupMentions;
|
||||
|
||||
/**
|
||||
* @var NotificationSyncer
|
||||
*/
|
||||
private $notifications;
|
||||
|
||||
public function __construct(CommentPost $post, array $userMentions, array $postMentions, array $groupMentions)
|
||||
{
|
||||
$this->post = $post;
|
||||
$this->userMentions = $userMentions;
|
||||
$this->postMentions = $postMentions;
|
||||
$this->groupMentions = $groupMentions;
|
||||
public function __construct(
|
||||
protected CommentPost $post,
|
||||
protected array $userMentions,
|
||||
protected array $postMentions,
|
||||
protected array $groupMentions
|
||||
) {
|
||||
}
|
||||
|
||||
public function handle(NotificationSyncer $notifications): void
|
||||
|
@ -62,7 +39,7 @@ class SendMentionsNotificationsJob extends AbstractJob
|
|||
$this->notifyAboutGroupMentions($this->post, $this->groupMentions);
|
||||
}
|
||||
|
||||
protected function notifyAboutUserMentions(Post $post, array $mentioned)
|
||||
protected function notifyAboutUserMentions(Post $post, array $mentioned): void
|
||||
{
|
||||
$users = User::whereIn('id', $mentioned)
|
||||
->with('groups')
|
||||
|
@ -75,7 +52,7 @@ class SendMentionsNotificationsJob extends AbstractJob
|
|||
$this->notifications->sync(new UserMentionedBlueprint($post), $users);
|
||||
}
|
||||
|
||||
protected function notifyAboutPostMentions(Post $reply, array $mentioned)
|
||||
protected function notifyAboutPostMentions(Post $reply, array $mentioned): void
|
||||
{
|
||||
$posts = Post::with('user')
|
||||
->whereIn('id', $mentioned)
|
||||
|
@ -91,7 +68,7 @@ class SendMentionsNotificationsJob extends AbstractJob
|
|||
}
|
||||
}
|
||||
|
||||
protected function notifyAboutGroupMentions(Post $post, array $mentioned)
|
||||
protected function notifyAboutGroupMentions(Post $post, array $mentioned): void
|
||||
{
|
||||
$users = User::whereHas('groups', function ($query) use ($mentioned) {
|
||||
$query->whereIn('groups.id', $mentioned);
|
||||
|
|
|
@ -17,26 +17,13 @@ use Flarum\Post\Event\Hidden;
|
|||
|
||||
class UpdateMentionsMetadataWhenInvisible
|
||||
{
|
||||
/**
|
||||
* @var NotificationSyncer
|
||||
*/
|
||||
protected $notifications;
|
||||
|
||||
/**
|
||||
* @var ExtensionManager
|
||||
*/
|
||||
protected $extensions;
|
||||
|
||||
public function __construct(NotificationSyncer $notifications, ExtensionManager $extensions)
|
||||
{
|
||||
$this->notifications = $notifications;
|
||||
$this->extensions = $extensions;
|
||||
public function __construct(
|
||||
protected NotificationSyncer $notifications,
|
||||
protected ExtensionManager $extensions
|
||||
) {
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Deleted|Hidden $event
|
||||
*/
|
||||
public function handle($event)
|
||||
public function handle(Deleted|Hidden $event): void
|
||||
{
|
||||
// Remove user mentions
|
||||
$event->post->mentionsUsers()->sync([]);
|
||||
|
|
|
@ -22,26 +22,13 @@ use s9e\TextFormatter\Utils;
|
|||
|
||||
class UpdateMentionsMetadataWhenVisible
|
||||
{
|
||||
/**
|
||||
* @var ExtensionManager
|
||||
*/
|
||||
protected $extensions;
|
||||
|
||||
/**
|
||||
* @var Queue
|
||||
*/
|
||||
protected $queue;
|
||||
|
||||
public function __construct(ExtensionManager $extensions, Queue $queue)
|
||||
{
|
||||
$this->extensions = $extensions;
|
||||
$this->queue = $queue;
|
||||
public function __construct(
|
||||
protected ExtensionManager $extensions,
|
||||
protected Queue $queue
|
||||
) {
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Posted|Restored|Revised|PostWasApproved $event
|
||||
*/
|
||||
public function handle($event)
|
||||
public function handle(Restored|Revised|Posted|PostWasApproved $event): void
|
||||
{
|
||||
if (! $event->post instanceof CommentPost) {
|
||||
return;
|
||||
|
@ -74,25 +61,25 @@ class UpdateMentionsMetadataWhenVisible
|
|||
$this->queue->push(new SendMentionsNotificationsJob($event->post, $userMentions, $postMentions, $groupMentions));
|
||||
}
|
||||
|
||||
protected function syncUserMentions(Post $post, array $mentioned)
|
||||
protected function syncUserMentions(Post $post, array $mentioned): void
|
||||
{
|
||||
$post->mentionsUsers()->sync($mentioned);
|
||||
$post->unsetRelation('mentionsUsers');
|
||||
}
|
||||
|
||||
protected function syncPostMentions(Post $reply, array $mentioned)
|
||||
protected function syncPostMentions(Post $reply, array $mentioned): void
|
||||
{
|
||||
$reply->mentionsPosts()->sync($mentioned);
|
||||
$reply->unsetRelation('mentionsPosts');
|
||||
}
|
||||
|
||||
protected function syncGroupMentions(Post $post, array $mentioned)
|
||||
protected function syncGroupMentions(Post $post, array $mentioned): void
|
||||
{
|
||||
$post->mentionsGroups()->sync($mentioned);
|
||||
$post->unsetRelation('mentionsGroups');
|
||||
}
|
||||
|
||||
protected function syncTagMentions(Post $post, array $mentioned)
|
||||
protected function syncTagMentions(Post $post, array $mentioned): void
|
||||
{
|
||||
$post->mentionsTags()->sync($mentioned);
|
||||
$post->unsetRelation('mentionsTags');
|
||||
|
|
|
@ -9,61 +9,41 @@
|
|||
|
||||
namespace Flarum\Mentions\Notification;
|
||||
|
||||
use Flarum\Database\AbstractModel;
|
||||
use Flarum\Locale\TranslatorInterface;
|
||||
use Flarum\Notification\Blueprint\BlueprintInterface;
|
||||
use Flarum\Notification\MailableInterface;
|
||||
use Flarum\Post\Post;
|
||||
use Symfony\Contracts\Translation\TranslatorInterface;
|
||||
use Flarum\User\User;
|
||||
|
||||
class GroupMentionedBlueprint implements BlueprintInterface, MailableInterface
|
||||
{
|
||||
/**
|
||||
* @var Post
|
||||
*/
|
||||
public $post;
|
||||
|
||||
/**
|
||||
* @param Post $post
|
||||
*/
|
||||
public function __construct(Post $post)
|
||||
{
|
||||
$this->post = $post;
|
||||
public function __construct(
|
||||
public Post $post
|
||||
) {
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function getSubject()
|
||||
public function getSubject(): ?AbstractModel
|
||||
{
|
||||
return $this->post;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function getFromUser()
|
||||
public function getFromUser(): ?User
|
||||
{
|
||||
return $this->post->user;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function getData()
|
||||
public function getData(): mixed
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function getEmailView()
|
||||
public function getEmailView(): string|array
|
||||
{
|
||||
return ['text' => 'flarum-mentions::emails.groupMentioned'];
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function getEmailSubject(TranslatorInterface $translator)
|
||||
public function getEmailSubject(TranslatorInterface $translator): string
|
||||
{
|
||||
return $translator->trans('flarum-mentions.email.group_mentioned.subject', [
|
||||
'{mentioner_display_name}' => $this->post->user->display_name,
|
||||
|
@ -71,18 +51,12 @@ class GroupMentionedBlueprint implements BlueprintInterface, MailableInterface
|
|||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public static function getType()
|
||||
public static function getType(): string
|
||||
{
|
||||
return 'groupMentioned';
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public static function getSubjectModel()
|
||||
public static function getSubjectModel(): string
|
||||
{
|
||||
return Post::class;
|
||||
}
|
||||
|
|
|
@ -9,69 +9,42 @@
|
|||
|
||||
namespace Flarum\Mentions\Notification;
|
||||
|
||||
use Flarum\Database\AbstractModel;
|
||||
use Flarum\Locale\TranslatorInterface;
|
||||
use Flarum\Notification\Blueprint\BlueprintInterface;
|
||||
use Flarum\Notification\MailableInterface;
|
||||
use Flarum\Post\Post;
|
||||
use Symfony\Contracts\Translation\TranslatorInterface;
|
||||
use Flarum\User\User;
|
||||
|
||||
class PostMentionedBlueprint implements BlueprintInterface, MailableInterface
|
||||
{
|
||||
/**
|
||||
* @var Post
|
||||
*/
|
||||
public $post;
|
||||
|
||||
/**
|
||||
* @var Post
|
||||
*/
|
||||
public $reply;
|
||||
|
||||
/**
|
||||
* @param Post $post
|
||||
* @param Post $reply
|
||||
*/
|
||||
public function __construct(Post $post, Post $reply)
|
||||
{
|
||||
$this->post = $post;
|
||||
$this->reply = $reply;
|
||||
public function __construct(
|
||||
public Post $post,
|
||||
public Post $reply
|
||||
) {
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function getSubject()
|
||||
public function getSubject(): ?AbstractModel
|
||||
{
|
||||
return $this->post;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function getFromUser()
|
||||
public function getFromUser(): ?User
|
||||
{
|
||||
return $this->reply->user;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function getData()
|
||||
public function getData(): array
|
||||
{
|
||||
return ['replyNumber' => (int) $this->reply->number];
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function getEmailView()
|
||||
public function getEmailView(): string|array
|
||||
{
|
||||
return ['text' => 'flarum-mentions::emails.postMentioned'];
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function getEmailSubject(TranslatorInterface $translator)
|
||||
public function getEmailSubject(TranslatorInterface $translator): string
|
||||
{
|
||||
return $translator->trans('flarum-mentions.email.post_mentioned.subject', [
|
||||
'{replier_display_name}' => $this->reply->user->display_name,
|
||||
|
@ -79,18 +52,12 @@ class PostMentionedBlueprint implements BlueprintInterface, MailableInterface
|
|||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public static function getType()
|
||||
public static function getType(): string
|
||||
{
|
||||
return 'postMentioned';
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public static function getSubjectModel()
|
||||
public static function getSubjectModel(): string
|
||||
{
|
||||
return Post::class;
|
||||
}
|
||||
|
|
|
@ -9,61 +9,41 @@
|
|||
|
||||
namespace Flarum\Mentions\Notification;
|
||||
|
||||
use Flarum\Database\AbstractModel;
|
||||
use Flarum\Locale\TranslatorInterface;
|
||||
use Flarum\Notification\Blueprint\BlueprintInterface;
|
||||
use Flarum\Notification\MailableInterface;
|
||||
use Flarum\Post\Post;
|
||||
use Symfony\Contracts\Translation\TranslatorInterface;
|
||||
use Flarum\User\User;
|
||||
|
||||
class UserMentionedBlueprint implements BlueprintInterface, MailableInterface
|
||||
{
|
||||
/**
|
||||
* @var Post
|
||||
*/
|
||||
public $post;
|
||||
|
||||
/**
|
||||
* @param Post $post
|
||||
*/
|
||||
public function __construct(Post $post)
|
||||
{
|
||||
$this->post = $post;
|
||||
public function __construct(
|
||||
public Post $post
|
||||
) {
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function getSubject()
|
||||
public function getSubject(): ?AbstractModel
|
||||
{
|
||||
return $this->post;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function getFromUser()
|
||||
public function getFromUser(): ?User
|
||||
{
|
||||
return $this->post->user;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function getData()
|
||||
public function getData(): mixed
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function getEmailView()
|
||||
public function getEmailView(): string|array
|
||||
{
|
||||
return ['text' => 'flarum-mentions::emails.userMentioned'];
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function getEmailSubject(TranslatorInterface $translator)
|
||||
public function getEmailSubject(TranslatorInterface $translator): string
|
||||
{
|
||||
return $translator->trans('flarum-mentions.email.user_mentioned.subject', [
|
||||
'{mentioner_display_name}' => $this->post->user->display_name,
|
||||
|
@ -71,18 +51,12 @@ class UserMentionedBlueprint implements BlueprintInterface, MailableInterface
|
|||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public static function getType()
|
||||
public static function getType(): string
|
||||
{
|
||||
return 'userMentioned';
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public static function getSubjectModel()
|
||||
public static function getSubjectModel(): string
|
||||
{
|
||||
return Post::class;
|
||||
}
|
||||
|
|
|
@ -15,21 +15,11 @@ use Flarum\User\User;
|
|||
|
||||
class UserPolicy extends AbstractPolicy
|
||||
{
|
||||
/**
|
||||
* @var SettingsRepositoryInterface
|
||||
*/
|
||||
protected $settings;
|
||||
|
||||
public function __construct(SettingsRepositoryInterface $settings)
|
||||
{
|
||||
$this->settings = $settings;
|
||||
public function __construct(
|
||||
protected SettingsRepositoryInterface $settings
|
||||
) {
|
||||
}
|
||||
|
||||
/**
|
||||
* @param User $actor
|
||||
* @param User $user
|
||||
* @return bool|null
|
||||
*/
|
||||
public function editNickname(User $actor, User $user)
|
||||
{
|
||||
if ($actor->isGuest() && ! $user->exists && $this->settings->get('flarum-nicknames.set_on_registration')) {
|
||||
|
|
|
@ -9,29 +9,20 @@
|
|||
|
||||
namespace Flarum\Nicknames;
|
||||
|
||||
use Flarum\Locale\TranslatorInterface;
|
||||
use Flarum\Settings\SettingsRepositoryInterface;
|
||||
use Flarum\User\UserValidator;
|
||||
use Illuminate\Validation\Validator;
|
||||
use Symfony\Contracts\Translation\TranslatorInterface;
|
||||
|
||||
class AddNicknameValidation
|
||||
{
|
||||
/**
|
||||
* @var SettingsRepositoryInterface
|
||||
*/
|
||||
protected $settings;
|
||||
|
||||
/**
|
||||
* @var TranslatorInterface
|
||||
*/
|
||||
protected $translator;
|
||||
|
||||
public function __construct(SettingsRepositoryInterface $settings, TranslatorInterface $translator)
|
||||
{
|
||||
$this->settings = $settings;
|
||||
$this->translator = $translator;
|
||||
public function __construct(
|
||||
protected SettingsRepositoryInterface $settings,
|
||||
protected TranslatorInterface $translator
|
||||
) {
|
||||
}
|
||||
|
||||
public function __invoke($flarumValidator, Validator $validator)
|
||||
public function __invoke(UserValidator $flarumValidator, Validator $validator): void
|
||||
{
|
||||
$idSuffix = $flarumValidator->getUser() ? ','.$flarumValidator->getUser()->id : '';
|
||||
$rules = $validator->getRules();
|
||||
|
|
|
@ -16,6 +16,6 @@ class NicknameDriver implements DriverInterface
|
|||
{
|
||||
public function displayName(User $user): string
|
||||
{
|
||||
return $user->nickname ? $user->nickname : $user->username;
|
||||
return $user->nickname ?? $user->username;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -19,27 +19,16 @@ namespace Flarum\Nicknames;
|
|||
use Flarum\Search\GambitInterface;
|
||||
use Flarum\Search\SearchState;
|
||||
use Flarum\User\UserRepository;
|
||||
use Illuminate\Database\Eloquent\Builder;
|
||||
|
||||
class NicknameFullTextGambit implements GambitInterface
|
||||
{
|
||||
/**
|
||||
* @var UserRepository
|
||||
*/
|
||||
protected $users;
|
||||
|
||||
/**
|
||||
* @param \Flarum\User\UserRepository $users
|
||||
*/
|
||||
public function __construct(UserRepository $users)
|
||||
{
|
||||
$this->users = $users;
|
||||
public function __construct(
|
||||
protected UserRepository $users
|
||||
) {
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $searchValue
|
||||
* @return \Illuminate\Database\Eloquent\Builder
|
||||
*/
|
||||
private function getUserSearchSubQuery($searchValue)
|
||||
private function getUserSearchSubQuery(string $searchValue): Builder
|
||||
{
|
||||
return $this->users
|
||||
->query()
|
||||
|
@ -48,15 +37,12 @@ class NicknameFullTextGambit implements GambitInterface
|
|||
->orWhere('nickname', 'like', "{$searchValue}%");
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function apply(SearchState $search, $searchValue)
|
||||
public function apply(SearchState $search, string $bit): bool
|
||||
{
|
||||
$search->getQuery()
|
||||
->whereIn(
|
||||
'id',
|
||||
$this->getUserSearchSubQuery($searchValue)
|
||||
$this->getUserSearchSubQuery($bit)
|
||||
);
|
||||
|
||||
return true;
|
||||
|
|
|
@ -15,17 +15,12 @@ use Illuminate\Support\Arr;
|
|||
|
||||
class SaveNicknameToDatabase
|
||||
{
|
||||
/**
|
||||
* @var SettingsRepositoryInterface
|
||||
*/
|
||||
protected $settings;
|
||||
|
||||
public function __construct(SettingsRepositoryInterface $settings)
|
||||
{
|
||||
$this->settings = $settings;
|
||||
public function __construct(
|
||||
protected SettingsRepositoryInterface $settings
|
||||
) {
|
||||
}
|
||||
|
||||
public function handle(Saving $event)
|
||||
public function handle(Saving $event): void
|
||||
{
|
||||
$user = $event->user;
|
||||
$data = $event->data;
|
||||
|
|
|
@ -19,19 +19,11 @@ use Psr\Http\Server\RequestHandlerInterface;
|
|||
|
||||
class CheckForUpdatesController implements RequestHandlerInterface
|
||||
{
|
||||
/**
|
||||
* @var Dispatcher
|
||||
*/
|
||||
protected $bus;
|
||||
|
||||
public function __construct(Dispatcher $bus)
|
||||
{
|
||||
$this->bus = $bus;
|
||||
public function __construct(
|
||||
protected Dispatcher $bus
|
||||
) {
|
||||
}
|
||||
|
||||
/**
|
||||
* @throws \Flarum\User\Exception\PermissionDeniedException
|
||||
*/
|
||||
public function handle(ServerRequestInterface $request): ResponseInterface
|
||||
{
|
||||
$actor = RequestUtil::getActor($request);
|
||||
|
|
|
@ -20,19 +20,11 @@ use Psr\Http\Server\RequestHandlerInterface;
|
|||
|
||||
class GlobalUpdateController implements RequestHandlerInterface
|
||||
{
|
||||
/**
|
||||
* @var Dispatcher
|
||||
*/
|
||||
protected $bus;
|
||||
|
||||
public function __construct(Dispatcher $bus)
|
||||
{
|
||||
$this->bus = $bus;
|
||||
public function __construct(
|
||||
protected Dispatcher $bus
|
||||
) {
|
||||
}
|
||||
|
||||
/**
|
||||
* @throws \Flarum\User\Exception\PermissionDeniedException
|
||||
*/
|
||||
public function handle(ServerRequestInterface $request): ResponseInterface
|
||||
{
|
||||
$actor = RequestUtil::getActor($request);
|
||||
|
|
|
@ -19,28 +19,15 @@ use Tobscure\JsonApi\Document;
|
|||
|
||||
class ListTasksController extends AbstractListController
|
||||
{
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public $serializer = TaskSerializer::class;
|
||||
public ?string $serializer = TaskSerializer::class;
|
||||
|
||||
/**
|
||||
* @var UrlGenerator
|
||||
*/
|
||||
protected $url;
|
||||
|
||||
/**
|
||||
* @var TaskRepository
|
||||
*/
|
||||
protected $repository;
|
||||
|
||||
public function __construct(UrlGenerator $url, TaskRepository $repository)
|
||||
{
|
||||
$this->url = $url;
|
||||
$this->repository = $repository;
|
||||
public function __construct(
|
||||
protected UrlGenerator $url,
|
||||
protected TaskRepository $repository
|
||||
) {
|
||||
}
|
||||
|
||||
protected function data(ServerRequestInterface $request, Document $document)
|
||||
protected function data(ServerRequestInterface $request, Document $document): iterable
|
||||
{
|
||||
$actor = RequestUtil::getActor($request);
|
||||
|
||||
|
|
|
@ -21,14 +21,9 @@ use Psr\Http\Server\RequestHandlerInterface;
|
|||
|
||||
class MajorUpdateController implements RequestHandlerInterface
|
||||
{
|
||||
/**
|
||||
* @var Dispatcher
|
||||
*/
|
||||
protected $bus;
|
||||
|
||||
public function __construct(Dispatcher $bus)
|
||||
{
|
||||
$this->bus = $bus;
|
||||
public function __construct(
|
||||
protected Dispatcher $bus
|
||||
) {
|
||||
}
|
||||
|
||||
public function handle(ServerRequestInterface $request): ResponseInterface
|
||||
|
|
|
@ -20,19 +20,11 @@ use Psr\Http\Server\RequestHandlerInterface;
|
|||
|
||||
class MinorUpdateController implements RequestHandlerInterface
|
||||
{
|
||||
/**
|
||||
* @var Dispatcher
|
||||
*/
|
||||
protected $bus;
|
||||
|
||||
public function __construct(Dispatcher $bus)
|
||||
{
|
||||
$this->bus = $bus;
|
||||
public function __construct(
|
||||
protected Dispatcher $bus
|
||||
) {
|
||||
}
|
||||
|
||||
/**
|
||||
* @throws \Flarum\User\Exception\PermissionDeniedException
|
||||
*/
|
||||
public function handle(ServerRequestInterface $request): ResponseInterface
|
||||
{
|
||||
$actor = RequestUtil::getActor($request);
|
||||
|
|
|
@ -21,14 +21,9 @@ use Psr\Http\Server\RequestHandlerInterface;
|
|||
|
||||
class RemoveExtensionController implements RequestHandlerInterface
|
||||
{
|
||||
/**
|
||||
* @var Dispatcher
|
||||
*/
|
||||
protected $bus;
|
||||
|
||||
public function __construct(Dispatcher $bus)
|
||||
{
|
||||
$this->bus = $bus;
|
||||
public function __construct(
|
||||
protected Dispatcher $bus
|
||||
) {
|
||||
}
|
||||
|
||||
public function handle(ServerRequestInterface $request): ResponseInterface
|
||||
|
|
|
@ -20,14 +20,9 @@ use Psr\Http\Server\RequestHandlerInterface;
|
|||
|
||||
class RequireExtensionController implements RequestHandlerInterface
|
||||
{
|
||||
/**
|
||||
* @var Dispatcher
|
||||
*/
|
||||
protected $bus;
|
||||
|
||||
public function __construct(Dispatcher $bus)
|
||||
{
|
||||
$this->bus = $bus;
|
||||
public function __construct(
|
||||
protected Dispatcher $bus
|
||||
) {
|
||||
}
|
||||
|
||||
public function handle(ServerRequestInterface $request): ResponseInterface
|
||||
|
|
|
@ -21,14 +21,9 @@ use Psr\Http\Server\RequestHandlerInterface;
|
|||
|
||||
class UpdateExtensionController implements RequestHandlerInterface
|
||||
{
|
||||
/**
|
||||
* @var Dispatcher
|
||||
*/
|
||||
protected $bus;
|
||||
|
||||
public function __construct(Dispatcher $bus)
|
||||
{
|
||||
$this->bus = $bus;
|
||||
public function __construct(
|
||||
protected Dispatcher $bus
|
||||
) {
|
||||
}
|
||||
|
||||
public function handle(ServerRequestInterface $request): ResponseInterface
|
||||
|
|
|
@ -20,14 +20,9 @@ use Psr\Http\Server\RequestHandlerInterface;
|
|||
|
||||
class WhyNotController implements RequestHandlerInterface
|
||||
{
|
||||
/**
|
||||
* @var Dispatcher
|
||||
*/
|
||||
protected $bus;
|
||||
|
||||
public function __construct(Dispatcher $bus)
|
||||
{
|
||||
$this->bus = $bus;
|
||||
public function __construct(
|
||||
protected Dispatcher $bus
|
||||
) {
|
||||
}
|
||||
|
||||
public function handle(ServerRequestInterface $request): ResponseInterface
|
||||
|
|
|
@ -15,18 +15,12 @@ use InvalidArgumentException;
|
|||
|
||||
class TaskSerializer extends AbstractSerializer
|
||||
{
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected $type = 'package-manager-tasks';
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*
|
||||
* @param Task $model
|
||||
* @throws InvalidArgumentException
|
||||
*/
|
||||
protected function getDefaultAttributes($model)
|
||||
protected function getDefaultAttributes(object|array $model): array
|
||||
{
|
||||
if (! ($model instanceof Task)) {
|
||||
throw new InvalidArgumentException(
|
||||
|
|
|
@ -13,15 +13,8 @@ use Flarum\PackageManager\Task\Task;
|
|||
|
||||
abstract class AbstractActionCommand
|
||||
{
|
||||
/**
|
||||
* @var Task|null
|
||||
*/
|
||||
public $task = null;
|
||||
|
||||
/**
|
||||
* @var string|null
|
||||
*/
|
||||
public $package = null;
|
||||
public ?Task $task = null;
|
||||
public ?string $package = null;
|
||||
|
||||
abstract public function getOperationName(): string;
|
||||
}
|
||||
|
|
|
@ -14,14 +14,9 @@ use Flarum\User\User;
|
|||
|
||||
class CheckForUpdates extends AbstractActionCommand
|
||||
{
|
||||
/**
|
||||
* @var \Flarum\User\User
|
||||
*/
|
||||
public $actor;
|
||||
|
||||
public function __construct(User $actor)
|
||||
{
|
||||
$this->actor = $actor;
|
||||
public function __construct(
|
||||
public User $actor
|
||||
) {
|
||||
}
|
||||
|
||||
public function getOperationName(): string
|
||||
|
|
|
@ -16,20 +16,10 @@ use Symfony\Component\Console\Input\ArrayInput;
|
|||
|
||||
class CheckForUpdatesHandler
|
||||
{
|
||||
/**
|
||||
* @var ComposerAdapter
|
||||
*/
|
||||
protected $composer;
|
||||
|
||||
/**
|
||||
* @var \Flarum\PackageManager\Settings\LastUpdateCheck
|
||||
*/
|
||||
protected $lastUpdateCheck;
|
||||
|
||||
public function __construct(ComposerAdapter $composer, LastUpdateCheck $lastUpdateCheck)
|
||||
{
|
||||
$this->composer = $composer;
|
||||
$this->lastUpdateCheck = $lastUpdateCheck;
|
||||
public function __construct(
|
||||
private ComposerAdapter $composer,
|
||||
private LastUpdateCheck $lastUpdateCheck
|
||||
) {
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -50,7 +40,7 @@ class CheckForUpdatesHandler
|
|||
*
|
||||
* @throws ComposerCommandFailedException
|
||||
*/
|
||||
public function handle(CheckForUpdates $command)
|
||||
public function handle(CheckForUpdates $command): array
|
||||
{
|
||||
$firstOutput = $this->runComposerCommand(false, $command);
|
||||
$firstOutput = json_decode($this->cleanJson($firstOutput), true);
|
||||
|
|
|
@ -14,14 +14,9 @@ use Flarum\User\User;
|
|||
|
||||
class GlobalUpdate extends AbstractActionCommand
|
||||
{
|
||||
/**
|
||||
* @var \Flarum\User\User
|
||||
*/
|
||||
public $actor;
|
||||
|
||||
public function __construct(User $actor)
|
||||
{
|
||||
$this->actor = $actor;
|
||||
public function __construct(
|
||||
public User $actor
|
||||
) {
|
||||
}
|
||||
|
||||
public function getOperationName(): string
|
||||
|
|
|
@ -18,32 +18,14 @@ use Symfony\Component\Console\Input\StringInput;
|
|||
|
||||
class GlobalUpdateHandler
|
||||
{
|
||||
/**
|
||||
* @var ComposerAdapter
|
||||
*/
|
||||
protected $composer;
|
||||
|
||||
/**
|
||||
* @var Dispatcher
|
||||
*/
|
||||
protected $events;
|
||||
|
||||
/**
|
||||
* @var FlarumDispatcher
|
||||
*/
|
||||
protected $commandDispatcher;
|
||||
|
||||
public function __construct(ComposerAdapter $composer, Dispatcher $events, FlarumDispatcher $commandDispatcher)
|
||||
{
|
||||
$this->composer = $composer;
|
||||
$this->events = $events;
|
||||
$this->commandDispatcher = $commandDispatcher;
|
||||
public function __construct(
|
||||
protected ComposerAdapter $composer,
|
||||
protected Dispatcher $events,
|
||||
protected FlarumDispatcher $commandDispatcher
|
||||
) {
|
||||
}
|
||||
|
||||
/**
|
||||
* @throws \Flarum\User\Exception\PermissionDeniedException|ComposerUpdateFailedException
|
||||
*/
|
||||
public function handle(GlobalUpdate $command)
|
||||
public function handle(GlobalUpdate $command): void
|
||||
{
|
||||
$command->actor->assertAdmin();
|
||||
|
||||
|
|
|
@ -14,20 +14,10 @@ use Flarum\User\User;
|
|||
|
||||
class MajorUpdate extends AbstractActionCommand
|
||||
{
|
||||
/**
|
||||
* @var \Flarum\User\User
|
||||
*/
|
||||
public $actor;
|
||||
|
||||
/**
|
||||
* @var bool
|
||||
*/
|
||||
public $dryRun;
|
||||
|
||||
public function __construct(User $actor, bool $dryRun)
|
||||
{
|
||||
$this->actor = $actor;
|
||||
$this->dryRun = $dryRun;
|
||||
public function __construct(
|
||||
public User $actor,
|
||||
public bool $dryRun
|
||||
) {
|
||||
}
|
||||
|
||||
public function getOperationName(): string
|
||||
|
|
|
@ -20,38 +20,12 @@ use Symfony\Component\Console\Input\ArrayInput;
|
|||
|
||||
class MajorUpdateHandler
|
||||
{
|
||||
/**
|
||||
* @var ComposerAdapter
|
||||
*/
|
||||
protected $composer;
|
||||
|
||||
/**
|
||||
* @var LastUpdateCheck
|
||||
*/
|
||||
protected $lastUpdateCheck;
|
||||
|
||||
/**
|
||||
* @var Dispatcher
|
||||
*/
|
||||
protected $events;
|
||||
|
||||
/**
|
||||
* @var ComposerJson
|
||||
*/
|
||||
protected $composerJson;
|
||||
|
||||
/**
|
||||
* @param ComposerAdapter $composer
|
||||
* @param LastUpdateCheck $lastUpdateCheck
|
||||
* @param Dispatcher $events
|
||||
* @param ComposerJson $composerJson
|
||||
*/
|
||||
public function __construct(ComposerAdapter $composer, LastUpdateCheck $lastUpdateCheck, Dispatcher $events, ComposerJson $composerJson)
|
||||
{
|
||||
$this->composer = $composer;
|
||||
$this->lastUpdateCheck = $lastUpdateCheck;
|
||||
$this->events = $events;
|
||||
$this->composerJson = $composerJson;
|
||||
public function __construct(
|
||||
protected ComposerAdapter $composer,
|
||||
protected LastUpdateCheck $lastUpdateCheck,
|
||||
protected Dispatcher $events,
|
||||
protected ComposerJson $composerJson
|
||||
) {
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -64,7 +38,7 @@ class MajorUpdateHandler
|
|||
* @throws \Flarum\User\Exception\PermissionDeniedException
|
||||
* @throws NoNewMajorVersionException|MajorUpdateFailedException
|
||||
*/
|
||||
public function handle(MajorUpdate $command)
|
||||
public function handle(MajorUpdate $command): void
|
||||
{
|
||||
$command->actor->assertAdmin();
|
||||
|
||||
|
|
|
@ -14,14 +14,9 @@ use Flarum\User\User;
|
|||
|
||||
class MinorUpdate extends AbstractActionCommand
|
||||
{
|
||||
/**
|
||||
* @var \Flarum\User\User
|
||||
*/
|
||||
public $actor;
|
||||
|
||||
public function __construct(User $actor)
|
||||
{
|
||||
$this->actor = $actor;
|
||||
public function __construct(
|
||||
public User $actor
|
||||
) {
|
||||
}
|
||||
|
||||
public function getOperationName(): string
|
||||
|
|
|
@ -19,39 +19,15 @@ use Symfony\Component\Console\Input\StringInput;
|
|||
|
||||
class MinorUpdateHandler
|
||||
{
|
||||
/**
|
||||
* @var ComposerAdapter
|
||||
*/
|
||||
protected $composer;
|
||||
|
||||
/**
|
||||
* @var \Flarum\PackageManager\Settings\LastUpdateCheck
|
||||
*/
|
||||
protected $lastUpdateCheck;
|
||||
|
||||
/**
|
||||
* @var Dispatcher
|
||||
*/
|
||||
protected $events;
|
||||
|
||||
/**
|
||||
* @var ComposerJson
|
||||
*/
|
||||
protected $composerJson;
|
||||
|
||||
public function __construct(ComposerAdapter $composer, LastUpdateCheck $lastUpdateCheck, Dispatcher $events, ComposerJson $composerJson)
|
||||
{
|
||||
$this->composer = $composer;
|
||||
$this->lastUpdateCheck = $lastUpdateCheck;
|
||||
$this->events = $events;
|
||||
$this->composerJson = $composerJson;
|
||||
public function __construct(
|
||||
protected ComposerAdapter $composer,
|
||||
protected LastUpdateCheck $lastUpdateCheck,
|
||||
protected Dispatcher $events,
|
||||
protected ComposerJson $composerJson
|
||||
) {
|
||||
}
|
||||
|
||||
/**
|
||||
* @throws \Flarum\User\Exception\PermissionDeniedException
|
||||
* @throws ComposerUpdateFailedException
|
||||
*/
|
||||
public function handle(MinorUpdate $command)
|
||||
public function handle(MinorUpdate $command): void
|
||||
{
|
||||
$command->actor->assertAdmin();
|
||||
|
||||
|
|
|
@ -14,20 +14,10 @@ use Flarum\User\User;
|
|||
|
||||
class RemoveExtension extends AbstractActionCommand
|
||||
{
|
||||
/**
|
||||
* @var User
|
||||
*/
|
||||
public $actor;
|
||||
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
public $extensionId;
|
||||
|
||||
public function __construct(User $actor, string $extensionId)
|
||||
{
|
||||
$this->actor = $actor;
|
||||
$this->extensionId = $extensionId;
|
||||
public function __construct(
|
||||
public User $actor,
|
||||
public string $extensionId
|
||||
) {
|
||||
}
|
||||
|
||||
public function getOperationName(): string
|
||||
|
|
|
@ -19,33 +19,14 @@ use Symfony\Component\Console\Input\StringInput;
|
|||
|
||||
class RemoveExtensionHandler
|
||||
{
|
||||
/**
|
||||
* @var ComposerAdapter
|
||||
*/
|
||||
protected $composer;
|
||||
|
||||
/**
|
||||
* @var ExtensionManager
|
||||
*/
|
||||
protected $extensions;
|
||||
|
||||
/**
|
||||
* @var Dispatcher
|
||||
*/
|
||||
protected $events;
|
||||
|
||||
public function __construct(ComposerAdapter $composer, ExtensionManager $extensions, Dispatcher $events)
|
||||
{
|
||||
$this->composer = $composer;
|
||||
$this->extensions = $extensions;
|
||||
$this->events = $events;
|
||||
public function __construct(
|
||||
private ComposerAdapter $composer,
|
||||
private ExtensionManager $extensions,
|
||||
private Dispatcher $events
|
||||
) {
|
||||
}
|
||||
|
||||
/**
|
||||
* @throws \Flarum\User\Exception\PermissionDeniedException
|
||||
* @throws \Exception
|
||||
*/
|
||||
public function handle(RemoveExtension $command)
|
||||
public function handle(RemoveExtension $command): void
|
||||
{
|
||||
$command->actor->assertAdmin();
|
||||
|
||||
|
|
|
@ -14,20 +14,10 @@ use Flarum\User\User;
|
|||
|
||||
class RequireExtension extends AbstractActionCommand
|
||||
{
|
||||
/**
|
||||
* @var User
|
||||
*/
|
||||
public $actor;
|
||||
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
public $package;
|
||||
|
||||
public function __construct(User $actor, string $package)
|
||||
{
|
||||
$this->actor = $actor;
|
||||
$this->package = $package;
|
||||
public function __construct(
|
||||
public User $actor,
|
||||
public ?string $package
|
||||
) {
|
||||
}
|
||||
|
||||
public function getOperationName(): string
|
||||
|
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue
Block a user