mirror of
https://github.com/flarum/core.git
synced 2025-10-22 04:06:37 +02:00
Update API action architecture
- An API action handles a Flarum\Api\Request, which is a simple object containing an array of params, the actor, and optionally an HTTP request object - Most API actions use SerializeAction as a base, which parses request input according to the JSON-API spec (creates a JsonApiRequest object), runs the child class method to get data, then serializes it and assigns it to a JsonApiResponse (standard HTTP response with a Tobscure\JsonApi\Document as content) - The JSON-API request input parsing is subject to restrictions as defined by public static properties on the action (i.e. extensible) - Also the actor is given to the serializer instance now, instead of being a static property
This commit is contained in:
@@ -1,11 +1,25 @@
|
||||
<?php
|
||||
|
||||
use Flarum\Api\Request;
|
||||
|
||||
$action = function ($class) {
|
||||
return function () use ($class) {
|
||||
$action = $this->app->make($class);
|
||||
$request = $this->app['request']->instance();
|
||||
$parameters = $this->app['router']->current()->parameters();
|
||||
return $action->handle($request, $parameters);
|
||||
|
||||
$httpRequest = $this->app['request']->instance();
|
||||
$routeParams = $this->app['router']->current()->parameters();
|
||||
$actor = $this->app['Flarum\Support\Actor'];
|
||||
|
||||
if (str_contains($httpRequest->header('CONTENT_TYPE'), 'application/vnd.api+json')) {
|
||||
$input = $httpRequest->json();
|
||||
} else {
|
||||
$input = $httpRequest->all();
|
||||
}
|
||||
$input = array_merge($input, $routeParams);
|
||||
|
||||
$request = new Request($input, $actor, $httpRequest);
|
||||
|
||||
return $action->handle($request);
|
||||
};
|
||||
};
|
||||
|
||||
|
Reference in New Issue
Block a user