1
0
mirror of https://github.com/flarum/core.git synced 2025-08-29 11:00:12 +02:00

chore: replace SeverRequestInterface with laravel Request in controllers

This commit is contained in:
Sami Mazouz
2023-08-11 14:17:54 +01:00
parent 0a89c3bd53
commit a60e3d174f
123 changed files with 497 additions and 528 deletions

View File

@@ -109,7 +109,6 @@
"ext-json": "*",
"components/font-awesome": "^5.15.0",
"composer/composer": "^2.0",
"dflydev/fig-cookies": "^3.0",
"doctrine/dbal": "^3.6.2",
"dragonmantank/cron-expression": "^3.3",
"franzl/whoops-middleware": "2.0",
@@ -124,8 +123,10 @@
"illuminate/events": "^10.0",
"illuminate/filesystem": "^10.0",
"illuminate/hashing": "^10.0",
"illuminate/http": "^10.0",
"illuminate/mail": "^10.0",
"illuminate/queue": "^10.0",
"illuminate/routing": "^10.0",
"illuminate/session": "^10.0",
"illuminate/support": "^10.0",
"illuminate/validation": "^10.0",
@@ -143,7 +144,6 @@
"middlewares/request-handler": "^2.0.2",
"monolog/monolog": "^3.3",
"nesbot/carbon": "^2.66",
"nikic/fast-route": "^1.3",
"psr/http-message": "^1.1",
"psr/http-server-handler": "^1.0.2",
"psr/http-server-middleware": "^1.0.2",
@@ -160,6 +160,7 @@
"symfony/mime": "^6.3",
"symfony/polyfill-intl-messageformatter": "^1.27",
"symfony/postmark-mailer": "^6.3",
"symfony/psr-http-message-bridge": "^2.3",
"symfony/translation": "^6.3",
"symfony/yaml": "^6.3",
"wikimedia/less.php": "^4.1"

View File

@@ -9,7 +9,7 @@
use Flarum\Extend;
use Flarum\Frontend\Document;
use Psr\Http\Message\ServerRequestInterface as Request;
use Illuminate\Http\Request;
return [
(new Extend\Frontend('forum'))

View File

@@ -15,8 +15,8 @@ use Flarum\Flags\Command\CreateFlag;
use Flarum\Flags\Flag;
use Flarum\Http\RequestUtil;
use Illuminate\Contracts\Bus\Dispatcher;
use Illuminate\Http\Request;
use Illuminate\Support\Arr;
use Psr\Http\Message\ServerRequestInterface;
use Tobscure\JsonApi\Document;
class CreateFlagController extends AbstractCreateController
@@ -34,7 +34,7 @@ class CreateFlagController extends AbstractCreateController
) {
}
protected function data(ServerRequestInterface $request, Document $document): Flag
protected function data(Request $request, Document $document): Flag
{
return $this->bus->dispatch(
new CreateFlag(RequestUtil::getActor($request), Arr::get($request->getParsedBody(), 'data', []))

View File

@@ -13,8 +13,8 @@ use Flarum\Api\Controller\AbstractDeleteController;
use Flarum\Flags\Command\DeleteFlags;
use Flarum\Http\RequestUtil;
use Illuminate\Contracts\Bus\Dispatcher;
use Illuminate\Http\Request;
use Illuminate\Support\Arr;
use Psr\Http\Message\ServerRequestInterface;
class DeleteFlagsController extends AbstractDeleteController
{
@@ -23,10 +23,10 @@ class DeleteFlagsController extends AbstractDeleteController
) {
}
protected function delete(ServerRequestInterface $request): void
protected function delete(Request $request): void
{
$this->bus->dispatch(
new DeleteFlags(Arr::get($request->getQueryParams(), 'id'), RequestUtil::getActor($request), $request->getParsedBody())
new DeleteFlags($request->query('id'), RequestUtil::getActor($request), $request->json()->all())
);
}
}

View File

@@ -14,7 +14,7 @@ use Flarum\Api\Controller\AbstractListController;
use Flarum\Flags\Api\Serializer\FlagSerializer;
use Flarum\Flags\Flag;
use Flarum\Http\RequestUtil;
use Psr\Http\Message\ServerRequestInterface;
use Illuminate\Http\Request;
use Tobscure\JsonApi\Document;
class ListFlagsController extends AbstractListController
@@ -28,7 +28,7 @@ class ListFlagsController extends AbstractListController
'post.discussion'
];
protected function data(ServerRequestInterface $request, Document $document): iterable
protected function data(Request $request, Document $document): iterable
{
$actor = RequestUtil::getActor($request);
$include = $this->extractInclude($request);

View File

@@ -13,11 +13,11 @@ use Flarum\Api\Controller;
use Flarum\Flags\Api\Controller\CreateFlagController;
use Flarum\Http\RequestUtil;
use Illuminate\Database\Eloquent\Collection;
use Psr\Http\Message\ServerRequestInterface;
use Illuminate\Http\Request;
class PrepareFlagsApiData
{
public function __invoke(Controller\AbstractSerializeController $controller, mixed $data, ServerRequestInterface $request): void
public function __invoke(Controller\AbstractSerializeController $controller, mixed $data, Request $request): void
{
// For any API action that allows the 'flags' relationship to be
// included, we need to preload this relationship onto the data (Post

View File

@@ -16,13 +16,13 @@ use Flarum\Post\Post;
use Illuminate\Database\Eloquent\Collection;
use Illuminate\Database\Eloquent\Relations\BelongsToMany;
use Illuminate\Database\Query\Expression;
use Psr\Http\Message\ServerRequestInterface;
use Illuminate\Http\Request;
class LoadLikesRelationship
{
public static int $maxLikes = 4;
public static function mutateRelation(BelongsToMany $query, ServerRequestInterface $request): void
public static function mutateRelation(BelongsToMany $query, Request $request): void
{
$actor = RequestUtil::getActor($request);

View File

@@ -15,7 +15,7 @@ use Flarum\Http\RequestUtil;
use Flarum\Post\Post;
use Illuminate\Database\Eloquent\Collection;
use Illuminate\Database\Eloquent\Relations\BelongsToMany;
use Psr\Http\Message\ServerRequestInterface;
use Illuminate\Http\Request;
/**
* Apply visibility permissions to API data's mentionedBy relationship.
@@ -25,7 +25,7 @@ class LoadMentionedByRelationship
{
public static int $maxMentionedBy = 4;
public static function mutateRelation(BelongsToMany $query, ServerRequestInterface $request): void
public static function mutateRelation(BelongsToMany $query, Request $request): void
{
$actor = RequestUtil::getActor($request);
@@ -42,7 +42,7 @@ class LoadMentionedByRelationship
/**
* Called using the @see ApiController::prepareDataForSerialization extender.
*/
public static function countRelation(AbstractSerializeController $controller, mixed $data, ServerRequestInterface $request): array
public static function countRelation(AbstractSerializeController $controller, mixed $data, Request $request): array
{
$actor = RequestUtil::getActor($request);
$loadable = null;

View File

@@ -12,7 +12,7 @@ namespace Flarum\Mentions\Formatter;
use Flarum\Discussion\Discussion;
use Flarum\Http\SlugManager;
use Flarum\Locale\TranslatorInterface;
use Psr\Http\Message\ServerRequestInterface as Request;
use Illuminate\Http\Request;
use s9e\TextFormatter\Renderer;
use s9e\TextFormatter\Utils;

View File

@@ -11,7 +11,7 @@ namespace Flarum\Mentions\Formatter;
use Flarum\Post\Post;
use Flarum\Tags\Tag;
use Psr\Http\Message\ServerRequestInterface as Request;
use Illuminate\Http\Request;
use s9e\TextFormatter\Renderer;
use s9e\TextFormatter\Utils;

View File

@@ -9,22 +9,22 @@
namespace Flarum\PackageManager\Api\Controller;
use Flarum\Http\Controller\AbstractController;
use Flarum\Http\RequestUtil;
use Flarum\PackageManager\Command\CheckForUpdates;
use Flarum\PackageManager\Job\Dispatcher;
use Illuminate\Http\Request;
use Laminas\Diactoros\Response\JsonResponse;
use Psr\Http\Message\ResponseInterface;
use Psr\Http\Message\ServerRequestInterface;
use Psr\Http\Server\RequestHandlerInterface;
class CheckForUpdatesController implements RequestHandlerInterface
class CheckForUpdatesController extends AbstractController
{
public function __construct(
protected Dispatcher $bus
) {
}
public function handle(ServerRequestInterface $request): ResponseInterface
public function __invoke(Request $request): ResponseInterface
{
$actor = RequestUtil::getActor($request);

View File

@@ -9,23 +9,23 @@
namespace Flarum\PackageManager\Api\Controller;
use Flarum\Http\Controller\AbstractController;
use Flarum\Http\RequestUtil;
use Flarum\PackageManager\Command\GlobalUpdate;
use Flarum\PackageManager\Job\Dispatcher;
use Illuminate\Http\Request;
use Laminas\Diactoros\Response\EmptyResponse;
use Laminas\Diactoros\Response\JsonResponse;
use Psr\Http\Message\ResponseInterface;
use Psr\Http\Message\ServerRequestInterface;
use Psr\Http\Server\RequestHandlerInterface;
class GlobalUpdateController implements RequestHandlerInterface
class GlobalUpdateController extends AbstractController
{
public function __construct(
protected Dispatcher $bus
) {
}
public function handle(ServerRequestInterface $request): ResponseInterface
public function __invoke(Request $request): ResponseInterface
{
$actor = RequestUtil::getActor($request);

View File

@@ -14,7 +14,7 @@ use Flarum\Http\RequestUtil;
use Flarum\Http\UrlGenerator;
use Flarum\PackageManager\Api\Serializer\TaskSerializer;
use Flarum\PackageManager\Task\TaskRepository;
use Psr\Http\Message\ServerRequestInterface;
use Illuminate\Http\Request;
use Tobscure\JsonApi\Document;
class ListTasksController extends AbstractListController
@@ -27,7 +27,7 @@ class ListTasksController extends AbstractListController
) {
}
protected function data(ServerRequestInterface $request, Document $document): iterable
protected function data(Request $request, Document $document): iterable
{
$actor = RequestUtil::getActor($request);
@@ -49,7 +49,7 @@ class ListTasksController extends AbstractListController
$document->addPaginationLinks(
$this->url->to('api')->route('package-manager.tasks.index'),
$request->getQueryParams(),
$request->query(),
$offset,
$limit,
$total

View File

@@ -9,27 +9,26 @@
namespace Flarum\PackageManager\Api\Controller;
use Flarum\Http\Controller\AbstractController;
use Flarum\Http\RequestUtil;
use Flarum\PackageManager\Command\MajorUpdate;
use Flarum\PackageManager\Job\Dispatcher;
use Illuminate\Support\Arr;
use Illuminate\Http\Request;
use Laminas\Diactoros\Response\EmptyResponse;
use Laminas\Diactoros\Response\JsonResponse;
use Psr\Http\Message\ResponseInterface;
use Psr\Http\Message\ServerRequestInterface;
use Psr\Http\Server\RequestHandlerInterface;
class MajorUpdateController implements RequestHandlerInterface
class MajorUpdateController extends AbstractController
{
public function __construct(
protected Dispatcher $bus
) {
}
public function handle(ServerRequestInterface $request): ResponseInterface
public function __invoke(Request $request): ResponseInterface
{
$actor = RequestUtil::getActor($request);
$dryRun = (bool) (int) Arr::get($request->getParsedBody(), 'data.dryRun', 0);
$dryRun = (bool) (int) $request->json('data.dryRun', 0);
$response = $this->bus->dispatch(
new MajorUpdate($actor, $dryRun)

View File

@@ -9,23 +9,23 @@
namespace Flarum\PackageManager\Api\Controller;
use Flarum\Http\Controller\AbstractController;
use Flarum\Http\RequestUtil;
use Flarum\PackageManager\Command\MinorUpdate;
use Flarum\PackageManager\Job\Dispatcher;
use Illuminate\Http\Request;
use Laminas\Diactoros\Response\EmptyResponse;
use Laminas\Diactoros\Response\JsonResponse;
use Psr\Http\Message\ResponseInterface;
use Psr\Http\Message\ServerRequestInterface;
use Psr\Http\Server\RequestHandlerInterface;
class MinorUpdateController implements RequestHandlerInterface
class MinorUpdateController extends AbstractController
{
public function __construct(
protected Dispatcher $bus
) {
}
public function handle(ServerRequestInterface $request): ResponseInterface
public function __invoke(Request $request): ResponseInterface
{
$actor = RequestUtil::getActor($request);

View File

@@ -9,30 +9,29 @@
namespace Flarum\PackageManager\Api\Controller;
use Flarum\Http\Controller\AbstractController;
use Flarum\Http\RequestUtil;
use Flarum\PackageManager\Command\RemoveExtension;
use Flarum\PackageManager\Job\Dispatcher;
use Illuminate\Http\Request;
use Illuminate\Support\Arr;
use Laminas\Diactoros\Response\EmptyResponse;
use Laminas\Diactoros\Response\JsonResponse;
use Psr\Http\Message\ResponseInterface;
use Psr\Http\Message\ServerRequestInterface;
use Psr\Http\Server\RequestHandlerInterface;
class RemoveExtensionController implements RequestHandlerInterface
class RemoveExtensionController extends AbstractController
{
public function __construct(
protected Dispatcher $bus
) {
}
public function handle(ServerRequestInterface $request): ResponseInterface
public function __invoke(Request $request, int $id): ResponseInterface
{
$actor = RequestUtil::getActor($request);
$extensionId = Arr::get($request->getQueryParams(), 'id');
$response = $this->bus->dispatch(
new RemoveExtension($actor, $extensionId)
new RemoveExtension($actor, $id)
);
return $response->queueJobs

View File

@@ -9,26 +9,25 @@
namespace Flarum\PackageManager\Api\Controller;
use Flarum\Http\Controller\AbstractController;
use Flarum\Http\RequestUtil;
use Flarum\PackageManager\Command\RequireExtension;
use Flarum\PackageManager\Job\Dispatcher;
use Illuminate\Support\Arr;
use Illuminate\Http\Request;
use Laminas\Diactoros\Response\JsonResponse;
use Psr\Http\Message\ResponseInterface;
use Psr\Http\Message\ServerRequestInterface;
use Psr\Http\Server\RequestHandlerInterface;
class RequireExtensionController implements RequestHandlerInterface
class RequireExtensionController extends AbstractController
{
public function __construct(
protected Dispatcher $bus
) {
}
public function handle(ServerRequestInterface $request): ResponseInterface
public function __invoke(Request $request): ResponseInterface
{
$actor = RequestUtil::getActor($request);
$package = Arr::get($request->getParsedBody(), 'data.package');
$package = $request->json('data.package');
$response = $this->bus->dispatch(
new RequireExtension($actor, $package)

View File

@@ -9,30 +9,28 @@
namespace Flarum\PackageManager\Api\Controller;
use Flarum\Http\Controller\AbstractController;
use Flarum\Http\RequestUtil;
use Flarum\PackageManager\Command\UpdateExtension;
use Flarum\PackageManager\Job\Dispatcher;
use Illuminate\Support\Arr;
use Illuminate\Http\Request;
use Laminas\Diactoros\Response\EmptyResponse;
use Laminas\Diactoros\Response\JsonResponse;
use Psr\Http\Message\ResponseInterface;
use Psr\Http\Message\ServerRequestInterface;
use Psr\Http\Server\RequestHandlerInterface;
class UpdateExtensionController implements RequestHandlerInterface
class UpdateExtensionController extends AbstractController
{
public function __construct(
protected Dispatcher $bus
) {
}
public function handle(ServerRequestInterface $request): ResponseInterface
public function __invoke(Request $request, int $id): ResponseInterface
{
$actor = RequestUtil::getActor($request);
$extensionId = Arr::get($request->getQueryParams(), 'id');
$response = $this->bus->dispatch(
new UpdateExtension($actor, $extensionId)
new UpdateExtension($actor, $id)
);
return $response->queueJobs

View File

@@ -9,27 +9,27 @@
namespace Flarum\PackageManager\Api\Controller;
use Flarum\Http\Controller\AbstractController;
use Flarum\Http\RequestUtil;
use Flarum\PackageManager\Command\WhyNot;
use Flarum\PackageManager\Job\Dispatcher;
use Illuminate\Http\Request;
use Illuminate\Support\Arr;
use Laminas\Diactoros\Response\JsonResponse;
use Psr\Http\Message\ResponseInterface;
use Psr\Http\Message\ServerRequestInterface;
use Psr\Http\Server\RequestHandlerInterface;
class WhyNotController implements RequestHandlerInterface
class WhyNotController extends AbstractController
{
public function __construct(
protected Dispatcher $bus
) {
}
public function handle(ServerRequestInterface $request): ResponseInterface
public function __invoke(Request $request): ResponseInterface
{
$actor = RequestUtil::getActor($request);
$package = Arr::get($request->getParsedBody(), 'data.package', '');
$version = Arr::get($request->getParsedBody(), 'data.version', '*');
$package = $request->json('data.package', '');
$version = $request->json('data.version', '*');
$whyNot = $this->bus->sync()->dispatch(
new WhyNot($actor, $package, $version)

View File

@@ -9,29 +9,27 @@
namespace Flarum\Pusher\Api\Controller;
use Flarum\Http\Controller\AbstractController;
use Flarum\Http\RequestUtil;
use Flarum\Settings\SettingsRepositoryInterface;
use Illuminate\Support\Arr;
use Illuminate\Http\Request;
use Laminas\Diactoros\Response\EmptyResponse;
use Laminas\Diactoros\Response\JsonResponse;
use Psr\Http\Message\ResponseInterface;
use Psr\Http\Message\ServerRequestInterface;
use Psr\Http\Server\RequestHandlerInterface;
use Pusher\Pusher;
class AuthController implements RequestHandlerInterface
class AuthController extends AbstractController
{
public function __construct(
protected SettingsRepositoryInterface $settings
) {
}
public function handle(ServerRequestInterface $request): ResponseInterface
public function __invoke(Request $request): ResponseInterface
{
$userChannel = 'private-user'.RequestUtil::getActor($request)->id;
$body = $request->getParsedBody();
if (Arr::get($body, 'channel_name') === $userChannel) {
if ($request->input('channel_name') === $userChannel) {
$pusher = new Pusher(
$this->settings->get('flarum-pusher.app_key'),
$this->settings->get('flarum-pusher.app_secret'),
@@ -39,7 +37,7 @@ class AuthController implements RequestHandlerInterface
['cluster' => $this->settings->get('flarum-pusher.app_cluster')]
);
$payload = json_decode($pusher->socket_auth($userChannel, Arr::get($body, 'socket_id')), true);
$payload = json_decode($pusher->socket_auth($userChannel, $request->input('socket_id')), true);
return new JsonResponse($payload);
}

View File

@@ -12,6 +12,7 @@ namespace Flarum\Statistics\Api\Controller;
use Carbon\Carbon;
use DateTime;
use Flarum\Discussion\Discussion;
use Flarum\Http\Controller\AbstractController;
use Flarum\Http\RequestUtil;
use Flarum\Post\Post;
use Flarum\Post\RegisteredTypesScope;
@@ -19,14 +20,13 @@ use Flarum\Settings\SettingsRepositoryInterface;
use Flarum\User\User;
use Illuminate\Contracts\Cache\Repository as CacheRepository;
use Illuminate\Database\Eloquent\Builder;
use Illuminate\Http\Request;
use Illuminate\Support\Arr;
use Laminas\Diactoros\Response\JsonResponse;
use Psr\Http\Message\ResponseInterface;
use Psr\Http\Message\ServerRequestInterface;
use Psr\Http\Server\RequestHandlerInterface;
use Tobscure\JsonApi\Exception\InvalidParameterException;
class ShowStatisticsData implements RequestHandlerInterface
class ShowStatisticsData extends AbstractController
{
/**
* The amount of time to cache lifetime statistics data for in seconds.
@@ -51,7 +51,7 @@ class ShowStatisticsData implements RequestHandlerInterface
];
}
public function handle(ServerRequestInterface $request): ResponseInterface
public function __invoke(Request $request): ResponseInterface
{
$actor = RequestUtil::getActor($request);
@@ -59,11 +59,9 @@ class ShowStatisticsData implements RequestHandlerInterface
// control panel.
$actor->assertAdmin();
$query = $request->getQueryParams();
$reportingPeriod = Arr::get($query, 'period');
$model = Arr::get($query, 'model');
$customDateRange = Arr::get($query, 'dateRange');
$reportingPeriod = $request->query('period');
$model = $request->query('model');
$customDateRange = $request->query('dateRange');
return new JsonResponse($this->getResponse($model, $reportingPeriod, $customDateRange));
}

View File

@@ -37,9 +37,9 @@ use Flarum\Tags\Tag;
use Flarum\Tags\Utf8SlugDriver;
use Illuminate\Database\Eloquent\Builder;
use Illuminate\Database\Eloquent\Relations\Relation;
use Psr\Http\Message\ServerRequestInterface;
use Illuminate\Http\Request;
$eagerLoadTagState = function ($query, ?ServerRequestInterface $request, array $relations) {
$eagerLoadTagState = function ($query, ?Request $request, array $relations) {
if ($request && in_array('tags.state', $relations, true)) {
$query->withStateFor(RequestUtil::getActor($request));
}
@@ -177,7 +177,7 @@ return [
(new Extend\ApiController(FlarumController\ListPostsController::class))
->addInclude('eventPostMentionsTags')
// Restricted tags should still appear as `deleted` to unauthorized users.
->loadWhere('eventPostMentionsTags', function (Relation|Builder $query, ?ServerRequestInterface $request) {
->loadWhere('eventPostMentionsTags', function (Relation|Builder $query, ?Request $request) {
if ($request) {
$actor = RequestUtil::getActor($request);
$query->whereVisibleTo($actor);

View File

@@ -15,8 +15,7 @@ use Flarum\Tags\Api\Serializer\TagSerializer;
use Flarum\Tags\Command\CreateTag;
use Flarum\Tags\Tag;
use Illuminate\Contracts\Bus\Dispatcher;
use Illuminate\Support\Arr;
use Psr\Http\Message\ServerRequestInterface;
use Illuminate\Http\Request;
use Tobscure\JsonApi\Document;
class CreateTagController extends AbstractCreateController
@@ -30,10 +29,10 @@ class CreateTagController extends AbstractCreateController
) {
}
protected function data(ServerRequestInterface $request, Document $document): Tag
protected function data(Request $request, Document $document): Tag
{
return $this->bus->dispatch(
new CreateTag(RequestUtil::getActor($request), Arr::get($request->getParsedBody(), 'data', []))
new CreateTag(RequestUtil::getActor($request), $request->json('data', []))
);
}
}

View File

@@ -13,8 +13,7 @@ use Flarum\Api\Controller\AbstractDeleteController;
use Flarum\Http\RequestUtil;
use Flarum\Tags\Command\DeleteTag;
use Illuminate\Contracts\Bus\Dispatcher;
use Illuminate\Support\Arr;
use Psr\Http\Message\ServerRequestInterface;
use Illuminate\Http\Request;
class DeleteTagController extends AbstractDeleteController
{
@@ -23,10 +22,10 @@ class DeleteTagController extends AbstractDeleteController
) {
}
protected function delete(ServerRequestInterface $request): void
protected function delete(Request $request): void
{
$this->bus->dispatch(
new DeleteTag(Arr::get($request->getQueryParams(), 'id'), RequestUtil::getActor($request))
new DeleteTag($request->query('id'), RequestUtil::getActor($request))
);
}
}

View File

@@ -16,7 +16,7 @@ use Flarum\Query\QueryCriteria;
use Flarum\Tags\Api\Serializer\TagSerializer;
use Flarum\Tags\Search\TagSearcher;
use Flarum\Tags\TagRepository;
use Psr\Http\Message\ServerRequestInterface;
use Illuminate\Http\Request;
use Tobscure\JsonApi\Document;
class ListTagsController extends AbstractListController
@@ -40,7 +40,7 @@ class ListTagsController extends AbstractListController
) {
}
protected function data(ServerRequestInterface $request, Document $document): iterable
protected function data(Request $request, Document $document): iterable
{
$actor = RequestUtil::getActor($request);
$include = $this->extractInclude($request);
@@ -58,7 +58,7 @@ class ListTagsController extends AbstractListController
$document->addPaginationLinks(
$this->url->to('api')->route('tags.index'),
$request->getQueryParams(),
$request->query(),
$offset,
$limit,
$results->areMoreResults() ? null : 0

View File

@@ -9,21 +9,21 @@
namespace Flarum\Tags\Api\Controller;
use Flarum\Http\Controller\AbstractController;
use Flarum\Http\RequestUtil;
use Flarum\Tags\Tag;
use Illuminate\Http\Request;
use Illuminate\Support\Arr;
use Laminas\Diactoros\Response\EmptyResponse;
use Psr\Http\Message\ResponseInterface;
use Psr\Http\Message\ServerRequestInterface;
use Psr\Http\Server\RequestHandlerInterface;
class OrderTagsController implements RequestHandlerInterface
class OrderTagsController extends AbstractController
{
public function handle(ServerRequestInterface $request): ResponseInterface
public function __invoke(Request $request): ResponseInterface
{
RequestUtil::getActor($request)->assertAdmin();
$order = Arr::get($request->getParsedBody(), 'order');
$order = $request->json('order');
if ($order === null) {
return new EmptyResponse(422);
@@ -37,7 +37,7 @@ class OrderTagsController implements RequestHandlerInterface
foreach ($order as $i => $parent) {
$parentId = Arr::get($parent, 'id');
Tag::where('id', $parentId)->update(['position' => $i]);
Tag::query()->where('id', $parentId)->update(['position' => $i]);
if (isset($parent['children']) && is_array($parent['children'])) {
foreach ($parent['children'] as $j => $childId) {

View File

@@ -15,8 +15,7 @@ use Flarum\Http\SlugManager;
use Flarum\Tags\Api\Serializer\TagSerializer;
use Flarum\Tags\Tag;
use Flarum\Tags\TagRepository;
use Illuminate\Support\Arr;
use Psr\Http\Message\ServerRequestInterface;
use Illuminate\Http\Request;
use Tobscure\JsonApi\Document;
class ShowTagController extends AbstractShowController
@@ -39,9 +38,9 @@ class ShowTagController extends AbstractShowController
) {
}
protected function data(ServerRequestInterface $request, Document $document): Tag
protected function data(Request $request, Document $document): Tag
{
$slug = Arr::get($request->getQueryParams(), 'slug');
$slug = $request->query('slug');
$actor = RequestUtil::getActor($request);
$include = $this->extractInclude($request);
$setParentOnChildren = false;

View File

@@ -15,8 +15,7 @@ use Flarum\Tags\Api\Serializer\TagSerializer;
use Flarum\Tags\Command\EditTag;
use Flarum\Tags\Tag;
use Illuminate\Contracts\Bus\Dispatcher;
use Illuminate\Support\Arr;
use Psr\Http\Message\ServerRequestInterface;
use Illuminate\Http\Request;
use Tobscure\JsonApi\Document;
class UpdateTagController extends AbstractShowController
@@ -28,11 +27,11 @@ class UpdateTagController extends AbstractShowController
) {
}
protected function data(ServerRequestInterface $request, Document $document): Tag
protected function data(Request $request, Document $document): Tag
{
$id = Arr::get($request->getQueryParams(), 'id');
$id = $request->query('id');
$actor = RequestUtil::getActor($request);
$data = Arr::get($request->getParsedBody(), 'data', []);
$data = $request->json('data', []);
return $this->bus->dispatch(
new EditTag($id, $actor, $data)

View File

@@ -17,8 +17,7 @@ use Flarum\Locale\TranslatorInterface;
use Flarum\Tags\Tag as TagModel;
use Flarum\Tags\TagRepository;
use Illuminate\Contracts\View\Factory;
use Illuminate\Support\Arr;
use Psr\Http\Message\ServerRequestInterface as Request;
use Illuminate\Http\Request;
class Tag
{
@@ -33,14 +32,13 @@ class Tag
public function __invoke(Document $document, Request $request): Document
{
$queryParams = $request->getQueryParams();
$actor = RequestUtil::getActor($request);
$slug = Arr::pull($queryParams, 'slug');
$sort = Arr::pull($queryParams, 'sort');
$q = Arr::pull($queryParams, 'q', '');
$page = Arr::pull($queryParams, 'page', 1);
$filters = Arr::pull($queryParams, 'filter', []);
$slug = $request->query('slug');
$sort = $request->query('sort');
$q = $request->query('q', '');
$page = $request->query('page', 1);
$filters = $request->query('filter', []);
$sortMap = $this->getSortMap();
@@ -91,13 +89,13 @@ class Tag
*/
protected function getApiDocument(Request $request, array $params): object
{
return json_decode($this->api->withParentRequest($request)->withQueryParams($params)->get('/discussions')->getBody());
return json_decode($this->api->withParentRequest($request)->withQueryParams($params)->get('/discussions')->content());
}
protected function getTagsDocument(Request $request, string $slug): object
{
return json_decode($this->api->withParentRequest($request)->withQueryParams([
'include' => 'children,children.parent,parent,parent.children.parent,state'
])->get("/tags/$slug")->getBody());
])->get("/tags/$slug")->content());
}
}

View File

@@ -16,8 +16,8 @@ use Flarum\Locale\TranslatorInterface;
use Flarum\Settings\SettingsRepositoryInterface;
use Flarum\Tags\TagRepository;
use Illuminate\Contracts\View\Factory;
use Illuminate\Http\Request;
use Illuminate\Support\Arr;
use Psr\Http\Message\ServerRequestInterface as Request;
class Tags
{
@@ -50,7 +50,7 @@ class Tags
$document->title = $this->translator->trans('flarum-tags.forum.all_tags.meta_title_text');
$document->meta['description'] = $this->translator->trans('flarum-tags.forum.all_tags.meta_description_text');
$document->content = $this->view->make('tags::frontend.content.tags', compact('primaryTags', 'secondaryTags', 'children'));
$document->canonicalUrl = $this->url->to('forum')->base().($defaultRoute === '/tags' ? '' : $request->getUri()->getPath());
$document->canonicalUrl = $this->url->to('forum')->base().($defaultRoute === '/tags' ? '' : $request->getUri());
$document->payload['apiDocument'] = $apiDocument;
return $document;
@@ -60,6 +60,6 @@ class Tags
{
return json_decode($this->api->withParentRequest($request)->withQueryParams([
'include' => 'children,lastPostedDiscussion,parent'
])->get('/tags')->getBody(), true);
])->get('/tags')->content(), true);
}
}

View File

@@ -11,11 +11,11 @@ namespace Flarum\Tags;
use Flarum\Api\Controller\ShowForumController;
use Flarum\Http\RequestUtil;
use Psr\Http\Message\ServerRequestInterface;
use Illuminate\Http\Request;
class LoadForumTagsRelationship
{
public function __invoke(ShowForumController $controller, array &$data, ServerRequestInterface $request): void
public function __invoke(ShowForumController $controller, array &$data, Request $request): void
{
$actor = RequestUtil::getActor($request);

View File

@@ -38,7 +38,6 @@
"require": {
"php": "^8.1",
"components/font-awesome": "^5.15.0",
"dflydev/fig-cookies": "^3.0",
"doctrine/dbal": "^3.6",
"dragonmantank/cron-expression": "*",
"franzl/whoops-middleware": "2.0",
@@ -53,8 +52,10 @@
"illuminate/events": "^10.0",
"illuminate/filesystem": "^10.0",
"illuminate/hashing": "^10.0",
"illuminate/http": "^10.0",
"illuminate/mail": "^10.0",
"illuminate/queue": "^10.0",
"illuminate/routing": "^10.0",
"illuminate/session": "^10.0",
"illuminate/support": "^10.0",
"illuminate/validation": "^10.0",
@@ -72,7 +73,6 @@
"middlewares/request-handler": "^2.0.2",
"monolog/monolog": "^3.0",
"nesbot/carbon": "^2.0",
"nikic/fast-route": "^1.3",
"psr/http-message": "^1.1",
"psr/http-server-handler": "^1.0.2",
"psr/http-server-middleware": "^1.0.2",

View File

@@ -20,8 +20,8 @@ use Flarum\User\User;
use Illuminate\Contracts\Container\Container;
use Illuminate\Contracts\Events\Dispatcher;
use Illuminate\Database\ConnectionInterface;
use Illuminate\Http\Request;
use Illuminate\Support\Arr;
use Psr\Http\Message\ServerRequestInterface as Request;
class AdminPayload
{

View File

@@ -14,7 +14,7 @@ use Flarum\Foundation\Application;
use Flarum\Frontend\Document;
use Flarum\Settings\SettingsRepositoryInterface;
use Illuminate\Contracts\View\Factory;
use Psr\Http\Message\ServerRequestInterface as Request;
use Illuminate\Http\Request;
class Index
{
@@ -29,7 +29,7 @@ class Index
{
$extensions = $this->extensions->getExtensions();
$extensionsEnabled = json_decode($this->settings->get('extensions_enabled', '{}'), true);
$csrfToken = $request->getAttribute('session')->token();
$csrfToken = $request->attributes->get('session')->token();
$mysqlVersion = $document->payload['mysqlVersion'];
$phpVersion = $document->payload['phpVersion'];

View File

@@ -11,15 +11,13 @@ namespace Flarum\Admin\Controller;
use Flarum\Bus\Dispatcher;
use Flarum\Extension\Command\ToggleExtension;
use Flarum\Http\Controller\AbstractController;
use Flarum\Http\RequestUtil;
use Flarum\Http\UrlGenerator;
use Illuminate\Support\Arr;
use Laminas\Diactoros\Response\RedirectResponse;
use Psr\Http\Message\ResponseInterface;
use Psr\Http\Message\ServerRequestInterface as Request;
use Psr\Http\Server\RequestHandlerInterface;
use Illuminate\Http\RedirectResponse;
use Illuminate\Http\Request;
class UpdateExtensionController implements RequestHandlerInterface
class UpdateExtensionController extends AbstractController
{
public function __construct(
protected UrlGenerator $url,
@@ -27,11 +25,10 @@ class UpdateExtensionController implements RequestHandlerInterface
) {
}
public function handle(Request $request): ResponseInterface
public function __invoke(Request $request, string $name): RedirectResponse
{
$actor = RequestUtil::getActor($request);
$enabled = (bool) (int) Arr::get($request->getParsedBody(), 'enabled');
$name = Arr::get($request->getQueryParams(), 'name');
$enabled = (bool) (int) $request->json('enabled');
$this->bus->dispatch(
new ToggleExtension($actor, $name, $enabled)

View File

@@ -10,22 +10,25 @@
namespace Flarum\Api;
use Flarum\Http\RequestUtil;
use Flarum\Http\Router;
use Flarum\User\User;
use Laminas\Diactoros\ServerRequestFactory;
use Laminas\Diactoros\Uri;
use Laminas\Stratigility\MiddlewarePipeInterface;
use Psr\Http\Message\ResponseInterface;
use Illuminate\Contracts\Container\Container;
use Illuminate\Http\Request;
use Illuminate\Http\Response;
use Illuminate\Routing\Pipeline;
use Psr\Http\Message\ServerRequestInterface;
use Symfony\Component\HttpFoundation\Request as SymfonyRequest;
class Client
{
protected ?User $actor = null;
protected ?ServerRequestInterface $parent = null;
protected ?Request $parent = null;
protected array $queryParams = [];
protected array $body = [];
public function __construct(
protected MiddlewarePipeInterface $pipe
protected array $middlewareStack,
protected Container $container
) {
}
@@ -42,9 +45,15 @@ class Client
return $new;
}
public function withParentRequest(ServerRequestInterface $parent): Client
public function withParentRequest(ServerRequestInterface|Request $parent): Client
{
$new = clone $this;
// Convert the PSR-7 request to an Illuminate request.
if ($parent instanceof ServerRequestInterface) {
$parent = RequestUtil::toIlluminate($parent);
}
$new->parent = $parent;
return $new;
@@ -66,27 +75,27 @@ class Client
return $new;
}
public function get(string $path): ResponseInterface
public function get(string $path): Response
{
return $this->send('GET', $path);
}
public function post(string $path): ResponseInterface
public function post(string $path): Response
{
return $this->send('POST', $path);
}
public function put(string $path): ResponseInterface
public function put(string $path): Response
{
return $this->send('PUT', $path);
}
public function patch(string $path): ResponseInterface
public function patch(string $path): Response
{
return $this->send('PATCH', $path);
}
public function delete(string $path): ResponseInterface
public function delete(string $path): Response
{
return $this->send('DELETE', $path);
}
@@ -96,16 +105,19 @@ class Client
*
* @internal
*/
public function send(string $method, string $path): ResponseInterface
public function send(string $method, string $path): Response
{
$request = ServerRequestFactory::fromGlobals(null, $this->queryParams, $this->body)
->withMethod($method)
->withUri(new Uri($path));
$parent = $this->parent ?: Request::createFromGlobals();
$symfonyRequest = SymfonyRequest::create(
$path, $method, $this->queryParams, $parent->cookies->all(), $parent->files->all(), $parent->server->all(), $this->body
);
$request = Request::createFromBase($symfonyRequest);
if ($this->parent) {
$request = $request
->withAttribute('ipAddress', $this->parent->getAttribute('ipAddress'))
->withAttribute('session', $this->parent->getAttribute('session'));
$request->attributes->set('ipAddress', $this->parent->attributes->get('ipAddress'));
$request->attributes->set('session', $this->parent->attributes->get('session'));
$request = RequestUtil::withActor($request, RequestUtil::getActor($this->parent));
}
@@ -114,6 +126,11 @@ class Client
$request = RequestUtil::withActor($request, $this->actor);
}
return $this->pipe->handle($request);
return (new Pipeline($this->container))
->send($request)
->through($this->middlewareStack)
->then(function (Request $request) {
return $this->container->make(Router::class)->dispatch($request);
});
}
}

View File

@@ -9,13 +9,13 @@
namespace Flarum\Api\Controller;
use Psr\Http\Message\ResponseInterface;
use Psr\Http\Message\ServerRequestInterface;
use Illuminate\Http\JsonResponse;
use Illuminate\Http\Request;
abstract class AbstractCreateController extends AbstractShowController
{
public function handle(ServerRequestInterface $request): ResponseInterface
public function __invoke(Request $request): JsonResponse
{
return parent::handle($request)->withStatus(201);
return parent::__invoke($request)->setStatusCode(201);
}
}

View File

@@ -9,19 +9,19 @@
namespace Flarum\Api\Controller;
use Flarum\Http\Controller\AbstractController;
use Illuminate\Http\Request;
use Laminas\Diactoros\Response\EmptyResponse;
use Psr\Http\Message\ResponseInterface;
use Psr\Http\Message\ServerRequestInterface;
use Psr\Http\Server\RequestHandlerInterface;
abstract class AbstractDeleteController implements RequestHandlerInterface
abstract class AbstractDeleteController extends AbstractController
{
public function handle(ServerRequestInterface $request): ResponseInterface
public function __invoke(Request $request): ResponseInterface
{
$this->delete($request);
return new EmptyResponse(204);
}
abstract protected function delete(ServerRequestInterface $request): void;
abstract protected function delete(Request $request): void;
}

View File

@@ -9,7 +9,7 @@
namespace Flarum\Api\Controller;
use Psr\Http\Message\ServerRequestInterface;
use Illuminate\Http\Request;
use Tobscure\JsonApi\Collection;
use Tobscure\JsonApi\Document;
use Tobscure\JsonApi\ElementInterface;
@@ -22,5 +22,5 @@ abstract class AbstractListController extends AbstractSerializeController
return new Collection($data, $serializer);
}
abstract protected function data(ServerRequestInterface $request, Document $document): iterable;
abstract protected function data(Request $request, Document $document): iterable;
}

View File

@@ -11,20 +11,19 @@ namespace Flarum\Api\Controller;
use Flarum\Api\JsonApiResponse;
use Flarum\Api\Serializer\AbstractSerializer;
use Flarum\Http\Controller\AbstractController;
use Illuminate\Contracts\Container\Container;
use Illuminate\Database\Eloquent\Collection;
use Illuminate\Support\Arr;
use Illuminate\Http\JsonResponse;
use Illuminate\Http\Request;
use Illuminate\Support\Str;
use InvalidArgumentException;
use Psr\Http\Message\ResponseInterface;
use Psr\Http\Message\ServerRequestInterface;
use Psr\Http\Server\RequestHandlerInterface;
use Tobscure\JsonApi\Document;
use Tobscure\JsonApi\ElementInterface;
use Tobscure\JsonApi\Parameters;
use Tobscure\JsonApi\SerializerInterface;
abstract class AbstractSerializeController implements RequestHandlerInterface
abstract class AbstractSerializeController extends AbstractController
{
/**
* The name of the serializer class to output results with.
@@ -93,7 +92,7 @@ abstract class AbstractSerializeController implements RequestHandlerInterface
*/
protected static array $loadRelationCallables = [];
public function handle(ServerRequestInterface $request): ResponseInterface
public function __invoke(Request $request): JsonResponse
{
$document = new Document;
@@ -134,7 +133,7 @@ abstract class AbstractSerializeController implements RequestHandlerInterface
/**
* Get the data to be serialized and assigned to the response document.
*/
abstract protected function data(ServerRequestInterface $request, Document $document): mixed;
abstract protected function data(Request $request, Document $document): mixed;
/**
* Create a PHP JSON-API Element for output in the document.
@@ -180,7 +179,7 @@ abstract class AbstractSerializeController implements RequestHandlerInterface
/**
* Eager loads the required relationships.
*/
protected function loadRelations(Collection $models, array $relations, ServerRequestInterface $request = null): void
protected function loadRelations(Collection $models, array $relations, Request $request = null): void
{
$addedRelations = $this->getRelationsToLoad($models);
$addedRelationCallables = $this->getRelationCallablesToLoad($models);
@@ -238,14 +237,14 @@ abstract class AbstractSerializeController implements RequestHandlerInterface
/**
* @throws \Tobscure\JsonApi\Exception\InvalidParameterException
*/
protected function extractInclude(ServerRequestInterface $request): array
protected function extractInclude(Request $request): array
{
$available = array_merge($this->include, $this->optionalInclude);
return $this->buildParameters($request)->getInclude($available) ?: $this->include;
}
protected function extractFields(ServerRequestInterface $request): array
protected function extractFields(Request $request): array
{
return $this->buildParameters($request)->getFields();
}
@@ -253,7 +252,7 @@ abstract class AbstractSerializeController implements RequestHandlerInterface
/**
* @throws \Tobscure\JsonApi\Exception\InvalidParameterException
*/
protected function extractSort(ServerRequestInterface $request): ?array
protected function extractSort(Request $request): ?array
{
return $this->buildParameters($request)->getSort($this->sortFields) ?: $this->sort;
}
@@ -261,7 +260,7 @@ abstract class AbstractSerializeController implements RequestHandlerInterface
/**
* @throws \Tobscure\JsonApi\Exception\InvalidParameterException
*/
protected function extractOffset(ServerRequestInterface $request): int
protected function extractOffset(Request $request): int
{
return (int) $this->buildParameters($request)->getOffset($this->extractLimit($request)) ?: 0;
}
@@ -269,24 +268,24 @@ abstract class AbstractSerializeController implements RequestHandlerInterface
/**
* @throws \Tobscure\JsonApi\Exception\InvalidParameterException
*/
protected function extractLimit(ServerRequestInterface $request): int
protected function extractLimit(Request $request): int
{
return (int) $this->buildParameters($request)->getLimit($this->maxLimit) ?: $this->limit;
}
protected function extractFilter(ServerRequestInterface $request): array
protected function extractFilter(Request $request): array
{
return $this->buildParameters($request)->getFilter() ?: [];
}
protected function buildParameters(ServerRequestInterface $request): Parameters
protected function buildParameters(Request $request): Parameters
{
return new Parameters($request->getQueryParams());
return new Parameters($request->query());
}
protected function sortIsDefault(ServerRequestInterface $request): bool
protected function sortIsDefault(Request $request): bool
{
return ! Arr::get($request->getQueryParams(), 'sort');
return ! $request->query('sort');
}
/**

View File

@@ -9,12 +9,13 @@
namespace Flarum\Api\Controller;
use Tobscure\JsonApi\ElementInterface;
use Tobscure\JsonApi\Resource;
use Tobscure\JsonApi\SerializerInterface;
abstract class AbstractShowController extends AbstractSerializeController
{
protected function createElement(mixed $data, SerializerInterface $serializer): \Tobscure\JsonApi\ElementInterface
protected function createElement(mixed $data, SerializerInterface $serializer): ElementInterface
{
return new Resource($data, $serializer);
}

View File

@@ -13,7 +13,7 @@ use Flarum\Foundation\Console\AssetsPublishCommand;
use Flarum\Foundation\Console\CacheClearCommand;
use Flarum\Foundation\IOException;
use Flarum\Http\RequestUtil;
use Psr\Http\Message\ServerRequestInterface;
use Illuminate\Http\Request;
use Symfony\Component\Console\Input\ArrayInput;
use Symfony\Component\Console\Output\NullOutput;
@@ -28,7 +28,7 @@ class ClearCacheController extends AbstractDeleteController
/**
* @throws IOException|\Flarum\User\Exception\PermissionDeniedException|\Symfony\Component\Console\Exception\ExceptionInterface
*/
protected function delete(ServerRequestInterface $request): void
protected function delete(Request $request): void
{
RequestUtil::getActor($request)->assertAdmin();

View File

@@ -15,8 +15,8 @@ use Flarum\Http\Event\DeveloperTokenCreated;
use Flarum\Http\RequestUtil;
use Illuminate\Contracts\Events\Dispatcher;
use Illuminate\Contracts\Validation\Factory;
use Illuminate\Http\Request;
use Illuminate\Support\Arr;
use Psr\Http\Message\ServerRequestInterface;
use Tobscure\JsonApi\Document;
/**
@@ -33,7 +33,7 @@ class CreateAccessTokenController extends AbstractCreateController
) {
}
public function data(ServerRequestInterface $request, Document $document): DeveloperAccessToken
public function data(Request $request, Document $document): DeveloperAccessToken
{
$actor = RequestUtil::getActor($request);

View File

@@ -16,8 +16,8 @@ use Flarum\Discussion\Discussion;
use Flarum\Http\RequestUtil;
use Illuminate\Contracts\Bus\Dispatcher;
use Illuminate\Database\Eloquent\Collection;
use Illuminate\Http\Request;
use Illuminate\Support\Arr;
use Psr\Http\Message\ServerRequestInterface;
use Tobscure\JsonApi\Document;
class CreateDiscussionController extends AbstractCreateController
@@ -37,7 +37,7 @@ class CreateDiscussionController extends AbstractCreateController
) {
}
protected function data(ServerRequestInterface $request, Document $document): Discussion
protected function data(Request $request, Document $document): Discussion
{
$actor = RequestUtil::getActor($request);
$ipAddress = $request->getAttribute('ipAddress');

View File

@@ -14,8 +14,8 @@ use Flarum\Group\Command\CreateGroup;
use Flarum\Group\Group;
use Flarum\Http\RequestUtil;
use Illuminate\Contracts\Bus\Dispatcher;
use Illuminate\Http\Request;
use Illuminate\Support\Arr;
use Psr\Http\Message\ServerRequestInterface;
use Tobscure\JsonApi\Document;
class CreateGroupController extends AbstractCreateController
@@ -27,7 +27,7 @@ class CreateGroupController extends AbstractCreateController
) {
}
protected function data(ServerRequestInterface $request, Document $document): Group
protected function data(Request $request, Document $document): Group
{
return $this->bus->dispatch(
new CreateGroup(RequestUtil::getActor($request), Arr::get($request->getParsedBody(), 'data', []))

View File

@@ -15,8 +15,8 @@ use Flarum\Http\RequestUtil;
use Flarum\Post\Command\PostReply;
use Flarum\Post\CommentPost;
use Illuminate\Contracts\Bus\Dispatcher;
use Illuminate\Http\Request;
use Illuminate\Support\Arr;
use Psr\Http\Message\ServerRequestInterface;
use Tobscure\JsonApi\Document;
class CreatePostController extends AbstractCreateController
@@ -35,7 +35,7 @@ class CreatePostController extends AbstractCreateController
) {
}
protected function data(ServerRequestInterface $request, Document $document): CommentPost
protected function data(Request $request, Document $document): CommentPost
{
$actor = RequestUtil::getActor($request);
$data = Arr::get($request->getParsedBody(), 'data', []);

View File

@@ -9,24 +9,22 @@
namespace Flarum\Api\Controller;
use Flarum\Http\Controller\AbstractController;
use Flarum\Http\RememberAccessToken;
use Flarum\Http\SessionAccessToken;
use Flarum\User\Exception\NotAuthenticatedException;
use Flarum\User\UserRepository;
use Illuminate\Contracts\Bus\Dispatcher as BusDispatcher;
use Illuminate\Contracts\Events\Dispatcher as EventDispatcher;
use Illuminate\Support\Arr;
use Laminas\Diactoros\Response\JsonResponse;
use Psr\Http\Message\ResponseInterface;
use Psr\Http\Message\ServerRequestInterface;
use Psr\Http\Server\RequestHandlerInterface;
use Illuminate\Http\JsonResponse;
use Illuminate\Http\Request;
/**
* Not to be confused with the CreateAccessTokenController,
* this controller is used to authenticate a user with credentials,
* and return a system generated session-type access token.
*/
class CreateTokenController implements RequestHandlerInterface
class CreateTokenController extends AbstractController
{
public function __construct(
protected UserRepository $users,
@@ -35,12 +33,10 @@ class CreateTokenController implements RequestHandlerInterface
) {
}
public function handle(ServerRequestInterface $request): ResponseInterface
public function __invoke(Request $request): JsonResponse
{
$body = $request->getParsedBody();
$identification = Arr::get($body, 'identification');
$password = Arr::get($body, 'password');
$identification = $request->json('identification');
$password = $request->json('password');
$user = $identification
? $this->users->findByIdentification($identification)
@@ -50,7 +46,7 @@ class CreateTokenController implements RequestHandlerInterface
throw new NotAuthenticatedException;
}
if (Arr::get($body, 'remember')) {
if ($request->json('remember')) {
$token = RememberAccessToken::generate($user->id);
} else {
$token = SessionAccessToken::generate($user->id);

View File

@@ -14,8 +14,8 @@ use Flarum\Http\RequestUtil;
use Flarum\User\Command\RegisterUser;
use Flarum\User\User;
use Illuminate\Contracts\Bus\Dispatcher;
use Illuminate\Http\Request;
use Illuminate\Support\Arr;
use Psr\Http\Message\ServerRequestInterface;
use Tobscure\JsonApi\Document;
class CreateUserController extends AbstractCreateController
@@ -27,7 +27,7 @@ class CreateUserController extends AbstractCreateController
) {
}
protected function data(ServerRequestInterface $request, Document $document): User
protected function data(Request $request, Document $document): User
{
return $this->bus->dispatch(
new RegisterUser(RequestUtil::getActor($request), Arr::get($request->getParsedBody(), 'data', []))

View File

@@ -14,15 +14,15 @@ use Flarum\Http\RequestUtil;
use Flarum\User\Exception\PermissionDeniedException;
use Illuminate\Contracts\Session\Session;
use Illuminate\Database\Eloquent\ModelNotFoundException;
use Illuminate\Http\Request;
use Illuminate\Support\Arr;
use Psr\Http\Message\ServerRequestInterface;
class DeleteAccessTokenController extends AbstractDeleteController
{
protected function delete(ServerRequestInterface $request): void
protected function delete(Request $request): void
{
$actor = RequestUtil::getActor($request);
$id = Arr::get($request->getQueryParams(), 'id');
$id = $request->query('id');
$actor->assertRegistered();

View File

@@ -12,7 +12,7 @@ namespace Flarum\Api\Controller;
use Flarum\Http\RequestUtil;
use Flarum\Notification\Command\DeleteAllNotifications;
use Illuminate\Contracts\Bus\Dispatcher;
use Psr\Http\Message\ServerRequestInterface;
use Illuminate\Http\Request;
class DeleteAllNotificationsController extends AbstractDeleteController
{
@@ -21,7 +21,7 @@ class DeleteAllNotificationsController extends AbstractDeleteController
) {
}
protected function delete(ServerRequestInterface $request): void
protected function delete(Request $request): void
{
$this->bus->dispatch(
new DeleteAllNotifications(RequestUtil::getActor($request))

View File

@@ -13,8 +13,7 @@ use Flarum\Api\Serializer\UserSerializer;
use Flarum\Http\RequestUtil;
use Flarum\User\Command\DeleteAvatar;
use Illuminate\Contracts\Bus\Dispatcher;
use Illuminate\Support\Arr;
use Psr\Http\Message\ServerRequestInterface;
use Illuminate\Http\Request;
use Tobscure\JsonApi\Document;
class DeleteAvatarController extends AbstractShowController
@@ -26,10 +25,10 @@ class DeleteAvatarController extends AbstractShowController
) {
}
protected function data(ServerRequestInterface $request, Document $document): mixed
protected function data(Request $request, Document $document): mixed
{
return $this->bus->dispatch(
new DeleteAvatar(Arr::get($request->getQueryParams(), 'id'), RequestUtil::getActor($request))
new DeleteAvatar($request->query( 'id'), RequestUtil::getActor($request))
);
}
}

View File

@@ -12,8 +12,8 @@ namespace Flarum\Api\Controller;
use Flarum\Discussion\Command\DeleteDiscussion;
use Flarum\Http\RequestUtil;
use Illuminate\Contracts\Bus\Dispatcher;
use Illuminate\Http\Request;
use Illuminate\Support\Arr;
use Psr\Http\Message\ServerRequestInterface;
class DeleteDiscussionController extends AbstractDeleteController
{
@@ -22,11 +22,11 @@ class DeleteDiscussionController extends AbstractDeleteController
) {
}
protected function delete(ServerRequestInterface $request): void
protected function delete(Request $request): void
{
$id = Arr::get($request->getQueryParams(), 'id');
$id = $request->query('id');
$actor = RequestUtil::getActor($request);
$input = $request->getParsedBody();
$input = $request->json()->all();
$this->bus->dispatch(
new DeleteDiscussion($id, $actor, $input)

View File

@@ -13,7 +13,7 @@ use Flarum\Http\RequestUtil;
use Flarum\Settings\SettingsRepositoryInterface;
use Illuminate\Contracts\Filesystem\Factory;
use Illuminate\Contracts\Filesystem\Filesystem;
use Psr\Http\Message\ServerRequestInterface;
use Illuminate\Http\Request;
class DeleteFaviconController extends AbstractDeleteController
{
@@ -26,7 +26,7 @@ class DeleteFaviconController extends AbstractDeleteController
$this->uploadDir = $filesystemFactory->disk('flarum-assets');
}
protected function delete(ServerRequestInterface $request): void
protected function delete(Request $request): void
{
RequestUtil::getActor($request)->assertAdmin();

View File

@@ -12,8 +12,7 @@ namespace Flarum\Api\Controller;
use Flarum\Group\Command\DeleteGroup;
use Flarum\Http\RequestUtil;
use Illuminate\Contracts\Bus\Dispatcher;
use Illuminate\Support\Arr;
use Psr\Http\Message\ServerRequestInterface;
use Illuminate\Http\Request;
class DeleteGroupController extends AbstractDeleteController
{
@@ -22,10 +21,10 @@ class DeleteGroupController extends AbstractDeleteController
) {
}
protected function delete(ServerRequestInterface $request): void
protected function delete(Request $request): void
{
$this->bus->dispatch(
new DeleteGroup(Arr::get($request->getQueryParams(), 'id'), RequestUtil::getActor($request))
new DeleteGroup($request->query('id'), RequestUtil::getActor($request))
);
}
}

View File

@@ -13,7 +13,7 @@ use Flarum\Http\RequestUtil;
use Flarum\Settings\SettingsRepositoryInterface;
use Illuminate\Contracts\Filesystem\Factory;
use Illuminate\Contracts\Filesystem\Filesystem;
use Psr\Http\Message\ServerRequestInterface;
use Illuminate\Http\Request;
class DeleteLogoController extends AbstractDeleteController
{
@@ -26,7 +26,7 @@ class DeleteLogoController extends AbstractDeleteController
$this->uploadDir = $filesystemFactory->disk('flarum-assets');
}
protected function delete(ServerRequestInterface $request): void
protected function delete(Request $request): void
{
RequestUtil::getActor($request)->assertAdmin();

View File

@@ -12,8 +12,7 @@ namespace Flarum\Api\Controller;
use Flarum\Http\RequestUtil;
use Flarum\Post\Command\DeletePost;
use Illuminate\Contracts\Bus\Dispatcher;
use Illuminate\Support\Arr;
use Psr\Http\Message\ServerRequestInterface;
use Illuminate\Http\Request;
class DeletePostController extends AbstractDeleteController
{
@@ -22,10 +21,10 @@ class DeletePostController extends AbstractDeleteController
) {
}
protected function delete(ServerRequestInterface $request): void
protected function delete(Request $request): void
{
$this->bus->dispatch(
new DeletePost(Arr::get($request->getQueryParams(), 'id'), RequestUtil::getActor($request))
new DeletePost($request->query('id'), RequestUtil::getActor($request))
);
}
}

View File

@@ -12,8 +12,7 @@ namespace Flarum\Api\Controller;
use Flarum\Http\RequestUtil;
use Flarum\User\Command\DeleteUser;
use Illuminate\Contracts\Bus\Dispatcher;
use Illuminate\Support\Arr;
use Psr\Http\Message\ServerRequestInterface;
use Illuminate\Http\Request;
class DeleteUserController extends AbstractDeleteController
{
@@ -22,10 +21,10 @@ class DeleteUserController extends AbstractDeleteController
) {
}
protected function delete(ServerRequestInterface $request): void
protected function delete(Request $request): void
{
$this->bus->dispatch(
new DeleteUser(Arr::get($request->getQueryParams(), 'id'), RequestUtil::getActor($request))
new DeleteUser($request->query('id'), RequestUtil::getActor($request))
);
}
}

View File

@@ -10,15 +10,14 @@
namespace Flarum\Api\Controller;
use Flarum\Api\ForgotPasswordValidator;
use Flarum\Http\Controller\AbstractController;
use Flarum\User\Job\RequestPasswordResetJob;
use Illuminate\Contracts\Queue\Queue;
use Illuminate\Support\Arr;
use Illuminate\Http\Request;
use Laminas\Diactoros\Response\EmptyResponse;
use Psr\Http\Message\ResponseInterface;
use Psr\Http\Message\ServerRequestInterface;
use Psr\Http\Server\RequestHandlerInterface;
class ForgotPasswordController implements RequestHandlerInterface
class ForgotPasswordController extends AbstractController
{
public function __construct(
protected Queue $queue,
@@ -26,13 +25,13 @@ class ForgotPasswordController implements RequestHandlerInterface
) {
}
public function handle(ServerRequestInterface $request): ResponseInterface
public function __invoke(Request $request): ResponseInterface
{
$params = $request->getParsedBody();
$this->validator->assertValid(
$request->json()->all()
);
$this->validator->assertValid($params);
$email = Arr::get($params, 'email');
$email = $request->json('email');
// Prevents leaking user existence by not throwing an error.
// Prevents leaking user existence by duration by using a queued job.

View File

@@ -14,7 +14,7 @@ use Flarum\Http\Filter\AccessTokenFilterer;
use Flarum\Http\RequestUtil;
use Flarum\Http\UrlGenerator;
use Flarum\Query\QueryCriteria;
use Psr\Http\Message\ServerRequestInterface;
use Illuminate\Http\Request;
use Tobscure\JsonApi\Document;
class ListAccessTokensController extends AbstractListController
@@ -27,7 +27,7 @@ class ListAccessTokensController extends AbstractListController
) {
}
protected function data(ServerRequestInterface $request, Document $document): iterable
protected function data(Request $request, Document $document): iterable
{
$actor = RequestUtil::getActor($request);
@@ -41,7 +41,7 @@ class ListAccessTokensController extends AbstractListController
$document->addPaginationLinks(
$this->url->to('api')->route('access-tokens.index'),
$request->getQueryParams(),
$request->query(),
$offset,
$limit,
$tokens->areMoreResults() ? null : 0

View File

@@ -16,7 +16,7 @@ use Flarum\Discussion\Search\DiscussionSearcher;
use Flarum\Http\RequestUtil;
use Flarum\Http\UrlGenerator;
use Flarum\Query\QueryCriteria;
use Psr\Http\Message\ServerRequestInterface;
use Illuminate\Http\Request;
use Tobscure\JsonApi\Document;
class ListDiscussionsController extends AbstractListController
@@ -46,7 +46,7 @@ class ListDiscussionsController extends AbstractListController
) {
}
protected function data(ServerRequestInterface $request, Document $document): iterable
protected function data(Request $request, Document $document): iterable
{
$actor = RequestUtil::getActor($request);
$filters = $this->extractFilter($request);
@@ -66,7 +66,7 @@ class ListDiscussionsController extends AbstractListController
$document->addPaginationLinks(
$this->url->to('api')->route('discussions.index'),
$request->getQueryParams(),
$request->query(),
$offset,
$limit,
$results->areMoreResults() ? null : 0

View File

@@ -14,7 +14,7 @@ use Flarum\Group\Filter\GroupFilterer;
use Flarum\Http\RequestUtil;
use Flarum\Http\UrlGenerator;
use Flarum\Query\QueryCriteria;
use Psr\Http\Message\ServerRequestInterface;
use Illuminate\Http\Request;
use Tobscure\JsonApi\Document;
class ListGroupsController extends AbstractListController
@@ -31,7 +31,7 @@ class ListGroupsController extends AbstractListController
) {
}
protected function data(ServerRequestInterface $request, Document $document): iterable
protected function data(Request $request, Document $document): iterable
{
$actor = RequestUtil::getActor($request);
@@ -48,7 +48,7 @@ class ListGroupsController extends AbstractListController
$document->addPaginationLinks(
$this->url->to('api')->route('groups.index'),
$request->getQueryParams(),
$request->query(),
$offset,
$limit,
$queryResults->areMoreResults() ? null : 0

View File

@@ -14,7 +14,7 @@ use Flarum\Discussion\Discussion;
use Flarum\Http\RequestUtil;
use Flarum\Http\UrlGenerator;
use Flarum\Notification\NotificationRepository;
use Psr\Http\Message\ServerRequestInterface;
use Illuminate\Http\Request;
use Tobscure\JsonApi\Document;
class ListNotificationsController extends AbstractListController
@@ -33,7 +33,7 @@ class ListNotificationsController extends AbstractListController
) {
}
protected function data(ServerRequestInterface $request, Document $document): iterable
protected function data(Request $request, Document $document): iterable
{
$actor = RequestUtil::getActor($request);
@@ -64,7 +64,7 @@ class ListNotificationsController extends AbstractListController
$document->addPaginationLinks(
$this->url->to('api')->route('notifications.index'),
$request->getQueryParams(),
$request->query(),
$offset,
$limit,
$areMoreResults ? null : 0

View File

@@ -15,8 +15,8 @@ use Flarum\Http\UrlGenerator;
use Flarum\Post\Filter\PostFilterer;
use Flarum\Post\PostRepository;
use Flarum\Query\QueryCriteria;
use Illuminate\Http\Request;
use Illuminate\Support\Arr;
use Psr\Http\Message\ServerRequestInterface;
use Tobscure\JsonApi\Document;
use Tobscure\JsonApi\Exception\InvalidParameterException;
@@ -41,7 +41,7 @@ class ListPostsController extends AbstractListController
) {
}
protected function data(ServerRequestInterface $request, Document $document): iterable
protected function data(Request $request, Document $document): iterable
{
$actor = RequestUtil::getActor($request);
@@ -57,7 +57,7 @@ class ListPostsController extends AbstractListController
$document->addPaginationLinks(
$this->url->to('api')->route('posts.index'),
$request->getQueryParams(),
$request->query(),
$offset,
$limit,
$results->areMoreResults() ? null : 0
@@ -84,7 +84,7 @@ class ListPostsController extends AbstractListController
/**
* @link https://github.com/flarum/framework/pull/3506
*/
protected function extractSort(ServerRequestInterface $request): ?array
protected function extractSort(Request $request): ?array
{
$sort = [];
@@ -95,15 +95,14 @@ class ListPostsController extends AbstractListController
return $sort;
}
protected function extractOffset(ServerRequestInterface $request): int
protected function extractOffset(Request $request): int
{
$actor = RequestUtil::getActor($request);
$queryParams = $request->getQueryParams();
$sort = $this->extractSort($request);
$limit = $this->extractLimit($request);
$filter = $this->extractFilter($request);
if (($near = Arr::get($queryParams, 'page.near')) > 1) {
if (($near = $request->query('page.near')) > 1) {
if (count($filter) > 1 || ! isset($filter['discussion']) || $sort) {
throw new InvalidParameterException(
'You can only use page[near] with filter[discussion] and the default sort order'

View File

@@ -15,7 +15,7 @@ use Flarum\Http\UrlGenerator;
use Flarum\Query\QueryCriteria;
use Flarum\User\Filter\UserFilterer;
use Flarum\User\Search\UserSearcher;
use Psr\Http\Message\ServerRequestInterface;
use Illuminate\Http\Request;
use Tobscure\JsonApi\Document;
class ListUsersController extends AbstractListController
@@ -39,7 +39,7 @@ class ListUsersController extends AbstractListController
) {
}
protected function data(ServerRequestInterface $request, Document $document): iterable
protected function data(Request $request, Document $document): iterable
{
$actor = RequestUtil::getActor($request);
@@ -69,7 +69,7 @@ class ListUsersController extends AbstractListController
$document->addPaginationLinks(
$this->url->to('api')->route('users.index'),
$request->getQueryParams(),
$request->query(),
$offset,
$limit,
$results->areMoreResults() ? null : 0

View File

@@ -12,7 +12,7 @@ namespace Flarum\Api\Controller;
use Flarum\Http\RequestUtil;
use Flarum\Notification\Command\ReadAllNotifications;
use Illuminate\Contracts\Bus\Dispatcher;
use Psr\Http\Message\ServerRequestInterface;
use Illuminate\Http\Request;
class ReadAllNotificationsController extends AbstractDeleteController
{
@@ -21,7 +21,7 @@ class ReadAllNotificationsController extends AbstractDeleteController
) {
}
protected function delete(ServerRequestInterface $request): void
protected function delete(Request $request): void
{
$this->bus->dispatch(
new ReadAllNotifications(RequestUtil::getActor($request))

View File

@@ -9,6 +9,7 @@
namespace Flarum\Api\Controller;
use Flarum\Http\Controller\AbstractController;
use Flarum\Http\RequestUtil;
use Flarum\Http\UrlGenerator;
use Flarum\Locale\TranslatorInterface;
@@ -16,13 +17,11 @@ use Flarum\Settings\SettingsRepositoryInterface;
use Flarum\User\AccountActivationMailerTrait;
use Flarum\User\Exception\PermissionDeniedException;
use Illuminate\Contracts\Queue\Queue;
use Illuminate\Support\Arr;
use Illuminate\Http\Request;
use Laminas\Diactoros\Response\EmptyResponse;
use Psr\Http\Message\ResponseInterface;
use Psr\Http\Message\ServerRequestInterface;
use Psr\Http\Server\RequestHandlerInterface;
class SendConfirmationEmailController implements RequestHandlerInterface
class SendConfirmationEmailController extends AbstractController
{
use AccountActivationMailerTrait;
@@ -34,9 +33,8 @@ class SendConfirmationEmailController implements RequestHandlerInterface
) {
}
public function handle(ServerRequestInterface $request): ResponseInterface
public function __invoke(Request $request, int $id): ResponseInterface
{
$id = Arr::get($request->getQueryParams(), 'id');
$actor = RequestUtil::getActor($request);
$actor->assertRegistered();

View File

@@ -9,16 +9,16 @@
namespace Flarum\Api\Controller;
use Flarum\Http\Controller\AbstractController;
use Flarum\Http\RequestUtil;
use Flarum\Locale\TranslatorInterface;
use Illuminate\Contracts\Mail\Mailer;
use Illuminate\Http\Request;
use Illuminate\Mail\Message;
use Laminas\Diactoros\Response\EmptyResponse;
use Psr\Http\Message\ResponseInterface;
use Psr\Http\Message\ServerRequestInterface;
use Psr\Http\Server\RequestHandlerInterface;
class SendTestMailController implements RequestHandlerInterface
class SendTestMailController extends AbstractController
{
public function __construct(
protected Mailer $mailer,
@@ -26,7 +26,7 @@ class SendTestMailController implements RequestHandlerInterface
) {
}
public function handle(ServerRequestInterface $request): ResponseInterface
public function __invoke(Request $request): ResponseInterface
{
$actor = RequestUtil::getActor($request);
$actor->assertAdmin();

View File

@@ -10,22 +10,21 @@
namespace Flarum\Api\Controller;
use Flarum\Group\Permission;
use Flarum\Http\Controller\AbstractController;
use Flarum\Http\RequestUtil;
use Illuminate\Http\Request;
use Illuminate\Support\Arr;
use Laminas\Diactoros\Response\EmptyResponse;
use Psr\Http\Message\ResponseInterface;
use Psr\Http\Message\ServerRequestInterface;
use Psr\Http\Server\RequestHandlerInterface;
class SetPermissionController implements RequestHandlerInterface
class SetPermissionController extends AbstractController
{
public function handle(ServerRequestInterface $request): ResponseInterface
public function __invoke(Request $request): ResponseInterface
{
RequestUtil::getActor($request)->assertAdmin();
$body = $request->getParsedBody();
$permission = Arr::get($body, 'permission');
$groupIds = Arr::get($body, 'groupIds');
$permission = $request->json('permission');
$groupIds = $request->json('groupIds');
Permission::where('permission', $permission)->delete();

View File

@@ -9,16 +9,16 @@
namespace Flarum\Api\Controller;
use Flarum\Http\Controller\AbstractController;
use Flarum\Http\RequestUtil;
use Flarum\Settings\Event;
use Flarum\Settings\SettingsRepositoryInterface;
use Illuminate\Contracts\Events\Dispatcher;
use Illuminate\Http\Request;
use Laminas\Diactoros\Response\EmptyResponse;
use Psr\Http\Message\ResponseInterface;
use Psr\Http\Message\ServerRequestInterface;
use Psr\Http\Server\RequestHandlerInterface;
class SetSettingsController implements RequestHandlerInterface
class SetSettingsController extends AbstractController
{
public function __construct(
protected SettingsRepositoryInterface $settings,
@@ -26,11 +26,11 @@ class SetSettingsController implements RequestHandlerInterface
) {
}
public function handle(ServerRequestInterface $request): ResponseInterface
public function __invoke(Request $request): ResponseInterface
{
RequestUtil::getActor($request)->assertAdmin();
$settings = $request->getParsedBody();
$settings = $request->json()->all();
$this->dispatcher->dispatch(new Event\Saving($settings));
@@ -42,6 +42,6 @@ class SetSettingsController implements RequestHandlerInterface
$this->dispatcher->dispatch(new Event\Saved($settings));
return new EmptyResponse(204);
return new EmptyResponse();
}
}

View File

@@ -19,9 +19,8 @@ use Flarum\Post\PostRepository;
use Flarum\User\User;
use Illuminate\Database\Eloquent\Builder;
use Illuminate\Database\Eloquent\Collection;
use Illuminate\Support\Arr;
use Illuminate\Http\Request;
use Illuminate\Support\Str;
use Psr\Http\Message\ServerRequestInterface;
use Tobscure\JsonApi\Document;
class ShowDiscussionController extends AbstractShowController
@@ -52,13 +51,13 @@ class ShowDiscussionController extends AbstractShowController
) {
}
protected function data(ServerRequestInterface $request, Document $document): Discussion
protected function data(Request $request, Document $document): Discussion
{
$discussionId = Arr::get($request->getQueryParams(), 'id');
$discussionId = $request->query('id');
$actor = RequestUtil::getActor($request);
$include = $this->extractInclude($request);
if (Arr::get($request->getQueryParams(), 'bySlug', false)) {
if ($request->query('bySlug', false)) {
$discussion = $this->slugManager->forResource(Discussion::class)->fromSlug($discussionId, $actor);
} else {
$discussion = $this->discussions->findOrFail($discussionId, $actor);
@@ -78,7 +77,7 @@ class ShowDiscussionController extends AbstractShowController
return $discussion;
}
private function includePosts(Discussion $discussion, ServerRequestInterface $request, array $include): void
private function includePosts(Discussion $discussion, Request $request, array $include): void
{
$actor = RequestUtil::getActor($request);
$limit = $this->extractLimit($request);
@@ -111,12 +110,11 @@ class ShowDiscussionController extends AbstractShowController
return $relationships;
}
private function getPostsOffset(ServerRequestInterface $request, Discussion $discussion, int $limit): int
private function getPostsOffset(Request $request, Discussion $discussion, int $limit): int
{
$queryParams = $request->getQueryParams();
$actor = RequestUtil::getActor($request);
if (($near = Arr::get($queryParams, 'page.near')) > 1) {
if (($near = $request->query('page.near')) > 1) {
$offset = $this->posts->getIndexForNumber($discussion->id, $near, $actor);
$offset = max(0, $offset - $limit / 2);
} else {
@@ -126,7 +124,7 @@ class ShowDiscussionController extends AbstractShowController
return $offset;
}
private function loadPosts(Discussion $discussion, User $actor, int $offset, int $limit, array $include, ServerRequestInterface $request): array
private function loadPosts(Discussion $discussion, User $actor, int $offset, int $limit, array $include, Request $request): array
{
/** @var Builder $query */
$query = $discussion->posts()->whereVisibleTo($actor);

View File

@@ -13,8 +13,8 @@ use Flarum\Api\Serializer\ExtensionReadmeSerializer;
use Flarum\Extension\Extension;
use Flarum\Extension\ExtensionManager;
use Flarum\Http\RequestUtil;
use Illuminate\Http\Request;
use Illuminate\Support\Arr;
use Psr\Http\Message\ServerRequestInterface;
use Tobscure\JsonApi\Document;
class ShowExtensionReadmeController extends AbstractShowController
@@ -26,9 +26,9 @@ class ShowExtensionReadmeController extends AbstractShowController
) {
}
protected function data(ServerRequestInterface $request, Document $document): ?Extension
protected function data(Request $request, Document $document): ?Extension
{
$extensionName = Arr::get($request->getQueryParams(), 'name');
$extensionName = $request->query('name');
RequestUtil::getActor($request)->assertAdmin();

View File

@@ -12,7 +12,7 @@ namespace Flarum\Api\Controller;
use Flarum\Api\Serializer\ForumSerializer;
use Flarum\Group\Group;
use Flarum\Http\RequestUtil;
use Psr\Http\Message\ServerRequestInterface;
use Illuminate\Http\Request;
use Tobscure\JsonApi\Document;
class ShowForumController extends AbstractShowController
@@ -21,7 +21,7 @@ class ShowForumController extends AbstractShowController
public array $include = ['groups', 'actor', 'actor.groups'];
protected function data(ServerRequestInterface $request, Document $document): array
protected function data(Request $request, Document $document): array
{
$actor = RequestUtil::getActor($request);

View File

@@ -13,8 +13,7 @@ use Flarum\Api\Serializer\GroupSerializer;
use Flarum\Group\Group;
use Flarum\Group\GroupRepository;
use Flarum\Http\RequestUtil;
use Illuminate\Support\Arr;
use Psr\Http\Message\ServerRequestInterface;
use Illuminate\Http\Request;
use Tobscure\JsonApi\Document;
class ShowGroupController extends AbstractShowController
@@ -26,9 +25,9 @@ class ShowGroupController extends AbstractShowController
) {
}
protected function data(ServerRequestInterface $request, Document $document): Group
protected function data(Request $request, Document $document): Group
{
$id = Arr::get($request->getQueryParams(), 'id');
$id = $request->query('id');
$actor = RequestUtil::getActor($request);
$group = $this->groups->findOrFail($id, $actor);

View File

@@ -13,14 +13,14 @@ use Flarum\Api\Serializer\MailSettingsSerializer;
use Flarum\Http\RequestUtil;
use Flarum\Settings\SettingsRepositoryInterface;
use Illuminate\Contracts\Validation\Factory;
use Psr\Http\Message\ServerRequestInterface;
use Illuminate\Http\Request;
use Tobscure\JsonApi\Document;
class ShowMailSettingsController extends AbstractShowController
{
public ?string $serializer = MailSettingsSerializer::class;
protected function data(ServerRequestInterface $request, Document $document): array
protected function data(Request $request, Document $document): array
{
RequestUtil::getActor($request)->assertAdmin();

View File

@@ -14,8 +14,7 @@ use Flarum\Http\RequestUtil;
use Flarum\Post\Post;
use Flarum\Post\PostRepository;
use Illuminate\Database\Eloquent\Collection;
use Illuminate\Support\Arr;
use Psr\Http\Message\ServerRequestInterface;
use Illuminate\Http\Request;
use Tobscure\JsonApi\Document;
class ShowPostController extends AbstractShowController
@@ -35,9 +34,9 @@ class ShowPostController extends AbstractShowController
) {
}
protected function data(ServerRequestInterface $request, Document $document): Post
protected function data(Request $request, Document $document): Post
{
$post = $this->posts->findOrFail(Arr::get($request->getQueryParams(), 'id'), RequestUtil::getActor($request));
$post = $this->posts->findOrFail($request->query('id'), RequestUtil::getActor($request));
$include = $this->extractInclude($request);

View File

@@ -15,8 +15,7 @@ use Flarum\Http\RequestUtil;
use Flarum\Http\SlugManager;
use Flarum\User\User;
use Flarum\User\UserRepository;
use Illuminate\Support\Arr;
use Psr\Http\Message\ServerRequestInterface;
use Illuminate\Http\Request;
use Tobscure\JsonApi\Document;
class ShowUserController extends AbstractShowController
@@ -31,12 +30,12 @@ class ShowUserController extends AbstractShowController
) {
}
protected function data(ServerRequestInterface $request, Document $document): User
protected function data(Request $request, Document $document): User
{
$id = Arr::get($request->getQueryParams(), 'id');
$id = $request->query('id');
$actor = RequestUtil::getActor($request);
if (Arr::get($request->getQueryParams(), 'bySlug', false)) {
if ($request->query('bySlug', false)) {
$user = $this->slugManager->forResource(User::class)->fromSlug($id, $actor);
} else {
$user = $this->users->findOrFail($id, $actor);

View File

@@ -13,11 +13,11 @@ use Flarum\Http\RememberAccessToken;
use Flarum\Http\RequestUtil;
use Flarum\Http\SessionAccessToken;
use Illuminate\Contracts\Database\Eloquent\Builder;
use Psr\Http\Message\ServerRequestInterface;
use Illuminate\Http\Request;
class TerminateAllOtherSessionsController extends AbstractDeleteController
{
protected function delete(ServerRequestInterface $request): void
protected function delete(Request $request): void
{
$actor = RequestUtil::getActor($request);

View File

@@ -11,8 +11,8 @@ namespace Flarum\Api\Controller;
use Flarum\Extension\ExtensionManager;
use Flarum\Http\RequestUtil;
use Illuminate\Http\Request;
use Illuminate\Support\Arr;
use Psr\Http\Message\ServerRequestInterface;
class UninstallExtensionController extends AbstractDeleteController
{
@@ -21,11 +21,11 @@ class UninstallExtensionController extends AbstractDeleteController
) {
}
protected function delete(ServerRequestInterface $request): void
protected function delete(Request $request): void
{
RequestUtil::getActor($request)->assertAdmin();
$name = Arr::get($request->getQueryParams(), 'name');
$name = $request->query('name');
if ($this->extensions->getExtension($name) == null) {
return;

View File

@@ -17,8 +17,8 @@ use Flarum\Http\RequestUtil;
use Flarum\Post\Post;
use Illuminate\Contracts\Bus\Dispatcher;
use Illuminate\Database\Eloquent\Collection;
use Illuminate\Http\Request;
use Illuminate\Support\Arr;
use Psr\Http\Message\ServerRequestInterface;
use Tobscure\JsonApi\Document;
class UpdateDiscussionController extends AbstractShowController
@@ -30,11 +30,11 @@ class UpdateDiscussionController extends AbstractShowController
) {
}
protected function data(ServerRequestInterface $request, Document $document): Discussion
protected function data(Request $request, Document $document): Discussion
{
$actor = RequestUtil::getActor($request);
$discussionId = (int) Arr::get($request->getQueryParams(), 'id');
$data = Arr::get($request->getParsedBody(), 'data', []);
$discussionId = (int) $request->query('id');
$data = $request->json()->all();
/** @var Discussion $discussion */
$discussion = $this->bus->dispatch(

View File

@@ -10,26 +10,24 @@
namespace Flarum\Api\Controller;
use Flarum\Extension\Command\ToggleExtension;
use Flarum\Http\Controller\AbstractController;
use Flarum\Http\RequestUtil;
use Illuminate\Contracts\Bus\Dispatcher;
use Illuminate\Support\Arr;
use Illuminate\Http\Request;
use Laminas\Diactoros\Response\EmptyResponse;
use Psr\Http\Message\ResponseInterface;
use Psr\Http\Message\ServerRequestInterface;
use Psr\Http\Server\RequestHandlerInterface;
class UpdateExtensionController implements RequestHandlerInterface
class UpdateExtensionController extends AbstractController
{
public function __construct(
protected Dispatcher $bus
) {
}
public function handle(ServerRequestInterface $request): ResponseInterface
public function __invoke(Request $request, string $name): ResponseInterface
{
$actor = RequestUtil::getActor($request);
$enabled = (bool) (int) Arr::get($request->getParsedBody(), 'enabled');
$name = Arr::get($request->getQueryParams(), 'name');
$enabled = (bool) (int) $request->json('enabled');
$this->bus->dispatch(
new ToggleExtension($actor, $name, $enabled)

View File

@@ -14,8 +14,8 @@ use Flarum\Group\Command\EditGroup;
use Flarum\Group\Group;
use Flarum\Http\RequestUtil;
use Illuminate\Contracts\Bus\Dispatcher;
use Illuminate\Http\Request;
use Illuminate\Support\Arr;
use Psr\Http\Message\ServerRequestInterface;
use Tobscure\JsonApi\Document;
class UpdateGroupController extends AbstractShowController
@@ -27,11 +27,11 @@ class UpdateGroupController extends AbstractShowController
) {
}
protected function data(ServerRequestInterface $request, Document $document): Group
protected function data(Request $request, Document $document): Group
{
$id = Arr::get($request->getQueryParams(), 'id');
$id = $request->query('id');
$actor = RequestUtil::getActor($request);
$data = Arr::get($request->getParsedBody(), 'data', []);
$data = $request->json()->all();
return $this->bus->dispatch(
new EditGroup($id, $actor, $data)

View File

@@ -14,8 +14,8 @@ use Flarum\Http\RequestUtil;
use Flarum\Notification\Command\ReadNotification;
use Flarum\Notification\Notification;
use Illuminate\Contracts\Bus\Dispatcher;
use Illuminate\Http\Request;
use Illuminate\Support\Arr;
use Psr\Http\Message\ServerRequestInterface;
use Tobscure\JsonApi\Document;
class UpdateNotificationController extends AbstractShowController
@@ -27,9 +27,9 @@ class UpdateNotificationController extends AbstractShowController
) {
}
protected function data(ServerRequestInterface $request, Document $document): Notification
protected function data(Request $request, Document $document): Notification
{
$id = Arr::get($request->getQueryParams(), 'id');
$id = $request->query('id');
$actor = RequestUtil::getActor($request);
return $this->bus->dispatch(

View File

@@ -14,8 +14,7 @@ use Flarum\Http\RequestUtil;
use Flarum\Post\Command\EditPost;
use Flarum\Post\Post;
use Illuminate\Contracts\Bus\Dispatcher;
use Illuminate\Support\Arr;
use Psr\Http\Message\ServerRequestInterface;
use Illuminate\Http\Request;
use Tobscure\JsonApi\Document;
class UpdatePostController extends AbstractShowController
@@ -32,11 +31,11 @@ class UpdatePostController extends AbstractShowController
) {
}
protected function data(ServerRequestInterface $request, Document $document): Post
protected function data(Request $request, Document $document): Post
{
$id = Arr::get($request->getQueryParams(), 'id');
$id = $request->query('id');
$actor = RequestUtil::getActor($request);
$data = Arr::get($request->getParsedBody(), 'data', []);
$data = $request->json()->all();
$post = $this->bus->dispatch(
new EditPost($id, $actor, $data)

View File

@@ -16,8 +16,8 @@ use Flarum\User\Command\EditUser;
use Flarum\User\Exception\NotAuthenticatedException;
use Flarum\User\User;
use Illuminate\Contracts\Bus\Dispatcher;
use Illuminate\Http\Request;
use Illuminate\Support\Arr;
use Psr\Http\Message\ServerRequestInterface;
use Tobscure\JsonApi\Document;
class UpdateUserController extends AbstractShowController
@@ -31,11 +31,11 @@ class UpdateUserController extends AbstractShowController
) {
}
protected function data(ServerRequestInterface $request, Document $document): User
protected function data(Request $request, Document $document): User
{
$id = Arr::get($request->getQueryParams(), 'id');
$id = $request->query('id');
$actor = RequestUtil::getActor($request);
$data = Arr::get($request->getParsedBody(), 'data', []);
$data = $request->json()->all();
if ($actor->id == $id) {
$this->serializer = CurrentUserSerializer::class;

View File

@@ -14,8 +14,8 @@ use Flarum\Http\RequestUtil;
use Flarum\User\Command\UploadAvatar;
use Flarum\User\User;
use Illuminate\Contracts\Bus\Dispatcher;
use Illuminate\Http\Request;
use Illuminate\Support\Arr;
use Psr\Http\Message\ServerRequestInterface;
use Tobscure\JsonApi\Document;
class UploadAvatarController extends AbstractShowController
@@ -27,11 +27,11 @@ class UploadAvatarController extends AbstractShowController
) {
}
protected function data(ServerRequestInterface $request, Document $document): User
protected function data(Request $request, Document $document): User
{
$id = Arr::get($request->getQueryParams(), 'id');
$id = $request->query('id');
$actor = RequestUtil::getActor($request);
$file = Arr::get($request->getUploadedFiles(), 'avatar');
$file = $request->file('avatar');
return $this->bus->dispatch(
new UploadAvatar($id, $file, $actor)

View File

@@ -13,10 +13,10 @@ use Flarum\Http\RequestUtil;
use Flarum\Settings\SettingsRepositoryInterface;
use Illuminate\Contracts\Filesystem\Factory;
use Illuminate\Contracts\Filesystem\Filesystem;
use Illuminate\Http\Request;
use Illuminate\Support\Arr;
use Illuminate\Support\Str;
use Intervention\Image\Image;
use Psr\Http\Message\ServerRequestInterface;
use Psr\Http\Message\UploadedFileInterface;
use Tobscure\JsonApi\Document;
@@ -34,7 +34,7 @@ abstract class UploadImageController extends ShowForumController
$this->uploadDir = $filesystemFactory->disk('flarum-assets');
}
public function data(ServerRequestInterface $request, Document $document): array
public function data(Request $request, Document $document): array
{
RequestUtil::getActor($request)->assertAdmin();

View File

@@ -9,7 +9,7 @@
namespace Flarum\Api;
use Laminas\Diactoros\Response\JsonResponse;
use Illuminate\Http\JsonResponse;
use Tobscure\JsonApi\Document;
class JsonApiResponse extends JsonResponse

View File

@@ -14,10 +14,10 @@ use DateTime;
use Flarum\Http\RequestUtil;
use Flarum\User\User;
use Illuminate\Contracts\Container\Container;
use Illuminate\Http\Request;
use Illuminate\Support\Arr;
use InvalidArgumentException;
use LogicException;
use Psr\Http\Message\ServerRequestInterface as Request;
use Tobscure\JsonApi\AbstractSerializer as BaseAbstractSerializer;
use Tobscure\JsonApi\Collection;
use Tobscure\JsonApi\Relationship;

View File

@@ -11,7 +11,7 @@ namespace Flarum\Formatter;
use Flarum\User\User;
use Illuminate\Contracts\Cache\Repository;
use Psr\Http\Message\ServerRequestInterface;
use Illuminate\Http\Request;
use s9e\TextFormatter\Configurator;
use s9e\TextFormatter\Parser;
use s9e\TextFormatter\Renderer;
@@ -81,7 +81,7 @@ class Formatter
return $parser->parse($text);
}
public function render(string $xml, mixed $context = null, ServerRequestInterface $request = null): string
public function render(string $xml, mixed $context = null, Request $request = null): string
{
$renderer = $this->getRenderer();

View File

@@ -11,7 +11,7 @@ namespace Flarum\Forum\Content;
use Flarum\Frontend\Document;
use Flarum\Http\RequestUtil;
use Psr\Http\Message\ServerRequestInterface as Request;
use Illuminate\Http\Request;
class AssertRegistered
{

View File

@@ -14,8 +14,8 @@ use Flarum\Frontend\Document;
use Flarum\Http\Exception\RouteNotFoundException;
use Flarum\Http\UrlGenerator;
use Illuminate\Contracts\View\Factory;
use Illuminate\Http\Request;
use Illuminate\Support\Arr;
use Psr\Http\Message\ServerRequestInterface as Request;
class Discussion
{
@@ -28,10 +28,9 @@ class Discussion
public function __invoke(Document $document, Request $request): Document
{
$queryParams = $request->getQueryParams();
$id = Arr::get($queryParams, 'id');
$near = intval(Arr::get($queryParams, 'near'));
$page = max(1, intval(Arr::get($queryParams, 'page')), 1 + intdiv($near, 20));
$id = $request->query('id');
$near = intval($request->query('near'));
$page = max(1, intval($request->query('page')), 1 + intdiv($near, 20));
$params = [
'id' => $id,
@@ -50,8 +49,8 @@ class Discussion
});
};
$url = function ($newQueryParams) use ($queryParams, $apiDocument) {
$newQueryParams = array_merge($queryParams, $newQueryParams);
$url = function ($newQueryParams) use ($request, $apiDocument) {
$newQueryParams = array_merge($request->query(), $newQueryParams);
unset($newQueryParams['id']);
unset($newQueryParams['near']);

View File

@@ -15,8 +15,7 @@ use Flarum\Http\UrlGenerator;
use Flarum\Locale\TranslatorInterface;
use Flarum\Settings\SettingsRepositoryInterface;
use Illuminate\Contracts\View\Factory;
use Illuminate\Support\Arr;
use Psr\Http\Message\ServerRequestInterface as Request;
use Illuminate\Http\Request;
class Index
{
@@ -31,12 +30,10 @@ class Index
public function __invoke(Document $document, Request $request): Document
{
$queryParams = $request->getQueryParams();
$sort = Arr::pull($queryParams, 'sort');
$q = Arr::pull($queryParams, 'q');
$page = max(1, intval(Arr::pull($queryParams, 'page')));
$filters = Arr::pull($queryParams, 'filter', []);
$sort = $request->query('sort');
$q = $request->query('q');
$page = max(1, intval($request->query('page')));
$filters = $request->query('filter', []);
$sortMap = resolve('flarum.forum.discussions.sortmap');

View File

@@ -13,8 +13,8 @@ use Flarum\Api\Client;
use Flarum\Frontend\Document;
use Flarum\Http\UrlGenerator;
use Illuminate\Database\Eloquent\ModelNotFoundException;
use Illuminate\Http\Request;
use Illuminate\Support\Arr;
use Psr\Http\Message\ServerRequestInterface as Request;
class User
{
@@ -26,8 +26,7 @@ class User
public function __invoke(Document $document, Request $request): Document
{
$queryParams = $request->getQueryParams();
$username = Arr::get($queryParams, 'username');
$username = $request->query('username');
$apiDocument = $this->getApiDocument($request, $username);
$user = $apiDocument->data->attributes;
@@ -53,6 +52,6 @@ class User
throw new ModelNotFoundException;
}
return json_decode($response->getBody());
return json_decode($response->content());
}
}

View File

@@ -9,18 +9,17 @@
namespace Flarum\Forum\Controller;
use Flarum\Http\Controller\AbstractController;
use Flarum\Http\SessionAccessToken;
use Flarum\Http\SessionAuthenticator;
use Flarum\Http\UrlGenerator;
use Flarum\User\Command\ConfirmEmail;
use Illuminate\Contracts\Bus\Dispatcher;
use Illuminate\Support\Arr;
use Illuminate\Http\Request;
use Laminas\Diactoros\Response\RedirectResponse;
use Psr\Http\Message\ResponseInterface;
use Psr\Http\Message\ServerRequestInterface as Request;
use Psr\Http\Server\RequestHandlerInterface;
class ConfirmEmailController implements RequestHandlerInterface
class ConfirmEmailController extends AbstractController
{
public function __construct(
protected Dispatcher $bus,
@@ -29,15 +28,15 @@ class ConfirmEmailController implements RequestHandlerInterface
) {
}
public function handle(Request $request): ResponseInterface
public function __invoke(Request $request): ResponseInterface
{
$token = Arr::get($request->getQueryParams(), 'token');
$token = $request->query('token');
$user = $this->bus->dispatch(
new ConfirmEmail($token)
);
$session = $request->getAttribute('session');
$session = $request->attributes->get('session');
$token = SessionAccessToken::generate($user->id);
$this->authenticator->logIn($session, $token);

View File

@@ -13,8 +13,7 @@ use Flarum\Http\Controller\AbstractHtmlController;
use Flarum\User\EmailToken;
use Illuminate\Contracts\View\Factory;
use Illuminate\Contracts\View\View;
use Illuminate\Support\Arr;
use Psr\Http\Message\ServerRequestInterface as Request;
use Illuminate\Http\Request;
class ConfirmEmailViewController extends AbstractHtmlController
{
@@ -25,12 +24,12 @@ class ConfirmEmailViewController extends AbstractHtmlController
public function render(Request $request): View
{
$token = Arr::get($request->getQueryParams(), 'token');
$token = $request->query('token');
EmailToken::validOrFail($token);
return $this->view
->make('flarum.forum::confirm-email')
->with('csrfToken', $request->getAttribute('session')->token());
->with('csrfToken', $request->attributes->get('session')->token());
}
}

View File

@@ -9,18 +9,17 @@
namespace Flarum\Forum\Controller;
use Flarum\Http\Controller\AbstractController;
use Flarum\Http\Rememberer;
use Flarum\Http\RequestUtil;
use Flarum\Http\SessionAuthenticator;
use Flarum\Http\UrlGenerator;
use Flarum\User\Event\LoggedOut;
use Illuminate\Contracts\Events\Dispatcher;
use Laminas\Diactoros\Response\EmptyResponse;
use Psr\Http\Message\ResponseInterface;
use Psr\Http\Message\ServerRequestInterface as Request;
use Psr\Http\Server\RequestHandlerInterface;
use Illuminate\Http\Request;
use Symfony\Component\HttpFoundation\Response;
class GlobalLogOutController implements RequestHandlerInterface
class GlobalLogOutController extends AbstractController
{
public function __construct(
protected Dispatcher $events,
@@ -30,9 +29,9 @@ class GlobalLogOutController implements RequestHandlerInterface
) {
}
public function handle(Request $request): ResponseInterface
public function __invoke(Request $request): Response
{
$session = $request->getAttribute('session');
$session = $request->attributes->get('session');
$actor = RequestUtil::getActor($request);
$actor->assertRegistered();
@@ -45,6 +44,6 @@ class GlobalLogOutController implements RequestHandlerInterface
$this->events->dispatch(new LoggedOut($actor, true));
return $this->rememberer->forget(new EmptyResponse());
return $this->rememberer->forget(new Response(null, 204));
}
}

View File

@@ -12,18 +12,18 @@ namespace Flarum\Forum\Controller;
use Flarum\Api\Client;
use Flarum\Forum\LogInValidator;
use Flarum\Http\AccessToken;
use Flarum\Http\Controller\AbstractController;
use Flarum\Http\RememberAccessToken;
use Flarum\Http\Rememberer;
use Flarum\Http\SessionAuthenticator;
use Flarum\User\Event\LoggedIn;
use Flarum\User\UserRepository;
use Illuminate\Contracts\Events\Dispatcher;
use Illuminate\Http\Request;
use Illuminate\Support\Arr;
use Psr\Http\Message\ResponseInterface;
use Psr\Http\Message\ServerRequestInterface as Request;
use Psr\Http\Server\RequestHandlerInterface;
use Symfony\Component\HttpFoundation\Response;
class LogInController implements RequestHandlerInterface
class LogInController extends AbstractController
{
public function __construct(
protected UserRepository $users,
@@ -35,9 +35,9 @@ class LogInController implements RequestHandlerInterface
) {
}
public function handle(Request $request): ResponseInterface
public function __invoke(Request $request): Response
{
$body = $request->getParsedBody();
$body = $request->json()->all();
$params = Arr::only($body, ['identification', 'password', 'remember']);
$this->validator->assertValid($body);
@@ -49,7 +49,7 @@ class LogInController implements RequestHandlerInterface
$token = AccessToken::findValid($data->token);
$session = $request->getAttribute('session');
$session = $request->attributes->get('session');
$this->authenticator->logIn($session, $token);
$this->events->dispatch(new LoggedIn($this->users->findOrFail($data->userId), $token));

View File

@@ -9,6 +9,7 @@
namespace Flarum\Forum\Controller;
use Flarum\Http\Controller\AbstractController;
use Flarum\Http\Rememberer;
use Flarum\Http\RequestUtil;
use Flarum\Http\SessionAuthenticator;
@@ -16,14 +17,13 @@ use Flarum\Http\UrlGenerator;
use Flarum\User\Event\LoggedOut;
use Illuminate\Contracts\Events\Dispatcher;
use Illuminate\Contracts\View\Factory;
use Illuminate\Support\Arr;
use Illuminate\Http\Request;
use Laminas\Diactoros\Response\HtmlResponse;
use Laminas\Diactoros\Response\RedirectResponse;
use Psr\Http\Message\ResponseInterface;
use Psr\Http\Message\ServerRequestInterface as Request;
use Psr\Http\Server\RequestHandlerInterface;
use Symfony\Component\HttpFoundation\RedirectResponse;
use Symfony\Component\HttpFoundation\Response;
class LogOutController implements RequestHandlerInterface
class LogOutController extends AbstractController
{
public function __construct(
protected Dispatcher $events,
@@ -34,12 +34,12 @@ class LogOutController implements RequestHandlerInterface
) {
}
public function handle(Request $request): ResponseInterface
public function __invoke(Request $request): Response|ResponseInterface
{
$session = $request->getAttribute('session');
$session = $request->attributes->get('session');
$actor = RequestUtil::getActor($request);
$url = Arr::get($request->getQueryParams(), 'return', $this->url->to('forum')->base());
$url = $request->query('return', $this->url->to('forum')->base());
// If there is no user logged in, return to the index.
if ($actor->isGuest()) {
@@ -50,8 +50,8 @@ class LogOutController implements RequestHandlerInterface
// allow the user to press a button to complete the log out process.
$csrfToken = $session->token();
if (Arr::get($request->getQueryParams(), 'token') !== $csrfToken) {
$return = Arr::get($request->getQueryParams(), 'return');
if ($request->query('token') !== $csrfToken) {
$return = $request->query('return');
$view = $this->view->make('flarum.forum::log-out')
->with('url', $this->url->to('forum')->route('logout').'?token='.$csrfToken.($return ? '&return='.urlencode($return) : ''));

View File

@@ -10,14 +10,14 @@
namespace Flarum\Forum\Controller;
use Flarum\Api\Client;
use Flarum\Http\Controller\AbstractController;
use Flarum\Http\RememberAccessToken;
use Flarum\Http\Rememberer;
use Flarum\Http\SessionAuthenticator;
use Psr\Http\Message\ResponseInterface;
use Psr\Http\Message\ServerRequestInterface as Request;
use Psr\Http\Server\RequestHandlerInterface;
use Illuminate\Http\Request;
use Symfony\Component\HttpFoundation\Response;
class RegisterController implements RequestHandlerInterface
class RegisterController extends AbstractController
{
public function __construct(
protected Client $api,
@@ -26,9 +26,9 @@ class RegisterController implements RequestHandlerInterface
) {
}
public function handle(Request $request): ResponseInterface
public function __invoke(Request $request): Response
{
$params = ['data' => ['attributes' => $request->getParsedBody()]];
$params = ['data' => ['attributes' => $request->json()->all()]];
$response = $this->api->withParentRequest($request)->withBody($params)->post('/users');
@@ -39,7 +39,7 @@ class RegisterController implements RequestHandlerInterface
$token = RememberAccessToken::generate($userId);
$session = $request->getAttribute('session');
$session = $request->attributes->get('session');
$this->authenticator->logIn($session, $token);
$response = $this->rememberer->remember($response, $token);

View File

@@ -15,8 +15,7 @@ use Flarum\User\Exception\InvalidConfirmationTokenException;
use Flarum\User\PasswordToken;
use Illuminate\Contracts\View\Factory;
use Illuminate\Contracts\View\View;
use Illuminate\Support\Arr;
use Psr\Http\Message\ServerRequestInterface as Request;
use Illuminate\Http\Request;
class ResetPasswordController extends AbstractHtmlController
{
@@ -27,7 +26,7 @@ class ResetPasswordController extends AbstractHtmlController
public function render(Request $request): View
{
$token = Arr::get($request->getQueryParams(), 'token');
$token = $request->query('token');
$token = PasswordToken::findOrFail($token);
@@ -38,6 +37,6 @@ class ResetPasswordController extends AbstractHtmlController
return $this->view
->make('flarum.forum::reset-password')
->with('passwordToken', $token->token)
->with('csrfToken', $request->getAttribute('session')->token());
->with('csrfToken', $request->attributes->get('session')->token());
}
}

Some files were not shown because too many files have changed in this diff Show More