Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

proof of concept illuminate http #3865

Draft
wants to merge 22 commits into
base: 2.x
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
5 changes: 3 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -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",
Expand All @@ -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",
Expand All @@ -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"
Expand Down
2 changes: 1 addition & 1 deletion extensions/akismet/src/Provider/AkismetProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ public function register(): void

return new Akismet(
$settings->get('flarum-akismet.api_key'),
$url->to('forum')->base(),
$url->base('forum'),
$app::VERSION,
$extensions->getExtension('flarum-akismet')->getVersion() ?? 'unknown',
$config->inDebugMode()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ public function can_only_see_approved_if_not_allowed_to_approve(?int $authentica
$this->request('GET', '/api/discussions', compact('authenticatedAs'))
);

$body = json_decode($response->getBody()->getContents(), true);
$body = json_decode($response->getContent(), true);

$this->assertEquals(200, $response->getStatusCode());
$this->assertEqualsCanonicalizing([1, 4, 5, 7], Arr::pluck($body['data'], 'id'));
Expand All @@ -54,7 +54,7 @@ public function can_see_unapproved_if_allowed_to_approve(int $authenticatedAs)
$this->request('GET', '/api/discussions', compact('authenticatedAs'))
);

$body = json_decode($response->getBody()->getContents(), true);
$body = json_decode($response->getContent(), true);

$this->assertEquals(200, $response->getStatusCode());
$this->assertEqualsCanonicalizing([1, 2, 3, 4, 5, 6, 7], Arr::pluck($body['data'], 'id'));
Expand Down
19 changes: 11 additions & 8 deletions extensions/approval/tests/integration/api/ListPostsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
use Flarum\Approval\Tests\integration\InteractsWithUnapprovedContent;
use Flarum\Testing\integration\RetrievesAuthorizedUsers;
use Flarum\Testing\integration\TestCase;
use Illuminate\Http\Request;
use Illuminate\Support\Arr;

class ListPostsTest extends TestCase
Expand All @@ -35,16 +36,17 @@ protected function setUp(): void
public function can_only_see_approved_if_not_allowed_to_approve(?int $authenticatedAs)
{
$response = $this->send(
$this
->request('GET', '/api/posts', compact('authenticatedAs'))
->withQueryParams([
tap(
$this->request('GET', '/api/posts', compact('authenticatedAs')),
fn (Request $request) => $request->query->add([
'filter' => [
'discussion' => 7
]
])
)
);

$body = json_decode($response->getBody()->getContents(), true);
$body = json_decode($response->getContent(), true);

$this->assertEquals(200, $response->getStatusCode());
$this->assertEqualsCanonicalizing([7, 8, 10], Arr::pluck($body['data'], 'id'));
Expand All @@ -57,16 +59,17 @@ public function can_only_see_approved_if_not_allowed_to_approve(?int $authentica
public function can_see_unapproved_if_allowed_to_approve(int $authenticatedAs)
{
$response = $this->send(
$this
->request('GET', '/api/posts', compact('authenticatedAs'))
->withQueryParams([
tap(
$this->request('GET', '/api/posts', compact('authenticatedAs')),
fn (Request $request) => $request->query->add([
'filter' => [
'discussion' => 7
]
])
)
);

$body = json_decode($response->getBody()->getContents(), true);
$body = json_decode($response->getContent(), true);

$this->assertEquals(200, $response->getStatusCode());
$this->assertEqualsCanonicalizing([7, 8, 9, 10, 11], Arr::pluck($body['data'], 'id'));
Expand Down
2 changes: 1 addition & 1 deletion extensions/embed/extend.php
Original file line number Diff line number Diff line change
Expand Up @@ -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'))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,7 @@
use Flarum\Flags\Flag;
use Flarum\Http\RequestUtil;
use Illuminate\Contracts\Bus\Dispatcher;
use Illuminate\Support\Arr;
use Psr\Http\Message\ServerRequestInterface;
use Illuminate\Http\Request;
use Tobscure\JsonApi\Document;

class CreateFlagController extends AbstractCreateController
Expand All @@ -34,10 +33,10 @@ public function __construct(
) {
}

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', []))
new CreateFlag(RequestUtil::getActor($request), $request->json('data', []))
);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,7 @@
use Flarum\Flags\Command\DeleteFlags;
use Flarum\Http\RequestUtil;
use Illuminate\Contracts\Bus\Dispatcher;
use Illuminate\Support\Arr;
use Psr\Http\Message\ServerRequestInterface;
use Illuminate\Http\Request;

class DeleteFlagsController extends AbstractDeleteController
{
Expand All @@ -23,10 +22,10 @@
) {
}

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->route('id'), RequestUtil::getActor($request), $request->json()->all())

Check failure on line 28 in extensions/flags/src/Api/Controller/DeleteFlagsController.php

View workflow job for this annotation

GitHub Actions / run / PHPStan PHP 8.1

Parameter #1 $postId of class Flarum\Flags\Command\DeleteFlags constructor expects int, object|string|null given.
);
}
}
4 changes: 2 additions & 2 deletions extensions/flags/src/Api/Controller/ListFlagsController.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
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
Expand All @@ -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);
Expand Down
4 changes: 2 additions & 2 deletions extensions/flags/src/PrepareFlagsApiData.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,11 @@
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
Expand Down
6 changes: 3 additions & 3 deletions extensions/flags/tests/integration/api/flags/ListTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ public function admin_can_see_one_flag_per_post()

$this->assertEquals(200, $response->getStatusCode());

$data = json_decode($response->getBody()->getContents(), true)['data'];
$data = json_decode($response->getContent(), true)['data'];

$ids = Arr::pluck($data, 'id');
$this->assertEqualsCanonicalizing(['1', '4', '5'], $ids);
Expand All @@ -94,7 +94,7 @@ public function regular_user_sees_own_flags()

$this->assertEquals(200, $response->getStatusCode());

$data = json_decode($response->getBody()->getContents(), true)['data'];
$data = json_decode($response->getContent(), true)['data'];

$ids = Arr::pluck($data, 'id');
$this->assertEqualsCanonicalizing(['2', '4'], $ids);
Expand All @@ -113,7 +113,7 @@ public function mod_can_see_one_flag_per_post()

$this->assertEquals(200, $response->getStatusCode());

$data = json_decode($response->getBody()->getContents(), true)['data'];
$data = json_decode($response->getContent(), true)['data'];

$ids = Arr::pluck($data, 'id');
$this->assertEqualsCanonicalizing(['1', '4', '5'], $ids);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ public function admin_can_see_one_flag_per_post()

$this->assertEquals(200, $response->getStatusCode());

$data = json_decode($response->getBody()->getContents(), true)['data'];
$data = json_decode($response->getContent(), true)['data'];

$ids = Arr::pluck($data, 'id');
$this->assertEqualsCanonicalizing(['1', '4', '5', '6', '7', '8', '9'], $ids);
Expand All @@ -127,7 +127,7 @@ public function regular_user_sees_own_flags()

$this->assertEquals(200, $response->getStatusCode());

$data = json_decode($response->getBody()->getContents(), true)['data'];
$data = json_decode($response->getContent(), true)['data'];

$ids = Arr::pluck($data, 'id');
$this->assertEqualsCanonicalizing(['2', '4'], $ids);
Expand All @@ -146,7 +146,7 @@ public function mod_can_see_one_flag_per_post()

$this->assertEquals(200, $response->getStatusCode());

$data = json_decode($response->getBody()->getContents(), true)['data'];
$data = json_decode($response->getContent(), true)['data'];

$ids = Arr::pluck($data, 'id');
// 7 is included, even though mods can't view discussions.
Expand Down
4 changes: 2 additions & 2 deletions extensions/likes/src/Api/LoadLikesRelationship.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,13 @@
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);

Expand Down
4 changes: 2 additions & 2 deletions extensions/likes/tests/integration/api/LikePostTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ protected function sendLikeRequest(int $postId, ?int $authenticatedAs, bool $lik
$this->request('GET', '/')
);

$token = $initial->getHeaderLine('X-CSRF-Token');
$token = $initial->headers->get('X-CSRF-Token');
}

$request = $this->request('PATCH', "/api/posts/$postId", [
Expand All @@ -159,7 +159,7 @@ protected function sendLikeRequest(int $postId, ?int $authenticatedAs, bool $lik
]);

if (! isset($authenticatedAs)) {
$request = $request->withHeader('X-CSRF-Token', $token);
$request->headers->set('X-CSRF-Token', $token);
}

return $this->send($request);
Expand Down
Loading
Loading