1
0
mirror of https://github.com/flarum/core.git synced 2025-07-16 14:26:25 +02:00

Replace depreciated helpers with class variant

This commit is contained in:
Matthew Kilgore
2020-07-25 18:41:01 -04:00
parent e85063fbf7
commit e9022d5710
3 changed files with 9 additions and 6 deletions

View File

@ -13,6 +13,7 @@ use Flarum\Api\Controller\AbstractCreateController;
use Flarum\Flags\Api\Serializer\FlagSerializer;
use Flarum\Flags\Command\CreateFlag;
use Illuminate\Contracts\Bus\Dispatcher;
use Illuminate\Support\Arr;
use Psr\Http\Message\ServerRequestInterface;
use Tobscure\JsonApi\Document;
@ -50,7 +51,7 @@ class CreateFlagController extends AbstractCreateController
protected function data(ServerRequestInterface $request, Document $document)
{
return $this->bus->dispatch(
new CreateFlag($request->getAttribute('actor'), array_get($request->getParsedBody(), 'data', []))
new CreateFlag($request->getAttribute('actor'), Arr::get($request->getParsedBody(), 'data', []))
);
}
}

View File

@ -12,6 +12,7 @@ namespace Flarum\Flags\Api\Controller;
use Flarum\Api\Controller\AbstractDeleteController;
use Flarum\Flags\Command\DeleteFlags;
use Illuminate\Contracts\Bus\Dispatcher;
use Illuminate\Support\Arr;
use Psr\Http\Message\ServerRequestInterface;
class DeleteFlagsController extends AbstractDeleteController
@ -35,7 +36,7 @@ class DeleteFlagsController extends AbstractDeleteController
protected function delete(ServerRequestInterface $request)
{
$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())
);
}
}

View File

@ -15,6 +15,7 @@ use Flarum\Post\CommentPost;
use Flarum\Post\PostRepository;
use Flarum\Settings\SettingsRepositoryInterface;
use Flarum\User\Exception\PermissionDeniedException;
use Illuminate\Support\Arr;
use Symfony\Component\Translation\TranslatorInterface;
use Tobscure\JsonApi\Exception\InvalidParameterException;
@ -57,7 +58,7 @@ class CreateFlagHandler
$actor = $command->actor;
$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);
if (! ($post instanceof CommentPost)) {
@ -70,7 +71,7 @@ class CreateFlagHandler
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([
'message' => $this->translator->trans('flarum-flags.forum.flag_post.reason_missing_message')
]);
@ -86,8 +87,8 @@ class CreateFlagHandler
$flag->post_id = $post->id;
$flag->user_id = $actor->id;
$flag->type = 'user';
$flag->reason = array_get($data, 'attributes.reason');
$flag->reason_detail = array_get($data, 'attributes.reasonDetail');
$flag->reason = Arr::get($data, 'attributes.reason');
$flag->reason_detail = Arr::get($data, 'attributes.reasonDetail');
$flag->created_at = time();
$flag->save();