framework/src/Api/Actions/SerializeCollectionAction.php
Toby Zerner a426fa6560 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
2015-05-02 08:56:43 +09:30

19 lines
489 B
PHP

<?php namespace Flarum\Api\Actions;
use Tobscure\JsonApi\SerializerInterface;
abstract class SerializeCollectionAction extends SerializeAction
{
/**
* Serialize the data as appropriate.
*
* @param \Tobscure\JsonApi\SerializerInterface $serializer
* @param array $data
* @return \Tobscure\JsonApi\Elements\Collection
*/
protected function serialize(SerializerInterface $serializer, $data)
{
return $serializer->collection($data);
}
}