1
0
mirror of https://github.com/flarum/core.git synced 2025-10-16 17:27:05 +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:
Toby Zerner
2015-05-02 08:56:43 +09:30
parent 5ea864ba89
commit a426fa6560
23 changed files with 673 additions and 378 deletions

View File

@@ -11,22 +11,13 @@ use Closure;
*/
abstract class BaseSerializer extends SerializerAbstract
{
/**
* The actor who is requesting the serialized objects.
*
* @var \Flarum\Support\Actor
*/
protected static $actor;
protected $actor;
/**
* Set the actor who is requesting the serialized objects.
*
* @param \Flarum\Support\Actor $actor
* @return void
*/
public static function setActor(Actor $actor)
public function __construct(Actor $actor, $include = null, $link = null)
{
static::$actor = $actor;
parent::__construct($include, $link);
$this->actor = $actor;
}
/**
@@ -70,7 +61,7 @@ abstract class BaseSerializer extends SerializerAbstract
$class = get_class(is_object($data) ? $data : $model->$relation()->getRelated());
$serializer = $serializer[$class];
}
$serializer = new $serializer($links);
$serializer = new $serializer($this->actor, $links);
return $many ? $serializer->collection($data) : $serializer->resource($data);
};
}