mirror of
https://github.com/flarum/core.git
synced 2025-07-17 14:51:19 +02:00
Replace depreciated helpers with class variant
This commit is contained in:
@@ -13,6 +13,7 @@ use Flarum\Api\Controller\AbstractCreateController;
|
|||||||
use Flarum\Flags\Api\Serializer\FlagSerializer;
|
use Flarum\Flags\Api\Serializer\FlagSerializer;
|
||||||
use Flarum\Flags\Command\CreateFlag;
|
use Flarum\Flags\Command\CreateFlag;
|
||||||
use Illuminate\Contracts\Bus\Dispatcher;
|
use Illuminate\Contracts\Bus\Dispatcher;
|
||||||
|
use Illuminate\Support\Arr;
|
||||||
use Psr\Http\Message\ServerRequestInterface;
|
use Psr\Http\Message\ServerRequestInterface;
|
||||||
use Tobscure\JsonApi\Document;
|
use Tobscure\JsonApi\Document;
|
||||||
|
|
||||||
@@ -50,7 +51,7 @@ class CreateFlagController extends AbstractCreateController
|
|||||||
protected function data(ServerRequestInterface $request, Document $document)
|
protected function data(ServerRequestInterface $request, Document $document)
|
||||||
{
|
{
|
||||||
return $this->bus->dispatch(
|
return $this->bus->dispatch(
|
||||||
new CreateFlag($request->getAttribute('actor'), array_get($request->getParsedBody(), 'data', []))
|
new CreateFlag($request->getAttribute('actor'), Arr::get($request->getParsedBody(), 'data', []))
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -12,6 +12,7 @@ namespace Flarum\Flags\Api\Controller;
|
|||||||
use Flarum\Api\Controller\AbstractDeleteController;
|
use Flarum\Api\Controller\AbstractDeleteController;
|
||||||
use Flarum\Flags\Command\DeleteFlags;
|
use Flarum\Flags\Command\DeleteFlags;
|
||||||
use Illuminate\Contracts\Bus\Dispatcher;
|
use Illuminate\Contracts\Bus\Dispatcher;
|
||||||
|
use Illuminate\Support\Arr;
|
||||||
use Psr\Http\Message\ServerRequestInterface;
|
use Psr\Http\Message\ServerRequestInterface;
|
||||||
|
|
||||||
class DeleteFlagsController extends AbstractDeleteController
|
class DeleteFlagsController extends AbstractDeleteController
|
||||||
@@ -35,7 +36,7 @@ class DeleteFlagsController extends AbstractDeleteController
|
|||||||
protected function delete(ServerRequestInterface $request)
|
protected function delete(ServerRequestInterface $request)
|
||||||
{
|
{
|
||||||
$this->bus->dispatch(
|
$this->bus->dispatch(
|
||||||
new DeleteFlags(array_get($request->getQueryParams(), 'id'), $request->getAttribute('actor'), $request->getParsedBody())
|
new DeleteFlags(Arr::get($request->getQueryParams(), 'id'), $request->getAttribute('actor'), $request->getParsedBody())
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -15,6 +15,7 @@ use Flarum\Post\CommentPost;
|
|||||||
use Flarum\Post\PostRepository;
|
use Flarum\Post\PostRepository;
|
||||||
use Flarum\Settings\SettingsRepositoryInterface;
|
use Flarum\Settings\SettingsRepositoryInterface;
|
||||||
use Flarum\User\Exception\PermissionDeniedException;
|
use Flarum\User\Exception\PermissionDeniedException;
|
||||||
|
use Illuminate\Support\Arr;
|
||||||
use Symfony\Component\Translation\TranslatorInterface;
|
use Symfony\Component\Translation\TranslatorInterface;
|
||||||
use Tobscure\JsonApi\Exception\InvalidParameterException;
|
use Tobscure\JsonApi\Exception\InvalidParameterException;
|
||||||
|
|
||||||
@@ -57,7 +58,7 @@ class CreateFlagHandler
|
|||||||
$actor = $command->actor;
|
$actor = $command->actor;
|
||||||
$data = $command->data;
|
$data = $command->data;
|
||||||
|
|
||||||
$postId = array_get($data, 'relationships.post.data.id');
|
$postId = Arr::get($data, 'relationships.post.data.id');
|
||||||
$post = $this->posts->findOrFail($postId, $actor);
|
$post = $this->posts->findOrFail($postId, $actor);
|
||||||
|
|
||||||
if (! ($post instanceof CommentPost)) {
|
if (! ($post instanceof CommentPost)) {
|
||||||
@@ -70,7 +71,7 @@ class CreateFlagHandler
|
|||||||
throw new PermissionDeniedException();
|
throw new PermissionDeniedException();
|
||||||
}
|
}
|
||||||
|
|
||||||
if (array_get($data, 'attributes.reason') === null && array_get($data, 'attributes.reasonDetail') === '') {
|
if (Arr::get($data, 'attributes.reason') === null && Arr::get($data, 'attributes.reasonDetail') === '') {
|
||||||
throw new ValidationException([
|
throw new ValidationException([
|
||||||
'message' => $this->translator->trans('flarum-flags.forum.flag_post.reason_missing_message')
|
'message' => $this->translator->trans('flarum-flags.forum.flag_post.reason_missing_message')
|
||||||
]);
|
]);
|
||||||
@@ -86,8 +87,8 @@ class CreateFlagHandler
|
|||||||
$flag->post_id = $post->id;
|
$flag->post_id = $post->id;
|
||||||
$flag->user_id = $actor->id;
|
$flag->user_id = $actor->id;
|
||||||
$flag->type = 'user';
|
$flag->type = 'user';
|
||||||
$flag->reason = array_get($data, 'attributes.reason');
|
$flag->reason = Arr::get($data, 'attributes.reason');
|
||||||
$flag->reason_detail = array_get($data, 'attributes.reasonDetail');
|
$flag->reason_detail = Arr::get($data, 'attributes.reasonDetail');
|
||||||
$flag->created_at = time();
|
$flag->created_at = time();
|
||||||
|
|
||||||
$flag->save();
|
$flag->save();
|
||||||
|
Reference in New Issue
Block a user