From a60e3d174fb1534a5219bec8fd21b51135e96c63 Mon Sep 17 00:00:00 2001 From: Sami Mazouz Date: Fri, 11 Aug 2023 14:17:54 +0100 Subject: [PATCH] chore: replace `SeverRequestInterface` with laravel `Request` in controllers --- composer.json | 5 +- extensions/embed/extend.php | 2 +- .../Api/Controller/CreateFlagController.php | 4 +- .../Api/Controller/DeleteFlagsController.php | 6 +- .../Api/Controller/ListFlagsController.php | 4 +- extensions/flags/src/PrepareFlagsApiData.php | 4 +- .../likes/src/Api/LoadLikesRelationship.php | 4 +- .../src/Api/LoadMentionedByRelationship.php | 6 +- .../src/Formatter/FormatPostMentions.php | 2 +- .../src/Formatter/FormatTagMentions.php | 2 +- .../Controller/CheckForUpdatesController.php | 8 +-- .../Api/Controller/GlobalUpdateController.php | 8 +-- .../Api/Controller/ListTasksController.php | 6 +- .../Api/Controller/MajorUpdateController.php | 11 ++-- .../Api/Controller/MinorUpdateController.php | 8 +-- .../Controller/RemoveExtensionController.php | 11 ++-- .../Controller/RequireExtensionController.php | 11 ++-- .../Controller/UpdateExtensionController.php | 12 ++-- .../src/Api/Controller/WhyNotController.php | 12 ++-- .../src/Api/Controller/AuthController.php | 14 ++--- .../src/Api/Controller/ShowStatisticsData.php | 16 +++--- extensions/tags/extend.php | 6 +- .../Api/Controller/CreateTagController.php | 7 +-- .../Api/Controller/DeleteTagController.php | 7 +-- .../src/Api/Controller/ListTagsController.php | 6 +- .../Api/Controller/OrderTagsController.php | 12 ++-- .../src/Api/Controller/ShowTagController.php | 7 +-- .../Api/Controller/UpdateTagController.php | 9 ++- extensions/tags/src/Content/Tag.php | 18 +++--- extensions/tags/src/Content/Tags.php | 6 +- .../tags/src/LoadForumTagsRelationship.php | 4 +- framework/core/composer.json | 4 +- .../core/src/Admin/Content/AdminPayload.php | 2 +- framework/core/src/Admin/Content/Index.php | 4 +- .../Controller/UpdateExtensionController.php | 15 ++--- framework/core/src/Api/Client.php | 57 ++++++++++++------- .../Controller/AbstractCreateController.php | 8 +-- .../Controller/AbstractDeleteController.php | 10 ++-- .../Api/Controller/AbstractListController.php | 4 +- .../AbstractSerializeController.php | 35 ++++++------ .../Api/Controller/AbstractShowController.php | 3 +- .../Api/Controller/ClearCacheController.php | 4 +- .../CreateAccessTokenController.php | 4 +- .../Controller/CreateDiscussionController.php | 4 +- .../Api/Controller/CreateGroupController.php | 4 +- .../Api/Controller/CreatePostController.php | 4 +- .../Api/Controller/CreateTokenController.php | 20 +++---- .../Api/Controller/CreateUserController.php | 4 +- .../DeleteAccessTokenController.php | 6 +- .../DeleteAllNotificationsController.php | 4 +- .../Api/Controller/DeleteAvatarController.php | 7 +-- .../Controller/DeleteDiscussionController.php | 8 +-- .../Controller/DeleteFaviconController.php | 4 +- .../Api/Controller/DeleteGroupController.php | 7 +-- .../Api/Controller/DeleteLogoController.php | 4 +- .../Api/Controller/DeletePostController.php | 7 +-- .../Api/Controller/DeleteUserController.php | 7 +-- .../Controller/ForgotPasswordController.php | 17 +++--- .../Controller/ListAccessTokensController.php | 6 +- .../Controller/ListDiscussionsController.php | 6 +- .../Api/Controller/ListGroupsController.php | 6 +- .../ListNotificationsController.php | 6 +- .../Api/Controller/ListPostsController.php | 13 ++--- .../Api/Controller/ListUsersController.php | 6 +- .../ReadAllNotificationsController.php | 4 +- .../SendConfirmationEmailController.php | 10 ++-- .../Api/Controller/SendTestMailController.php | 8 +-- .../Controller/SetPermissionController.php | 13 ++--- .../Api/Controller/SetSettingsController.php | 12 ++-- .../Controller/ShowDiscussionController.php | 18 +++--- .../ShowExtensionReadmeController.php | 6 +- .../Api/Controller/ShowForumController.php | 4 +- .../Api/Controller/ShowGroupController.php | 7 +-- .../Controller/ShowMailSettingsController.php | 4 +- .../src/Api/Controller/ShowPostController.php | 7 +-- .../src/Api/Controller/ShowUserController.php | 9 ++- .../TerminateAllOtherSessionsController.php | 4 +- .../UninstallExtensionController.php | 6 +- .../Controller/UpdateDiscussionController.php | 8 +-- .../Controller/UpdateExtensionController.php | 12 ++-- .../Api/Controller/UpdateGroupController.php | 8 +-- .../UpdateNotificationController.php | 6 +- .../Api/Controller/UpdatePostController.php | 9 ++- .../Api/Controller/UpdateUserController.php | 8 +-- .../Api/Controller/UploadAvatarController.php | 8 +-- .../Api/Controller/UploadImageController.php | 4 +- framework/core/src/Api/JsonApiResponse.php | 2 +- .../src/Api/Serializer/AbstractSerializer.php | 2 +- framework/core/src/Formatter/Formatter.php | 4 +- .../src/Forum/Content/AssertRegistered.php | 2 +- .../core/src/Forum/Content/Discussion.php | 13 ++--- framework/core/src/Forum/Content/Index.php | 13 ++--- framework/core/src/Forum/Content/User.php | 7 +-- .../Controller/ConfirmEmailController.php | 13 ++--- .../Controller/ConfirmEmailViewController.php | 7 +-- .../Controller/GlobalLogOutController.php | 15 +++-- .../src/Forum/Controller/LogInController.php | 14 ++--- .../src/Forum/Controller/LogOutController.php | 20 +++---- .../Forum/Controller/RegisterController.php | 14 ++--- .../Controller/ResetPasswordController.php | 7 +-- .../Controller/SavePasswordController.php | 14 ++--- .../core/src/Frontend/Content/Assets.php | 4 +- .../core/src/Frontend/Content/CorePayload.php | 6 +- framework/core/src/Frontend/Content/Meta.php | 2 +- framework/core/src/Frontend/Controller.php | 14 ++--- framework/core/src/Frontend/Document.php | 2 +- .../src/Frontend/Driver/BasicTitleDriver.php | 6 +- .../Frontend/Driver/TitleDriverInterface.php | 4 +- framework/core/src/Frontend/Frontend.php | 6 +- .../Http/Controller/AbstractController.php | 10 ++++ .../Controller/AbstractHtmlController.php | 7 +-- .../Install/Controller/IndexController.php | 2 +- .../Install/Controller/InstallController.php | 24 ++++---- framework/core/src/Install/Installer.php | 23 +++----- framework/core/src/Post/CommentPost.php | 4 +- .../core/src/Post/PostCreationThrottler.php | 6 +- .../src/Update/Controller/IndexController.php | 2 +- .../Update/Controller/UpdateController.php | 13 ++--- .../Throttler/EmailActivationThrottler.php | 6 +- .../User/Throttler/EmailChangeThrottler.php | 9 ++- .../User/Throttler/PasswordResetThrottler.php | 9 ++- .../api/AbstractSerializeControllerTest.php | 3 +- .../extenders/FrontendTitleTest.php | 3 +- 123 files changed, 497 insertions(+), 528 deletions(-) create mode 100644 framework/core/src/Http/Controller/AbstractController.php diff --git a/composer.json b/composer.json index c0e0b2511..3449fe13c 100644 --- a/composer.json +++ b/composer.json @@ -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" diff --git a/extensions/embed/extend.php b/extensions/embed/extend.php index a69a68cba..2b33ecbf8 100644 --- a/extensions/embed/extend.php +++ b/extensions/embed/extend.php @@ -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')) diff --git a/extensions/flags/src/Api/Controller/CreateFlagController.php b/extensions/flags/src/Api/Controller/CreateFlagController.php index 7d5b5c376..32ffc905f 100644 --- a/extensions/flags/src/Api/Controller/CreateFlagController.php +++ b/extensions/flags/src/Api/Controller/CreateFlagController.php @@ -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', [])) diff --git a/extensions/flags/src/Api/Controller/DeleteFlagsController.php b/extensions/flags/src/Api/Controller/DeleteFlagsController.php index 6253cae04..00125f571 100644 --- a/extensions/flags/src/Api/Controller/DeleteFlagsController.php +++ b/extensions/flags/src/Api/Controller/DeleteFlagsController.php @@ -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()) ); } } diff --git a/extensions/flags/src/Api/Controller/ListFlagsController.php b/extensions/flags/src/Api/Controller/ListFlagsController.php index 216f61b05..796b248ce 100644 --- a/extensions/flags/src/Api/Controller/ListFlagsController.php +++ b/extensions/flags/src/Api/Controller/ListFlagsController.php @@ -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); diff --git a/extensions/flags/src/PrepareFlagsApiData.php b/extensions/flags/src/PrepareFlagsApiData.php index 4442255d2..6c97b29d7 100755 --- a/extensions/flags/src/PrepareFlagsApiData.php +++ b/extensions/flags/src/PrepareFlagsApiData.php @@ -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 diff --git a/extensions/likes/src/Api/LoadLikesRelationship.php b/extensions/likes/src/Api/LoadLikesRelationship.php index 4f9b62619..4c7f9cd7d 100644 --- a/extensions/likes/src/Api/LoadLikesRelationship.php +++ b/extensions/likes/src/Api/LoadLikesRelationship.php @@ -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); diff --git a/extensions/mentions/src/Api/LoadMentionedByRelationship.php b/extensions/mentions/src/Api/LoadMentionedByRelationship.php index 47bceafb7..b11c7eea3 100644 --- a/extensions/mentions/src/Api/LoadMentionedByRelationship.php +++ b/extensions/mentions/src/Api/LoadMentionedByRelationship.php @@ -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; diff --git a/extensions/mentions/src/Formatter/FormatPostMentions.php b/extensions/mentions/src/Formatter/FormatPostMentions.php index 992dca150..9542d1778 100644 --- a/extensions/mentions/src/Formatter/FormatPostMentions.php +++ b/extensions/mentions/src/Formatter/FormatPostMentions.php @@ -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; diff --git a/extensions/mentions/src/Formatter/FormatTagMentions.php b/extensions/mentions/src/Formatter/FormatTagMentions.php index b867969ca..e5a121ab3 100644 --- a/extensions/mentions/src/Formatter/FormatTagMentions.php +++ b/extensions/mentions/src/Formatter/FormatTagMentions.php @@ -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; diff --git a/extensions/package-manager/src/Api/Controller/CheckForUpdatesController.php b/extensions/package-manager/src/Api/Controller/CheckForUpdatesController.php index 04a0d97c0..eff7ebe8a 100755 --- a/extensions/package-manager/src/Api/Controller/CheckForUpdatesController.php +++ b/extensions/package-manager/src/Api/Controller/CheckForUpdatesController.php @@ -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); diff --git a/extensions/package-manager/src/Api/Controller/GlobalUpdateController.php b/extensions/package-manager/src/Api/Controller/GlobalUpdateController.php index 2bd9793d0..a8317a391 100755 --- a/extensions/package-manager/src/Api/Controller/GlobalUpdateController.php +++ b/extensions/package-manager/src/Api/Controller/GlobalUpdateController.php @@ -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); diff --git a/extensions/package-manager/src/Api/Controller/ListTasksController.php b/extensions/package-manager/src/Api/Controller/ListTasksController.php index 804bd3a58..3a32e762b 100644 --- a/extensions/package-manager/src/Api/Controller/ListTasksController.php +++ b/extensions/package-manager/src/Api/Controller/ListTasksController.php @@ -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 diff --git a/extensions/package-manager/src/Api/Controller/MajorUpdateController.php b/extensions/package-manager/src/Api/Controller/MajorUpdateController.php index d2e41526b..f278ed52f 100755 --- a/extensions/package-manager/src/Api/Controller/MajorUpdateController.php +++ b/extensions/package-manager/src/Api/Controller/MajorUpdateController.php @@ -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) diff --git a/extensions/package-manager/src/Api/Controller/MinorUpdateController.php b/extensions/package-manager/src/Api/Controller/MinorUpdateController.php index f2aeee206..6634d910a 100755 --- a/extensions/package-manager/src/Api/Controller/MinorUpdateController.php +++ b/extensions/package-manager/src/Api/Controller/MinorUpdateController.php @@ -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); diff --git a/extensions/package-manager/src/Api/Controller/RemoveExtensionController.php b/extensions/package-manager/src/Api/Controller/RemoveExtensionController.php index de760a194..c96864c2d 100755 --- a/extensions/package-manager/src/Api/Controller/RemoveExtensionController.php +++ b/extensions/package-manager/src/Api/Controller/RemoveExtensionController.php @@ -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 diff --git a/extensions/package-manager/src/Api/Controller/RequireExtensionController.php b/extensions/package-manager/src/Api/Controller/RequireExtensionController.php index 5f05938db..a390ad989 100755 --- a/extensions/package-manager/src/Api/Controller/RequireExtensionController.php +++ b/extensions/package-manager/src/Api/Controller/RequireExtensionController.php @@ -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) diff --git a/extensions/package-manager/src/Api/Controller/UpdateExtensionController.php b/extensions/package-manager/src/Api/Controller/UpdateExtensionController.php index 6b59dd2de..dc64851d9 100755 --- a/extensions/package-manager/src/Api/Controller/UpdateExtensionController.php +++ b/extensions/package-manager/src/Api/Controller/UpdateExtensionController.php @@ -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 diff --git a/extensions/package-manager/src/Api/Controller/WhyNotController.php b/extensions/package-manager/src/Api/Controller/WhyNotController.php index 6ca94dc56..42abe50a0 100755 --- a/extensions/package-manager/src/Api/Controller/WhyNotController.php +++ b/extensions/package-manager/src/Api/Controller/WhyNotController.php @@ -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) diff --git a/extensions/pusher/src/Api/Controller/AuthController.php b/extensions/pusher/src/Api/Controller/AuthController.php index ce1432a50..6b7729cbb 100644 --- a/extensions/pusher/src/Api/Controller/AuthController.php +++ b/extensions/pusher/src/Api/Controller/AuthController.php @@ -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); } diff --git a/extensions/statistics/src/Api/Controller/ShowStatisticsData.php b/extensions/statistics/src/Api/Controller/ShowStatisticsData.php index 9319a6d1b..978fa8e12 100644 --- a/extensions/statistics/src/Api/Controller/ShowStatisticsData.php +++ b/extensions/statistics/src/Api/Controller/ShowStatisticsData.php @@ -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)); } diff --git a/extensions/tags/extend.php b/extensions/tags/extend.php index a216c68d9..fb5732a7f 100644 --- a/extensions/tags/extend.php +++ b/extensions/tags/extend.php @@ -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); diff --git a/extensions/tags/src/Api/Controller/CreateTagController.php b/extensions/tags/src/Api/Controller/CreateTagController.php index 7a5fcd6f7..3d2bcfca3 100644 --- a/extensions/tags/src/Api/Controller/CreateTagController.php +++ b/extensions/tags/src/Api/Controller/CreateTagController.php @@ -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', [])) ); } } diff --git a/extensions/tags/src/Api/Controller/DeleteTagController.php b/extensions/tags/src/Api/Controller/DeleteTagController.php index db75abeb8..0779c624e 100644 --- a/extensions/tags/src/Api/Controller/DeleteTagController.php +++ b/extensions/tags/src/Api/Controller/DeleteTagController.php @@ -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)) ); } } diff --git a/extensions/tags/src/Api/Controller/ListTagsController.php b/extensions/tags/src/Api/Controller/ListTagsController.php index 85400f3c5..7cbb53e68 100644 --- a/extensions/tags/src/Api/Controller/ListTagsController.php +++ b/extensions/tags/src/Api/Controller/ListTagsController.php @@ -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 diff --git a/extensions/tags/src/Api/Controller/OrderTagsController.php b/extensions/tags/src/Api/Controller/OrderTagsController.php index 9cb4e125e..caa3b0c6f 100644 --- a/extensions/tags/src/Api/Controller/OrderTagsController.php +++ b/extensions/tags/src/Api/Controller/OrderTagsController.php @@ -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) { diff --git a/extensions/tags/src/Api/Controller/ShowTagController.php b/extensions/tags/src/Api/Controller/ShowTagController.php index ae34d51de..5ac388493 100644 --- a/extensions/tags/src/Api/Controller/ShowTagController.php +++ b/extensions/tags/src/Api/Controller/ShowTagController.php @@ -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; diff --git a/extensions/tags/src/Api/Controller/UpdateTagController.php b/extensions/tags/src/Api/Controller/UpdateTagController.php index 2f5776446..40cf62a16 100644 --- a/extensions/tags/src/Api/Controller/UpdateTagController.php +++ b/extensions/tags/src/Api/Controller/UpdateTagController.php @@ -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) diff --git a/extensions/tags/src/Content/Tag.php b/extensions/tags/src/Content/Tag.php index 01804fc90..74b94ac88 100644 --- a/extensions/tags/src/Content/Tag.php +++ b/extensions/tags/src/Content/Tag.php @@ -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()); } } diff --git a/extensions/tags/src/Content/Tags.php b/extensions/tags/src/Content/Tags.php index b17c5da0b..3b737b3f5 100644 --- a/extensions/tags/src/Content/Tags.php +++ b/extensions/tags/src/Content/Tags.php @@ -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); } } diff --git a/extensions/tags/src/LoadForumTagsRelationship.php b/extensions/tags/src/LoadForumTagsRelationship.php index e0d8c7453..874205770 100755 --- a/extensions/tags/src/LoadForumTagsRelationship.php +++ b/extensions/tags/src/LoadForumTagsRelationship.php @@ -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); diff --git a/framework/core/composer.json b/framework/core/composer.json index 3ffaf15b9..c5ac8fac0 100644 --- a/framework/core/composer.json +++ b/framework/core/composer.json @@ -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", diff --git a/framework/core/src/Admin/Content/AdminPayload.php b/framework/core/src/Admin/Content/AdminPayload.php index d2e8af468..203befa72 100644 --- a/framework/core/src/Admin/Content/AdminPayload.php +++ b/framework/core/src/Admin/Content/AdminPayload.php @@ -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 { diff --git a/framework/core/src/Admin/Content/Index.php b/framework/core/src/Admin/Content/Index.php index b70466fb5..960f42c37 100644 --- a/framework/core/src/Admin/Content/Index.php +++ b/framework/core/src/Admin/Content/Index.php @@ -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']; diff --git a/framework/core/src/Admin/Controller/UpdateExtensionController.php b/framework/core/src/Admin/Controller/UpdateExtensionController.php index 1d93705b6..1578566ef 100644 --- a/framework/core/src/Admin/Controller/UpdateExtensionController.php +++ b/framework/core/src/Admin/Controller/UpdateExtensionController.php @@ -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) diff --git a/framework/core/src/Api/Client.php b/framework/core/src/Api/Client.php index 3ef24084d..73d03c172 100644 --- a/framework/core/src/Api/Client.php +++ b/framework/core/src/Api/Client.php @@ -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); + }); } } diff --git a/framework/core/src/Api/Controller/AbstractCreateController.php b/framework/core/src/Api/Controller/AbstractCreateController.php index 00b9c774b..715c5d17a 100644 --- a/framework/core/src/Api/Controller/AbstractCreateController.php +++ b/framework/core/src/Api/Controller/AbstractCreateController.php @@ -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); } } diff --git a/framework/core/src/Api/Controller/AbstractDeleteController.php b/framework/core/src/Api/Controller/AbstractDeleteController.php index b2702c79a..5add710dd 100644 --- a/framework/core/src/Api/Controller/AbstractDeleteController.php +++ b/framework/core/src/Api/Controller/AbstractDeleteController.php @@ -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; } diff --git a/framework/core/src/Api/Controller/AbstractListController.php b/framework/core/src/Api/Controller/AbstractListController.php index ac4fd8753..3f92afd2c 100644 --- a/framework/core/src/Api/Controller/AbstractListController.php +++ b/framework/core/src/Api/Controller/AbstractListController.php @@ -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; } diff --git a/framework/core/src/Api/Controller/AbstractSerializeController.php b/framework/core/src/Api/Controller/AbstractSerializeController.php index 2c65d74f0..9f8dd65d5 100644 --- a/framework/core/src/Api/Controller/AbstractSerializeController.php +++ b/framework/core/src/Api/Controller/AbstractSerializeController.php @@ -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'); } /** diff --git a/framework/core/src/Api/Controller/AbstractShowController.php b/framework/core/src/Api/Controller/AbstractShowController.php index b87b5c594..c683dba76 100644 --- a/framework/core/src/Api/Controller/AbstractShowController.php +++ b/framework/core/src/Api/Controller/AbstractShowController.php @@ -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); } diff --git a/framework/core/src/Api/Controller/ClearCacheController.php b/framework/core/src/Api/Controller/ClearCacheController.php index 24352d1cb..a44072e16 100644 --- a/framework/core/src/Api/Controller/ClearCacheController.php +++ b/framework/core/src/Api/Controller/ClearCacheController.php @@ -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(); diff --git a/framework/core/src/Api/Controller/CreateAccessTokenController.php b/framework/core/src/Api/Controller/CreateAccessTokenController.php index 4917d6bff..750edb4b2 100644 --- a/framework/core/src/Api/Controller/CreateAccessTokenController.php +++ b/framework/core/src/Api/Controller/CreateAccessTokenController.php @@ -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); diff --git a/framework/core/src/Api/Controller/CreateDiscussionController.php b/framework/core/src/Api/Controller/CreateDiscussionController.php index fe5a28ee6..32dff97d9 100644 --- a/framework/core/src/Api/Controller/CreateDiscussionController.php +++ b/framework/core/src/Api/Controller/CreateDiscussionController.php @@ -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'); diff --git a/framework/core/src/Api/Controller/CreateGroupController.php b/framework/core/src/Api/Controller/CreateGroupController.php index 1d8ff85f3..a64d248bf 100644 --- a/framework/core/src/Api/Controller/CreateGroupController.php +++ b/framework/core/src/Api/Controller/CreateGroupController.php @@ -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', [])) diff --git a/framework/core/src/Api/Controller/CreatePostController.php b/framework/core/src/Api/Controller/CreatePostController.php index 717b5ab4d..ef457b3af 100644 --- a/framework/core/src/Api/Controller/CreatePostController.php +++ b/framework/core/src/Api/Controller/CreatePostController.php @@ -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', []); diff --git a/framework/core/src/Api/Controller/CreateTokenController.php b/framework/core/src/Api/Controller/CreateTokenController.php index 5d64d972d..0677c2347 100644 --- a/framework/core/src/Api/Controller/CreateTokenController.php +++ b/framework/core/src/Api/Controller/CreateTokenController.php @@ -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); diff --git a/framework/core/src/Api/Controller/CreateUserController.php b/framework/core/src/Api/Controller/CreateUserController.php index 03c091607..5812441dc 100644 --- a/framework/core/src/Api/Controller/CreateUserController.php +++ b/framework/core/src/Api/Controller/CreateUserController.php @@ -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', [])) diff --git a/framework/core/src/Api/Controller/DeleteAccessTokenController.php b/framework/core/src/Api/Controller/DeleteAccessTokenController.php index af2b224ec..152b08bae 100644 --- a/framework/core/src/Api/Controller/DeleteAccessTokenController.php +++ b/framework/core/src/Api/Controller/DeleteAccessTokenController.php @@ -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(); diff --git a/framework/core/src/Api/Controller/DeleteAllNotificationsController.php b/framework/core/src/Api/Controller/DeleteAllNotificationsController.php index 33f7620fe..9d3b594aa 100644 --- a/framework/core/src/Api/Controller/DeleteAllNotificationsController.php +++ b/framework/core/src/Api/Controller/DeleteAllNotificationsController.php @@ -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)) diff --git a/framework/core/src/Api/Controller/DeleteAvatarController.php b/framework/core/src/Api/Controller/DeleteAvatarController.php index 33baf6348..7c50060d2 100644 --- a/framework/core/src/Api/Controller/DeleteAvatarController.php +++ b/framework/core/src/Api/Controller/DeleteAvatarController.php @@ -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)) ); } } diff --git a/framework/core/src/Api/Controller/DeleteDiscussionController.php b/framework/core/src/Api/Controller/DeleteDiscussionController.php index 99319e4bd..605d3680a 100644 --- a/framework/core/src/Api/Controller/DeleteDiscussionController.php +++ b/framework/core/src/Api/Controller/DeleteDiscussionController.php @@ -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) diff --git a/framework/core/src/Api/Controller/DeleteFaviconController.php b/framework/core/src/Api/Controller/DeleteFaviconController.php index 3c7374d4b..bed804a71 100644 --- a/framework/core/src/Api/Controller/DeleteFaviconController.php +++ b/framework/core/src/Api/Controller/DeleteFaviconController.php @@ -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(); diff --git a/framework/core/src/Api/Controller/DeleteGroupController.php b/framework/core/src/Api/Controller/DeleteGroupController.php index 4acc0afea..1c6f0d538 100644 --- a/framework/core/src/Api/Controller/DeleteGroupController.php +++ b/framework/core/src/Api/Controller/DeleteGroupController.php @@ -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)) ); } } diff --git a/framework/core/src/Api/Controller/DeleteLogoController.php b/framework/core/src/Api/Controller/DeleteLogoController.php index 8485f3219..c7117fb0a 100644 --- a/framework/core/src/Api/Controller/DeleteLogoController.php +++ b/framework/core/src/Api/Controller/DeleteLogoController.php @@ -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(); diff --git a/framework/core/src/Api/Controller/DeletePostController.php b/framework/core/src/Api/Controller/DeletePostController.php index 3e61c55f8..1f4c1d3c9 100644 --- a/framework/core/src/Api/Controller/DeletePostController.php +++ b/framework/core/src/Api/Controller/DeletePostController.php @@ -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)) ); } } diff --git a/framework/core/src/Api/Controller/DeleteUserController.php b/framework/core/src/Api/Controller/DeleteUserController.php index 07329b6bc..ecd24189f 100644 --- a/framework/core/src/Api/Controller/DeleteUserController.php +++ b/framework/core/src/Api/Controller/DeleteUserController.php @@ -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)) ); } } diff --git a/framework/core/src/Api/Controller/ForgotPasswordController.php b/framework/core/src/Api/Controller/ForgotPasswordController.php index 00a2fcf85..342ef05f2 100644 --- a/framework/core/src/Api/Controller/ForgotPasswordController.php +++ b/framework/core/src/Api/Controller/ForgotPasswordController.php @@ -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. diff --git a/framework/core/src/Api/Controller/ListAccessTokensController.php b/framework/core/src/Api/Controller/ListAccessTokensController.php index 5b6b425ba..f0aea1e7c 100644 --- a/framework/core/src/Api/Controller/ListAccessTokensController.php +++ b/framework/core/src/Api/Controller/ListAccessTokensController.php @@ -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 diff --git a/framework/core/src/Api/Controller/ListDiscussionsController.php b/framework/core/src/Api/Controller/ListDiscussionsController.php index ca34a1881..8a2522846 100644 --- a/framework/core/src/Api/Controller/ListDiscussionsController.php +++ b/framework/core/src/Api/Controller/ListDiscussionsController.php @@ -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 diff --git a/framework/core/src/Api/Controller/ListGroupsController.php b/framework/core/src/Api/Controller/ListGroupsController.php index df5c90467..f2a085119 100644 --- a/framework/core/src/Api/Controller/ListGroupsController.php +++ b/framework/core/src/Api/Controller/ListGroupsController.php @@ -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 diff --git a/framework/core/src/Api/Controller/ListNotificationsController.php b/framework/core/src/Api/Controller/ListNotificationsController.php index 354478ca1..3d9d63e24 100644 --- a/framework/core/src/Api/Controller/ListNotificationsController.php +++ b/framework/core/src/Api/Controller/ListNotificationsController.php @@ -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 diff --git a/framework/core/src/Api/Controller/ListPostsController.php b/framework/core/src/Api/Controller/ListPostsController.php index 5a6a0cf1c..7f0ab43b6 100644 --- a/framework/core/src/Api/Controller/ListPostsController.php +++ b/framework/core/src/Api/Controller/ListPostsController.php @@ -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' diff --git a/framework/core/src/Api/Controller/ListUsersController.php b/framework/core/src/Api/Controller/ListUsersController.php index 792635341..4fdc54f59 100644 --- a/framework/core/src/Api/Controller/ListUsersController.php +++ b/framework/core/src/Api/Controller/ListUsersController.php @@ -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 diff --git a/framework/core/src/Api/Controller/ReadAllNotificationsController.php b/framework/core/src/Api/Controller/ReadAllNotificationsController.php index ca806a6be..dd263fced 100644 --- a/framework/core/src/Api/Controller/ReadAllNotificationsController.php +++ b/framework/core/src/Api/Controller/ReadAllNotificationsController.php @@ -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)) diff --git a/framework/core/src/Api/Controller/SendConfirmationEmailController.php b/framework/core/src/Api/Controller/SendConfirmationEmailController.php index dadde03a3..18a7fe0e6 100644 --- a/framework/core/src/Api/Controller/SendConfirmationEmailController.php +++ b/framework/core/src/Api/Controller/SendConfirmationEmailController.php @@ -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(); diff --git a/framework/core/src/Api/Controller/SendTestMailController.php b/framework/core/src/Api/Controller/SendTestMailController.php index 388510bb5..ac2819846 100644 --- a/framework/core/src/Api/Controller/SendTestMailController.php +++ b/framework/core/src/Api/Controller/SendTestMailController.php @@ -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(); diff --git a/framework/core/src/Api/Controller/SetPermissionController.php b/framework/core/src/Api/Controller/SetPermissionController.php index 533321637..db748a86a 100644 --- a/framework/core/src/Api/Controller/SetPermissionController.php +++ b/framework/core/src/Api/Controller/SetPermissionController.php @@ -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(); diff --git a/framework/core/src/Api/Controller/SetSettingsController.php b/framework/core/src/Api/Controller/SetSettingsController.php index 38c8b8ca4..38fecb851 100644 --- a/framework/core/src/Api/Controller/SetSettingsController.php +++ b/framework/core/src/Api/Controller/SetSettingsController.php @@ -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(); } } diff --git a/framework/core/src/Api/Controller/ShowDiscussionController.php b/framework/core/src/Api/Controller/ShowDiscussionController.php index cabfe79cb..c66fc50df 100644 --- a/framework/core/src/Api/Controller/ShowDiscussionController.php +++ b/framework/core/src/Api/Controller/ShowDiscussionController.php @@ -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); diff --git a/framework/core/src/Api/Controller/ShowExtensionReadmeController.php b/framework/core/src/Api/Controller/ShowExtensionReadmeController.php index 034d6d0e3..7a78b1631 100644 --- a/framework/core/src/Api/Controller/ShowExtensionReadmeController.php +++ b/framework/core/src/Api/Controller/ShowExtensionReadmeController.php @@ -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(); diff --git a/framework/core/src/Api/Controller/ShowForumController.php b/framework/core/src/Api/Controller/ShowForumController.php index f0c005513..a5cc83fd3 100644 --- a/framework/core/src/Api/Controller/ShowForumController.php +++ b/framework/core/src/Api/Controller/ShowForumController.php @@ -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); diff --git a/framework/core/src/Api/Controller/ShowGroupController.php b/framework/core/src/Api/Controller/ShowGroupController.php index 6787be3cc..79363a62b 100644 --- a/framework/core/src/Api/Controller/ShowGroupController.php +++ b/framework/core/src/Api/Controller/ShowGroupController.php @@ -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); diff --git a/framework/core/src/Api/Controller/ShowMailSettingsController.php b/framework/core/src/Api/Controller/ShowMailSettingsController.php index 90a4dc654..7ce5f03db 100644 --- a/framework/core/src/Api/Controller/ShowMailSettingsController.php +++ b/framework/core/src/Api/Controller/ShowMailSettingsController.php @@ -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(); diff --git a/framework/core/src/Api/Controller/ShowPostController.php b/framework/core/src/Api/Controller/ShowPostController.php index 25f7715b0..694e4c24b 100644 --- a/framework/core/src/Api/Controller/ShowPostController.php +++ b/framework/core/src/Api/Controller/ShowPostController.php @@ -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); diff --git a/framework/core/src/Api/Controller/ShowUserController.php b/framework/core/src/Api/Controller/ShowUserController.php index 779d5e5f0..858cf5509 100644 --- a/framework/core/src/Api/Controller/ShowUserController.php +++ b/framework/core/src/Api/Controller/ShowUserController.php @@ -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); diff --git a/framework/core/src/Api/Controller/TerminateAllOtherSessionsController.php b/framework/core/src/Api/Controller/TerminateAllOtherSessionsController.php index fadf6f384..460858fc1 100644 --- a/framework/core/src/Api/Controller/TerminateAllOtherSessionsController.php +++ b/framework/core/src/Api/Controller/TerminateAllOtherSessionsController.php @@ -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); diff --git a/framework/core/src/Api/Controller/UninstallExtensionController.php b/framework/core/src/Api/Controller/UninstallExtensionController.php index 8f0cfb01e..1911be7f8 100644 --- a/framework/core/src/Api/Controller/UninstallExtensionController.php +++ b/framework/core/src/Api/Controller/UninstallExtensionController.php @@ -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; diff --git a/framework/core/src/Api/Controller/UpdateDiscussionController.php b/framework/core/src/Api/Controller/UpdateDiscussionController.php index 24516159c..cc9b99b68 100644 --- a/framework/core/src/Api/Controller/UpdateDiscussionController.php +++ b/framework/core/src/Api/Controller/UpdateDiscussionController.php @@ -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( diff --git a/framework/core/src/Api/Controller/UpdateExtensionController.php b/framework/core/src/Api/Controller/UpdateExtensionController.php index bd6765896..66d2e273a 100644 --- a/framework/core/src/Api/Controller/UpdateExtensionController.php +++ b/framework/core/src/Api/Controller/UpdateExtensionController.php @@ -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) diff --git a/framework/core/src/Api/Controller/UpdateGroupController.php b/framework/core/src/Api/Controller/UpdateGroupController.php index aa59e8970..0e520cf4f 100644 --- a/framework/core/src/Api/Controller/UpdateGroupController.php +++ b/framework/core/src/Api/Controller/UpdateGroupController.php @@ -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) diff --git a/framework/core/src/Api/Controller/UpdateNotificationController.php b/framework/core/src/Api/Controller/UpdateNotificationController.php index 153f37ced..251e83e7e 100644 --- a/framework/core/src/Api/Controller/UpdateNotificationController.php +++ b/framework/core/src/Api/Controller/UpdateNotificationController.php @@ -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( diff --git a/framework/core/src/Api/Controller/UpdatePostController.php b/framework/core/src/Api/Controller/UpdatePostController.php index 0935836b9..604334c90 100644 --- a/framework/core/src/Api/Controller/UpdatePostController.php +++ b/framework/core/src/Api/Controller/UpdatePostController.php @@ -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) diff --git a/framework/core/src/Api/Controller/UpdateUserController.php b/framework/core/src/Api/Controller/UpdateUserController.php index 1651880fc..25a7f12e9 100644 --- a/framework/core/src/Api/Controller/UpdateUserController.php +++ b/framework/core/src/Api/Controller/UpdateUserController.php @@ -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; diff --git a/framework/core/src/Api/Controller/UploadAvatarController.php b/framework/core/src/Api/Controller/UploadAvatarController.php index 015fc3e08..df1b9e88d 100644 --- a/framework/core/src/Api/Controller/UploadAvatarController.php +++ b/framework/core/src/Api/Controller/UploadAvatarController.php @@ -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) diff --git a/framework/core/src/Api/Controller/UploadImageController.php b/framework/core/src/Api/Controller/UploadImageController.php index 3e9e2e7d4..a27aaf51c 100644 --- a/framework/core/src/Api/Controller/UploadImageController.php +++ b/framework/core/src/Api/Controller/UploadImageController.php @@ -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(); diff --git a/framework/core/src/Api/JsonApiResponse.php b/framework/core/src/Api/JsonApiResponse.php index b05a5dcb6..c0ea8121d 100644 --- a/framework/core/src/Api/JsonApiResponse.php +++ b/framework/core/src/Api/JsonApiResponse.php @@ -9,7 +9,7 @@ namespace Flarum\Api; -use Laminas\Diactoros\Response\JsonResponse; +use Illuminate\Http\JsonResponse; use Tobscure\JsonApi\Document; class JsonApiResponse extends JsonResponse diff --git a/framework/core/src/Api/Serializer/AbstractSerializer.php b/framework/core/src/Api/Serializer/AbstractSerializer.php index a14209453..767c9134f 100644 --- a/framework/core/src/Api/Serializer/AbstractSerializer.php +++ b/framework/core/src/Api/Serializer/AbstractSerializer.php @@ -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; diff --git a/framework/core/src/Formatter/Formatter.php b/framework/core/src/Formatter/Formatter.php index fb71c954a..865dc257c 100644 --- a/framework/core/src/Formatter/Formatter.php +++ b/framework/core/src/Formatter/Formatter.php @@ -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(); diff --git a/framework/core/src/Forum/Content/AssertRegistered.php b/framework/core/src/Forum/Content/AssertRegistered.php index 4c819454c..741ad6def 100644 --- a/framework/core/src/Forum/Content/AssertRegistered.php +++ b/framework/core/src/Forum/Content/AssertRegistered.php @@ -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 { diff --git a/framework/core/src/Forum/Content/Discussion.php b/framework/core/src/Forum/Content/Discussion.php index 5c49cadbf..868099725 100644 --- a/framework/core/src/Forum/Content/Discussion.php +++ b/framework/core/src/Forum/Content/Discussion.php @@ -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']); diff --git a/framework/core/src/Forum/Content/Index.php b/framework/core/src/Forum/Content/Index.php index a8af226e6..b61b9e279 100644 --- a/framework/core/src/Forum/Content/Index.php +++ b/framework/core/src/Forum/Content/Index.php @@ -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'); diff --git a/framework/core/src/Forum/Content/User.php b/framework/core/src/Forum/Content/User.php index cbd46140a..1326ad6f8 100644 --- a/framework/core/src/Forum/Content/User.php +++ b/framework/core/src/Forum/Content/User.php @@ -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()); } } diff --git a/framework/core/src/Forum/Controller/ConfirmEmailController.php b/framework/core/src/Forum/Controller/ConfirmEmailController.php index 2b1be5a18..8e95075dd 100644 --- a/framework/core/src/Forum/Controller/ConfirmEmailController.php +++ b/framework/core/src/Forum/Controller/ConfirmEmailController.php @@ -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); diff --git a/framework/core/src/Forum/Controller/ConfirmEmailViewController.php b/framework/core/src/Forum/Controller/ConfirmEmailViewController.php index df73c270d..70d92ccec 100644 --- a/framework/core/src/Forum/Controller/ConfirmEmailViewController.php +++ b/framework/core/src/Forum/Controller/ConfirmEmailViewController.php @@ -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()); } } diff --git a/framework/core/src/Forum/Controller/GlobalLogOutController.php b/framework/core/src/Forum/Controller/GlobalLogOutController.php index 609ef2f17..9190ff151 100644 --- a/framework/core/src/Forum/Controller/GlobalLogOutController.php +++ b/framework/core/src/Forum/Controller/GlobalLogOutController.php @@ -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)); } } diff --git a/framework/core/src/Forum/Controller/LogInController.php b/framework/core/src/Forum/Controller/LogInController.php index e30b10846..4a7e1a402 100644 --- a/framework/core/src/Forum/Controller/LogInController.php +++ b/framework/core/src/Forum/Controller/LogInController.php @@ -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)); diff --git a/framework/core/src/Forum/Controller/LogOutController.php b/framework/core/src/Forum/Controller/LogOutController.php index 5744946f4..c84451691 100644 --- a/framework/core/src/Forum/Controller/LogOutController.php +++ b/framework/core/src/Forum/Controller/LogOutController.php @@ -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) : '')); diff --git a/framework/core/src/Forum/Controller/RegisterController.php b/framework/core/src/Forum/Controller/RegisterController.php index 8ea02956b..29a4909c9 100644 --- a/framework/core/src/Forum/Controller/RegisterController.php +++ b/framework/core/src/Forum/Controller/RegisterController.php @@ -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); diff --git a/framework/core/src/Forum/Controller/ResetPasswordController.php b/framework/core/src/Forum/Controller/ResetPasswordController.php index 482487ec1..13e58f294 100644 --- a/framework/core/src/Forum/Controller/ResetPasswordController.php +++ b/framework/core/src/Forum/Controller/ResetPasswordController.php @@ -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()); } } diff --git a/framework/core/src/Forum/Controller/SavePasswordController.php b/framework/core/src/Forum/Controller/SavePasswordController.php index 81d7b105b..fbfeeeae6 100644 --- a/framework/core/src/Forum/Controller/SavePasswordController.php +++ b/framework/core/src/Forum/Controller/SavePasswordController.php @@ -10,6 +10,7 @@ namespace Flarum\Forum\Controller; use Flarum\Foundation\DispatchEventsTrait; +use Flarum\Http\Controller\AbstractController; use Flarum\Http\SessionAccessToken; use Flarum\Http\SessionAuthenticator; use Flarum\Http\UrlGenerator; @@ -17,15 +18,14 @@ use Flarum\User\PasswordToken; use Flarum\User\UserValidator; use Illuminate\Contracts\Events\Dispatcher; use Illuminate\Contracts\Validation\Factory; +use Illuminate\Http\Request; use Illuminate\Support\Arr; use Illuminate\Support\MessageBag; use Illuminate\Validation\ValidationException; use Laminas\Diactoros\Response\RedirectResponse; use Psr\Http\Message\ResponseInterface; -use Psr\Http\Message\ServerRequestInterface as Request; -use Psr\Http\Server\RequestHandlerInterface; -class SavePasswordController implements RequestHandlerInterface +class SavePasswordController extends AbstractController { use DispatchEventsTrait; @@ -38,9 +38,9 @@ class SavePasswordController implements RequestHandlerInterface ) { } - public function handle(Request $request): ResponseInterface + public function __invoke(Request $request): ResponseInterface { - $input = $request->getParsedBody(); + $input = $request->json()->all(); $token = PasswordToken::findOrFail(Arr::get($input, 'passwordToken')); @@ -57,7 +57,7 @@ class SavePasswordController implements RequestHandlerInterface throw new ValidationException($validator); } } catch (ValidationException $e) { - $request->getAttribute('session')->put('errors', new MessageBag($e->errors())); + $request->attributes->get('session')->put('errors', new MessageBag($e->errors())); // @todo: must return a 422 instead, look into renderable exceptions. return new RedirectResponse($this->url->to('forum')->route('resetPassword', ['token' => $token->token])); @@ -68,7 +68,7 @@ class SavePasswordController implements RequestHandlerInterface $this->dispatchEventsFor($token->user); - $session = $request->getAttribute('session'); + $session = $request->attributes->get('session'); $accessToken = SessionAccessToken::generate($token->user->id); $this->authenticator->logIn($session, $accessToken); diff --git a/framework/core/src/Frontend/Content/Assets.php b/framework/core/src/Frontend/Content/Assets.php index bab92ac1f..ddbeef9e5 100644 --- a/framework/core/src/Frontend/Content/Assets.php +++ b/framework/core/src/Frontend/Content/Assets.php @@ -14,8 +14,8 @@ use Flarum\Frontend\Assets as FrontendAssets; use Flarum\Frontend\Compiler\CompilerInterface; use Flarum\Frontend\Document; use Illuminate\Contracts\Container\Container; +use Illuminate\Http\Request; use Illuminate\Support\Arr; -use Psr\Http\Message\ServerRequestInterface as Request; class Assets { @@ -43,7 +43,7 @@ class Assets public function __invoke(Document $document, Request $request): void { - $locale = $request->getAttribute('locale'); + $locale = $request->attributes->get('locale'); $compilers = $this->assembleCompilers($locale); diff --git a/framework/core/src/Frontend/Content/CorePayload.php b/framework/core/src/Frontend/Content/CorePayload.php index 3bba17493..4f601a97e 100644 --- a/framework/core/src/Frontend/Content/CorePayload.php +++ b/framework/core/src/Frontend/Content/CorePayload.php @@ -12,7 +12,7 @@ namespace Flarum\Frontend\Content; use Flarum\Frontend\Document; use Flarum\Http\RequestUtil; use Flarum\Locale\LocaleManager; -use Psr\Http\Message\ServerRequestInterface as Request; +use Illuminate\Http\Request; class CorePayload { @@ -37,10 +37,10 @@ class CorePayload 'resources' => $data, 'session' => [ 'userId' => RequestUtil::getActor($request)->id, - 'csrfToken' => $request->getAttribute('session')->token() + 'csrfToken' => $request->attributes->get('session')->token() ], 'locales' => $this->locales->getLocales(), - 'locale' => $request->getAttribute('locale') + 'locale' => $request->attributes->get('locale') ]; } diff --git a/framework/core/src/Frontend/Content/Meta.php b/framework/core/src/Frontend/Content/Meta.php index fd422d0e6..374f55be9 100644 --- a/framework/core/src/Frontend/Content/Meta.php +++ b/framework/core/src/Frontend/Content/Meta.php @@ -11,8 +11,8 @@ namespace Flarum\Frontend\Content; use Flarum\Frontend\Document; use Flarum\Locale\LocaleManager; +use Illuminate\Http\Request; use Illuminate\Support\Arr; -use Psr\Http\Message\ServerRequestInterface as Request; class Meta { diff --git a/framework/core/src/Frontend/Controller.php b/framework/core/src/Frontend/Controller.php index 7a2b93406..0cd61ad7b 100644 --- a/framework/core/src/Frontend/Controller.php +++ b/framework/core/src/Frontend/Controller.php @@ -9,22 +9,18 @@ namespace Flarum\Frontend; -use Laminas\Diactoros\Response\HtmlResponse; -use Psr\Http\Message\ResponseInterface as Response; -use Psr\Http\Message\ServerRequestInterface as Request; -use Psr\Http\Server\RequestHandlerInterface; +use Flarum\Http\Controller\AbstractController; +use Illuminate\Http\Request; -class Controller implements RequestHandlerInterface +class Controller extends AbstractController { public function __construct( protected Frontend $frontend ) { } - public function handle(Request $request): Response + public function __invoke(Request $request): string { - return new HtmlResponse( - $this->frontend->document($request)->render() - ); + return $this->frontend->document($request)->render(); } } diff --git a/framework/core/src/Frontend/Document.php b/framework/core/src/Frontend/Document.php index 3b03602cc..4e3918e3f 100644 --- a/framework/core/src/Frontend/Document.php +++ b/framework/core/src/Frontend/Document.php @@ -17,8 +17,8 @@ use Illuminate\Contracts\Filesystem\Factory as FilesystemFactory; use Illuminate\Contracts\Support\Renderable; use Illuminate\Contracts\View\Factory; use Illuminate\Contracts\View\View; +use Illuminate\Http\Request; use Illuminate\Support\Arr; -use Psr\Http\Message\ServerRequestInterface as Request; /** * A view which renders a HTML skeleton for Flarum's frontend app. diff --git a/framework/core/src/Frontend/Driver/BasicTitleDriver.php b/framework/core/src/Frontend/Driver/BasicTitleDriver.php index 3d003b7fd..e9f3e7ad1 100644 --- a/framework/core/src/Frontend/Driver/BasicTitleDriver.php +++ b/framework/core/src/Frontend/Driver/BasicTitleDriver.php @@ -11,8 +11,8 @@ namespace Flarum\Frontend\Driver; use Flarum\Frontend\Document; use Flarum\Locale\TranslatorInterface; +use Illuminate\Http\Request; use Illuminate\Support\Arr; -use Psr\Http\Message\ServerRequestInterface; class BasicTitleDriver implements TitleDriverInterface { @@ -21,9 +21,9 @@ class BasicTitleDriver implements TitleDriverInterface ) { } - public function makeTitle(Document $document, ServerRequestInterface $request, array $forumApiDocument): string + public function makeTitle(Document $document, Request $request, array $forumApiDocument): string { - $onHomePage = rtrim($request->getUri()->getPath(), '/') === ''; + $onHomePage = rtrim($request->getUri(), '/') === ''; $params = [ 'pageTitle' => $document->title ?? '', diff --git a/framework/core/src/Frontend/Driver/TitleDriverInterface.php b/framework/core/src/Frontend/Driver/TitleDriverInterface.php index 14b5d4382..7b55d3583 100644 --- a/framework/core/src/Frontend/Driver/TitleDriverInterface.php +++ b/framework/core/src/Frontend/Driver/TitleDriverInterface.php @@ -10,9 +10,9 @@ namespace Flarum\Frontend\Driver; use Flarum\Frontend\Document; -use Psr\Http\Message\ServerRequestInterface; +use Illuminate\Http\Request; interface TitleDriverInterface { - public function makeTitle(Document $document, ServerRequestInterface $request, array $forumApiDocument): string; + public function makeTitle(Document $document, Request $request, array $forumApiDocument): string; } diff --git a/framework/core/src/Frontend/Frontend.php b/framework/core/src/Frontend/Frontend.php index e8ac8b35d..621f8d32b 100644 --- a/framework/core/src/Frontend/Frontend.php +++ b/framework/core/src/Frontend/Frontend.php @@ -11,8 +11,8 @@ namespace Flarum\Frontend; use Flarum\Api\Client; use Illuminate\Contracts\Container\Container; -use Psr\Http\Message\ResponseInterface as Response; -use Psr\Http\Message\ServerRequestInterface as Request; +use Illuminate\Http\Request; +use Illuminate\Http\Response; class Frontend { @@ -59,6 +59,6 @@ class Frontend private function getResponseBody(Response $response): array { - return json_decode($response->getBody(), true); + return json_decode($response->content(), true); } } diff --git a/framework/core/src/Http/Controller/AbstractController.php b/framework/core/src/Http/Controller/AbstractController.php new file mode 100644 index 000000000..8f577d3f3 --- /dev/null +++ b/framework/core/src/Http/Controller/AbstractController.php @@ -0,0 +1,10 @@ +render($request); diff --git a/framework/core/src/Install/Controller/IndexController.php b/framework/core/src/Install/Controller/IndexController.php index 6f742fefe..a1449f8b9 100644 --- a/framework/core/src/Install/Controller/IndexController.php +++ b/framework/core/src/Install/Controller/IndexController.php @@ -13,7 +13,7 @@ use Flarum\Http\Controller\AbstractHtmlController; use Flarum\Install\Installation; use Illuminate\Contracts\Support\Renderable; use Illuminate\Contracts\View\Factory; -use Psr\Http\Message\ServerRequestInterface as Request; +use Illuminate\Http\Request; class IndexController extends AbstractHtmlController { diff --git a/framework/core/src/Install/Controller/InstallController.php b/framework/core/src/Install/Controller/InstallController.php index 0d98540a4..2189a7567 100644 --- a/framework/core/src/Install/Controller/InstallController.php +++ b/framework/core/src/Install/Controller/InstallController.php @@ -9,6 +9,7 @@ namespace Flarum\Install\Controller; +use Flarum\Http\Controller\AbstractController; use Flarum\Http\RememberAccessToken; use Flarum\Http\Rememberer; use Flarum\Http\SessionAuthenticator; @@ -18,14 +19,14 @@ use Flarum\Install\DatabaseConfig; use Flarum\Install\Installation; use Flarum\Install\StepFailed; use Flarum\Install\ValidationFailed; +use Illuminate\Http\Request; use Illuminate\Support\Arr; use Illuminate\Support\Str; -use Laminas\Diactoros\Response; +use Laminas\Diactoros\Response as PsrResponse; use Psr\Http\Message\ResponseInterface; -use Psr\Http\Message\ServerRequestInterface as Request; -use Psr\Http\Server\RequestHandlerInterface; +use Symfony\Component\HttpFoundation\Response; -class InstallController implements RequestHandlerInterface +class InstallController extends AbstractController { public function __construct( protected Installation $installation, @@ -34,10 +35,10 @@ class InstallController implements RequestHandlerInterface ) { } - public function handle(Request $request): ResponseInterface + public function __invoke(Request $request): ResponseInterface|Response { - $input = $request->getParsedBody(); - $baseUrl = BaseUrl::fromUri($request->getUri()); + $input = $request->input(); + $baseUrl = BaseUrl::fromString($request->getUri()); // An access token we will use to auto-login the admin at the end of installation $accessToken = Str::random(40); @@ -55,23 +56,24 @@ class InstallController implements RequestHandlerInterface ]) ->build(); } catch (ValidationFailed $e) { - return new Response\HtmlResponse($e->getMessage(), 500); + return new PsrResponse\HtmlResponse($e->getMessage(), 500); } try { $pipeline->run(); } catch (StepFailed $e) { - return new Response\HtmlResponse($e->getPrevious()->getMessage(), 500); + return new PsrResponse\HtmlResponse($e->getPrevious()->getMessage(), 500); } - $session = $request->getAttribute('session'); + $session = $request->attributes->get('session'); + // Because the Eloquent models cannot be used yet, we create a temporary in-memory object // that won't interact with the database but can be passed to the authenticator and rememberer $token = new RememberAccessToken(); $token->token = $accessToken; $this->authenticator->logIn($session, $token); - return $this->rememberer->remember(new Response\EmptyResponse, $token); + return $this->rememberer->remember(new Response(null, 204), $token); } private function makeDatabaseConfig(array $input): DatabaseConfig diff --git a/framework/core/src/Install/Installer.php b/framework/core/src/Install/Installer.php index 192e499cd..dbe692abd 100644 --- a/framework/core/src/Install/Installer.php +++ b/framework/core/src/Install/Installer.php @@ -31,21 +31,16 @@ class Installer implements AppInterface return $this->container; } - public function getRequestHandler(): RequestHandlerInterface + public function getMiddlewareStack(): array { - $pipe = new MiddlewarePipe; - $pipe->pipe(new HttpMiddleware\HandleErrors( - $this->container->make(Registry::class), - $this->container->make(WhoopsFormatter::class), - $this->container->tagged(Reporter::class) - )); - $pipe->pipe($this->container->make(HttpMiddleware\StartSession::class)); - $pipe->pipe( - new HttpMiddleware\ResolveRoute($this->container->make('flarum.install.routes')) - ); - $pipe->pipe(new HttpMiddleware\ExecuteRoute()); - - return $pipe; + return [ + new HttpMiddleware\HandleErrors( + $this->container->make(Registry::class), + $this->container->make(WhoopsFormatter::class), + $this->container->tagged(Reporter::class) + ), + $this->container->make(HttpMiddleware\StartSession::class), + ]; } /** diff --git a/framework/core/src/Post/CommentPost.php b/framework/core/src/Post/CommentPost.php index c1b150ddb..d2afb248e 100644 --- a/framework/core/src/Post/CommentPost.php +++ b/framework/core/src/Post/CommentPost.php @@ -16,7 +16,7 @@ use Flarum\Post\Event\Posted; use Flarum\Post\Event\Restored; use Flarum\Post\Event\Revised; use Flarum\User\User; -use Psr\Http\Message\ServerRequestInterface; +use Illuminate\Http\Request; /** * A standard comment in a discussion. @@ -109,7 +109,7 @@ class CommentPost extends Post /** * Get the content rendered as HTML. */ - public function formatContent(?ServerRequestInterface $request = null): string + public function formatContent(?Request $request = null): string { return static::$formatter->render($this->attributes['content'], $this, $request); } diff --git a/framework/core/src/Post/PostCreationThrottler.php b/framework/core/src/Post/PostCreationThrottler.php index 86d44c7e5..0c8083b62 100644 --- a/framework/core/src/Post/PostCreationThrottler.php +++ b/framework/core/src/Post/PostCreationThrottler.php @@ -11,15 +11,15 @@ namespace Flarum\Post; use Carbon\Carbon; use Flarum\Http\RequestUtil; -use Psr\Http\Message\ServerRequestInterface; +use Illuminate\Http\Request; class PostCreationThrottler { public static int $timeout = 10; - public function __invoke(ServerRequestInterface $request): ?bool + public function __invoke(Request $request): ?bool { - if (! in_array($request->getAttribute('routeName'), ['discussions.create', 'posts.create'])) { + if (! $request->routeIs('discussions.create', 'posts.create')) { return null; } diff --git a/framework/core/src/Update/Controller/IndexController.php b/framework/core/src/Update/Controller/IndexController.php index c9ae10579..5245bfc40 100644 --- a/framework/core/src/Update/Controller/IndexController.php +++ b/framework/core/src/Update/Controller/IndexController.php @@ -12,7 +12,7 @@ namespace Flarum\Update\Controller; use Flarum\Http\Controller\AbstractHtmlController; use Illuminate\Contracts\Support\Renderable; use Illuminate\Contracts\View\Factory; -use Psr\Http\Message\ServerRequestInterface as Request; +use Illuminate\Http\Request; class IndexController extends AbstractHtmlController { diff --git a/framework/core/src/Update/Controller/UpdateController.php b/framework/core/src/Update/Controller/UpdateController.php index d018664be..0db37ba23 100644 --- a/framework/core/src/Update/Controller/UpdateController.php +++ b/framework/core/src/Update/Controller/UpdateController.php @@ -12,16 +12,15 @@ namespace Flarum\Update\Controller; use Exception; use Flarum\Database\Console\MigrateCommand; use Flarum\Foundation\Config; -use Illuminate\Support\Arr; +use Flarum\Http\Controller\AbstractController; +use Illuminate\Http\Request; use Laminas\Diactoros\Response; use Laminas\Diactoros\Response\HtmlResponse; use Psr\Http\Message\ResponseInterface; -use Psr\Http\Message\ServerRequestInterface as Request; -use Psr\Http\Server\RequestHandlerInterface; use Symfony\Component\Console\Input\StringInput; use Symfony\Component\Console\Output\StreamOutput; -class UpdateController implements RequestHandlerInterface +class UpdateController extends AbstractController { public function __construct( protected MigrateCommand $command, @@ -29,11 +28,9 @@ class UpdateController implements RequestHandlerInterface ) { } - public function handle(Request $request): ResponseInterface + public function __invoke(Request $request): ResponseInterface { - $input = $request->getParsedBody(); - - if (Arr::get($input, 'databasePassword') !== $this->config['database.password']) { + if ($request->input('databasePassword') !== $this->config['database.password']) { return new HtmlResponse('Incorrect database password.', 500); } diff --git a/framework/core/src/User/Throttler/EmailActivationThrottler.php b/framework/core/src/User/Throttler/EmailActivationThrottler.php index 01c7bba1c..ae45f4d49 100644 --- a/framework/core/src/User/Throttler/EmailActivationThrottler.php +++ b/framework/core/src/User/Throttler/EmailActivationThrottler.php @@ -12,7 +12,7 @@ namespace Flarum\User\Throttler; use Carbon\Carbon; use Flarum\Http\RequestUtil; use Flarum\User\EmailToken; -use Psr\Http\Message\ServerRequestInterface; +use Illuminate\Http\Request; /** * Unactivated users can request a confirmation email, @@ -22,9 +22,9 @@ class EmailActivationThrottler { public static int $timeout = 300; - public function __invoke(ServerRequestInterface $request): ?bool + public function __invoke(Request $request): ?bool { - if ($request->getAttribute('routeName') !== 'users.confirmation.send') { + if ($request->routeIs('users.confirmation.send')) { return null; } diff --git a/framework/core/src/User/Throttler/EmailChangeThrottler.php b/framework/core/src/User/Throttler/EmailChangeThrottler.php index cdb009bd6..5fbb92376 100644 --- a/framework/core/src/User/Throttler/EmailChangeThrottler.php +++ b/framework/core/src/User/Throttler/EmailChangeThrottler.php @@ -12,8 +12,7 @@ namespace Flarum\User\Throttler; use Carbon\Carbon; use Flarum\Http\RequestUtil; use Flarum\User\EmailToken; -use Illuminate\Support\Arr; -use Psr\Http\Message\ServerRequestInterface; +use Illuminate\Http\Request; /** * Users can request an email change, @@ -23,13 +22,13 @@ class EmailChangeThrottler { public static int $timeout = 300; - public function __invoke(ServerRequestInterface $request): ?bool + public function __invoke(Request $request): ?bool { - if ($request->getAttribute('routeName') !== 'users.update') { + if ($request->routeIs('users.update')) { return null; } - if (! Arr::has($request->getParsedBody(), 'data.attributes.email')) { + if (! $request->json('data.attributes.email')) { return null; } diff --git a/framework/core/src/User/Throttler/PasswordResetThrottler.php b/framework/core/src/User/Throttler/PasswordResetThrottler.php index 695e3f7d1..0aa38bb63 100644 --- a/framework/core/src/User/Throttler/PasswordResetThrottler.php +++ b/framework/core/src/User/Throttler/PasswordResetThrottler.php @@ -12,8 +12,7 @@ namespace Flarum\User\Throttler; use Carbon\Carbon; use Flarum\Http\RequestUtil; use Flarum\User\PasswordToken; -use Illuminate\Support\Arr; -use Psr\Http\Message\ServerRequestInterface; +use Illuminate\Http\Request; /** * Logged-in users can request password reset email, @@ -24,13 +23,13 @@ class PasswordResetThrottler { public static int $timeout = 300; - public function __invoke(ServerRequestInterface $request): ?bool + public function __invoke(Request $request): ?bool { - if ($request->getAttribute('routeName') !== 'forgot') { + if ($request->routeIs('forgot')) { return null; } - if (! Arr::has($request->getParsedBody(), 'email')) { + if (! $request->has('email')) { return null; } diff --git a/framework/core/tests/integration/api/AbstractSerializeControllerTest.php b/framework/core/tests/integration/api/AbstractSerializeControllerTest.php index 9b98cc487..d990ae1e9 100644 --- a/framework/core/tests/integration/api/AbstractSerializeControllerTest.php +++ b/framework/core/tests/integration/api/AbstractSerializeControllerTest.php @@ -12,6 +12,7 @@ namespace Flarum\Tests\integration\api; use Flarum\Api\Controller\AbstractSerializeController; use Flarum\Extend; use Flarum\Testing\integration\TestCase; +use Illuminate\Http\Request; use Psr\Http\Message\ServerRequestInterface; use Tobscure\JsonApi\Document; use Tobscure\JsonApi\ElementInterface; @@ -41,7 +42,7 @@ class DummySerializeController extends AbstractSerializeController { public ?string $serializer = null; - protected function data(ServerRequestInterface $request, Document $document): mixed + protected function data(Request $request, Document $document): mixed { return []; } diff --git a/framework/core/tests/integration/extenders/FrontendTitleTest.php b/framework/core/tests/integration/extenders/FrontendTitleTest.php index c3410428b..122eb751d 100644 --- a/framework/core/tests/integration/extenders/FrontendTitleTest.php +++ b/framework/core/tests/integration/extenders/FrontendTitleTest.php @@ -14,6 +14,7 @@ use Flarum\Frontend\Document; use Flarum\Frontend\Driver\TitleDriverInterface; use Flarum\Testing\integration\RetrievesAuthorizedUsers; use Flarum\Testing\integration\TestCase; +use Illuminate\Http\Request; use Psr\Http\Message\ServerRequestInterface; class FrontendTitleTest extends TestCase @@ -67,7 +68,7 @@ class FrontendTitleTest extends TestCase class CustomTitleDriver implements TitleDriverInterface { - public function makeTitle(Document $document, ServerRequestInterface $request, array $forumApiDocument): string + public function makeTitle(Document $document, Request $request, array $forumApiDocument): string { return 'CustomTitle'; }