mirror of
https://github.com/flarum/framework.git
synced 2024-11-24 19:34:46 +08:00
chore: some fixes
This commit is contained in:
parent
834bd732da
commit
6fb1640b3c
|
@ -16,7 +16,6 @@ use Flarum\Flags\Flag;
|
|||
use Flarum\Http\RequestUtil;
|
||||
use Illuminate\Contracts\Bus\Dispatcher;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Arr;
|
||||
use Tobscure\JsonApi\Document;
|
||||
|
||||
class CreateFlagController extends AbstractCreateController
|
||||
|
@ -37,7 +36,7 @@ class CreateFlagController extends AbstractCreateController
|
|||
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', []))
|
||||
);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -9,12 +9,13 @@
|
|||
|
||||
namespace Flarum\Api;
|
||||
|
||||
use Flarum\Foundation\Config;
|
||||
use Flarum\Http\RequestUtil;
|
||||
use Flarum\Http\Router;
|
||||
use Flarum\User\User;
|
||||
use Illuminate\Contracts\Container\Container;
|
||||
use Illuminate\Http\JsonResponse;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Http\Response;
|
||||
use Illuminate\Routing\Pipeline;
|
||||
use Psr\Http\Message\ServerRequestInterface;
|
||||
use Symfony\Component\HttpFoundation\Request as SymfonyRequest;
|
||||
|
@ -75,27 +76,27 @@ class Client
|
|||
return $new;
|
||||
}
|
||||
|
||||
public function get(string $path): Response
|
||||
public function get(string $path): JsonResponse
|
||||
{
|
||||
return $this->send('GET', $path);
|
||||
}
|
||||
|
||||
public function post(string $path): Response
|
||||
public function post(string $path): JsonResponse
|
||||
{
|
||||
return $this->send('POST', $path);
|
||||
}
|
||||
|
||||
public function put(string $path): Response
|
||||
public function put(string $path): JsonResponse
|
||||
{
|
||||
return $this->send('PUT', $path);
|
||||
}
|
||||
|
||||
public function patch(string $path): Response
|
||||
public function patch(string $path): JsonResponse
|
||||
{
|
||||
return $this->send('PATCH', $path);
|
||||
}
|
||||
|
||||
public function delete(string $path): Response
|
||||
public function delete(string $path): JsonResponse
|
||||
{
|
||||
return $this->send('DELETE', $path);
|
||||
}
|
||||
|
@ -105,18 +106,19 @@ class Client
|
|||
*
|
||||
* @internal
|
||||
*/
|
||||
public function send(string $method, string $path): Response
|
||||
public function send(string $method, string $path): JsonResponse
|
||||
{
|
||||
$parent = $this->parent ?: Request::createFromGlobals();
|
||||
/** @var Config $config */
|
||||
$config = $this->container->make(Config::class);
|
||||
|
||||
$symfonyRequest = SymfonyRequest::create(
|
||||
$path, $method, $this->queryParams, $parent->cookies->all(), $parent->files->all(), $parent->server->all(), $this->body
|
||||
$config->path('api').$path, $method, $this->queryParams, $parent->cookies->all(), $parent->files->all(), $parent->server->all(), json_encode($this->body)
|
||||
);
|
||||
|
||||
$request = Request::createFromBase($symfonyRequest);
|
||||
|
||||
if ($this->parent) {
|
||||
$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));
|
||||
}
|
||||
|
|
|
@ -16,7 +16,6 @@ use Flarum\Http\RequestUtil;
|
|||
use Illuminate\Contracts\Events\Dispatcher;
|
||||
use Illuminate\Contracts\Validation\Factory;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Arr;
|
||||
use Tobscure\JsonApi\Document;
|
||||
|
||||
/**
|
||||
|
@ -40,7 +39,7 @@ class CreateAccessTokenController extends AbstractCreateController
|
|||
$actor->assertRegistered();
|
||||
$actor->assertCan('createAccessToken');
|
||||
|
||||
$title = Arr::get($request->getParsedBody(), 'data.attributes.title');
|
||||
$title = $request->json('data.attributes.title');
|
||||
|
||||
$this->validation->make(compact('title'), [
|
||||
'title' => 'required|string|max:255',
|
||||
|
|
|
@ -17,7 +17,6 @@ use Flarum\Http\RequestUtil;
|
|||
use Illuminate\Contracts\Bus\Dispatcher;
|
||||
use Illuminate\Database\Eloquent\Collection;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Arr;
|
||||
use Tobscure\JsonApi\Document;
|
||||
|
||||
class CreateDiscussionController extends AbstractCreateController
|
||||
|
@ -40,10 +39,10 @@ class CreateDiscussionController extends AbstractCreateController
|
|||
protected function data(Request $request, Document $document): Discussion
|
||||
{
|
||||
$actor = RequestUtil::getActor($request);
|
||||
$ipAddress = $request->getAttribute('ipAddress');
|
||||
$ipAddress = $request->ip();
|
||||
|
||||
$discussion = $this->bus->dispatch(
|
||||
new StartDiscussion($actor, Arr::get($request->getParsedBody(), 'data', []), $ipAddress)
|
||||
new StartDiscussion($actor, $request->json('data', []), $ipAddress)
|
||||
);
|
||||
|
||||
// After creating the discussion, we assume that the user has seen all
|
||||
|
|
|
@ -15,7 +15,6 @@ use Flarum\Group\Group;
|
|||
use Flarum\Http\RequestUtil;
|
||||
use Illuminate\Contracts\Bus\Dispatcher;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Arr;
|
||||
use Tobscure\JsonApi\Document;
|
||||
|
||||
class CreateGroupController extends AbstractCreateController
|
||||
|
@ -30,7 +29,7 @@ class CreateGroupController extends AbstractCreateController
|
|||
protected function data(Request $request, Document $document): Group
|
||||
{
|
||||
return $this->bus->dispatch(
|
||||
new CreateGroup(RequestUtil::getActor($request), Arr::get($request->getParsedBody(), 'data', []))
|
||||
new CreateGroup(RequestUtil::getActor($request), $request->json('data', []))
|
||||
);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -38,9 +38,9 @@ class CreatePostController extends AbstractCreateController
|
|||
protected function data(Request $request, Document $document): CommentPost
|
||||
{
|
||||
$actor = RequestUtil::getActor($request);
|
||||
$data = Arr::get($request->getParsedBody(), 'data', []);
|
||||
$data = $request->json('data', []);
|
||||
$discussionId = (int) Arr::get($data, 'relationships.discussion.data.id');
|
||||
$ipAddress = $request->getAttribute('ipAddress');
|
||||
$ipAddress = $request->ip();
|
||||
|
||||
/** @var CommentPost $post */
|
||||
$post = $this->bus->dispatch(
|
||||
|
|
|
@ -15,7 +15,6 @@ use Flarum\User\Command\RegisterUser;
|
|||
use Flarum\User\User;
|
||||
use Illuminate\Contracts\Bus\Dispatcher;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Arr;
|
||||
use Tobscure\JsonApi\Document;
|
||||
|
||||
class CreateUserController extends AbstractCreateController
|
||||
|
@ -30,7 +29,7 @@ class CreateUserController extends AbstractCreateController
|
|||
protected function data(Request $request, Document $document): User
|
||||
{
|
||||
return $this->bus->dispatch(
|
||||
new RegisterUser(RequestUtil::getActor($request), Arr::get($request->getParsedBody(), 'data', []))
|
||||
new RegisterUser(RequestUtil::getActor($request), $request->json('data', []))
|
||||
);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -29,7 +29,7 @@ class DeleteAccessTokenController extends AbstractDeleteController
|
|||
$token = AccessToken::query()->findOrFail($id);
|
||||
|
||||
/** @var Session|null $session */
|
||||
$session = $request->getAttribute('session');
|
||||
$session = $request->attributes->get('session');
|
||||
|
||||
// Current session should only be terminated through logout.
|
||||
if ($session && $token->token === $session->get('access_token')) {
|
||||
|
|
|
@ -23,7 +23,7 @@ class TerminateAllOtherSessionsController extends AbstractDeleteController
|
|||
|
||||
$actor->assertRegistered();
|
||||
|
||||
$session = $request->getAttribute('session');
|
||||
$session = $request->attributes->get('session');
|
||||
$sessionAccessToken = $session ? $session->get('access_token') : null;
|
||||
|
||||
// Delete all session access tokens except for this one.
|
||||
|
|
|
@ -44,7 +44,7 @@ class UpdateUserController extends AbstractShowController
|
|||
// Require the user's current password if they are attempting to change
|
||||
// their own email address.
|
||||
if (isset($data['attributes']['email']) && $actor->id == $id) {
|
||||
$password = (string) Arr::get($request->getParsedBody(), 'meta.password');
|
||||
$password = (string) Arr::get($data, 'meta.password');
|
||||
|
||||
if (! $actor->checkPassword($password)) {
|
||||
throw new NotAuthenticatedException;
|
||||
|
|
|
@ -31,7 +31,7 @@ class AccessTokenSerializer extends AbstractSerializer
|
|||
);
|
||||
}
|
||||
|
||||
$session = $this->request->getAttribute('session');
|
||||
$session = $this->request->attributes->get('session');
|
||||
|
||||
$agent = new Agent();
|
||||
$agent->setUserAgent($model->last_user_agent);
|
||||
|
|
|
@ -11,8 +11,8 @@ namespace Flarum\Frontend;
|
|||
|
||||
use Flarum\Api\Client;
|
||||
use Illuminate\Contracts\Container\Container;
|
||||
use Illuminate\Http\JsonResponse;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Http\Response;
|
||||
|
||||
class Frontend
|
||||
{
|
||||
|
@ -57,8 +57,8 @@ class Frontend
|
|||
);
|
||||
}
|
||||
|
||||
private function getResponseBody(Response $response): array
|
||||
private function getResponseBody(JsonResponse $response): array
|
||||
{
|
||||
return json_decode($response->content(), true);
|
||||
return $response->getData(true);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -15,6 +15,7 @@ use Laminas\Diactoros\ResponseFactory;
|
|||
use Laminas\Diactoros\ServerRequestFactory;
|
||||
use Laminas\Diactoros\StreamFactory;
|
||||
use Laminas\Diactoros\UploadedFileFactory;
|
||||
use Psr\Http\Message\ResponseInterface;
|
||||
use Psr\Http\Message\ServerRequestInterface;
|
||||
use Symfony\Bridge\PsrHttpMessage\Factory\HttpFoundationFactory;
|
||||
use Symfony\Bridge\PsrHttpMessage\Factory\PsrHttpFactory;
|
||||
|
@ -80,7 +81,7 @@ class RequestUtil
|
|||
return $psrHttpFactory->createRequest($request);
|
||||
}
|
||||
|
||||
public static function responseToSymfony(\Psr\Http\Message\ResponseInterface $response): SymfonyResponse
|
||||
public static function responseToSymfony(ResponseInterface $response): SymfonyResponse
|
||||
{
|
||||
return (new HttpFoundationFactory())->createResponse($response);
|
||||
}
|
||||
|
|
|
@ -19,7 +19,7 @@ class PostCreationThrottler
|
|||
|
||||
public function __invoke(Request $request): ?bool
|
||||
{
|
||||
if (! $request->routeIs('discussions.create', 'posts.create')) {
|
||||
if (! $request->routeIs('api.discussions.create', 'api.posts.create')) {
|
||||
return null;
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue
Block a user