Define static properties on SerializeAction subclasses

Explained in 8a0cf2dcba0703f9aebf2d82591f2d95f0dc7afa.

If we ever come up with a better way of doing this it should be easy to
change over, since modification of these properties by extensions is
abstracted by an Extend API.
This commit is contained in:
Toby Zerner 2015-06-18 12:24:18 +09:30
parent 263126f14c
commit 6f7a06820d
19 changed files with 498 additions and 138 deletions

View File

@ -19,17 +19,12 @@ class IndexAction extends SerializeCollectionAction
protected $activity;
/**
* The name of the serializer class to output results with.
*
* @var string
* @inheritdoc
*/
public static $serializer = 'Flarum\Api\Serializers\ActivitySerializer';
/**
* The relationships that are available to be included, and which ones are
* included by default.
*
* @var array
* @inheritdoc
*/
public static $include = [
'subject' => true,
@ -38,12 +33,30 @@ class IndexAction extends SerializeCollectionAction
];
/**
* The relations that are linked by default.
*
* @var array
* @inheritdoc
*/
public static $link = ['user'];
/**
* @inheritdoc
*/
public static $limitMax = 50;
/**
* @inheritdoc
*/
public static $limit = 20;
/**
* @inheritdoc
*/
public static $sortFields = [];
/**
* @inheritdoc
*/
public static $sort;
/**
* Instantiate the action.
*

View File

@ -24,17 +24,12 @@ class CreateAction extends BaseCreateAction
protected $forum;
/**
* The name of the serializer class to output results with.
*
* @var string
* @inheritdoc
*/
public static $serializer = 'Flarum\Api\Serializers\DiscussionSerializer';
/**
* The relationships that are available to be included, and which ones are
* included by default.
*
* @var array
* @inheritdoc
*/
public static $include = [
'posts' => true,
@ -44,6 +39,31 @@ class CreateAction extends BaseCreateAction
'lastPost' => true
];
/**
* @inheritdoc
*/
public static $link = [];
/**
* @inheritdoc
*/
public static $limitMax = 50;
/**
* @inheritdoc
*/
public static $limit = 20;
/**
* @inheritdoc
*/
public static $sortFields = [];
/**
* @inheritdoc
*/
public static $sort;
/**
* Instantiate the action.
*

View File

@ -24,17 +24,12 @@ class IndexAction extends SerializeCollectionAction
protected $url;
/**
* The name of the serializer class to output results with.
*
* @var string
* @inheritdoc
*/
public static $serializer = 'Flarum\Api\Serializers\DiscussionSerializer';
/**
* The relationships that are available to be included, and which ones are
* included by default.
*
* @var array
* @inheritdoc
*/
public static $include = [
'startUser' => true,
@ -47,12 +42,30 @@ class IndexAction extends SerializeCollectionAction
];
/**
* The fields that are available to be sorted by.
*
* @var array
* @inheritdoc
*/
public static $link = [];
/**
* @inheritdoc
*/
public static $limitMax = 50;
/**
* @inheritdoc
*/
public static $limit = 20;
/**
* @inheritdoc
*/
public static $sortFields = ['lastTime', 'commentsCount', 'startTime'];
/**
* @inheritdoc
*/
public static $sort;
/**
* Instantiate the action.
*

View File

@ -22,17 +22,12 @@ class ShowAction extends SerializeResourceAction
protected $posts;
/**
* The name of the serializer class to output results with.
*
* @var string
* @inheritdoc
*/
public static $serializer = 'Flarum\Api\Serializers\DiscussionSerializer';
/**
* The relationships that are available to be included, and which ones are
* included by default.
*
* @var array
* @inheritdoc
*/
public static $include = [
'startUser' => false,
@ -47,23 +42,27 @@ class ShowAction extends SerializeResourceAction
];
/**
* The relations that are linked by default.
*
* @var array
* @inheritdoc
*/
public static $link = ['posts', 'posts.discussion'];
/**
* The fields that are available to be sorted by.
*
* @var array
* @inheritdoc
*/
public static $limitMax = 50;
/**
* @inheritdoc
*/
public static $limit = 20;
/**
* @inheritdoc
*/
public static $sortFields = ['time'];
/**
* The default sort field and order to user.
*
* @var string
* @inheritdoc
*/
public static $sort = ['time' => 'asc'];

View File

@ -15,22 +15,43 @@ class UpdateAction extends SerializeResourceAction
protected $bus;
/**
* The name of the serializer class to output results with.
*
* @var string
* @inheritdoc
*/
public static $serializer = 'Flarum\Api\Serializers\DiscussionSerializer';
/**
* The relations that are included by default.
*
* @var array
* @inheritdoc
*/
public static $include = [
'addedPosts' => true,
'addedPosts.user' => true
];
/**
* @inheritdoc
*/
public static $link = [];
/**
* @inheritdoc
*/
public static $limitMax = 50;
/**
* @inheritdoc
*/
public static $limit = 20;
/**
* @inheritdoc
*/
public static $sortFields = [];
/**
* @inheritdoc
*/
public static $sort;
/**
* Instantiate the action.
*

View File

@ -7,12 +7,40 @@ use Tobscure\JsonApi\Document;
class ShowAction extends SerializeResourceAction
{
/**
* The name of the serializer class to output results with.
*
* @var string
* @inheritdoc
*/
public static $serializer = 'Flarum\Api\Serializers\ForumSerializer';
/**
* @inheritdoc
*/
public static $include = [];
/**
* @inheritdoc
*/
public static $link = [];
/**
* @inheritdoc
*/
public static $limitMax = 50;
/**
* @inheritdoc
*/
public static $limit = 20;
/**
* @inheritdoc
*/
public static $sortFields = [];
/**
* @inheritdoc
*/
public static $sort;
/**
* Get the forum, ready to be serialized and assigned to the JsonApi
* response.

View File

@ -8,12 +8,40 @@ use Tobscure\JsonApi\Document;
class IndexAction extends SerializeCollectionAction
{
/**
* The name of the serializer class to output results with.
*
* @var string
* @inheritdoc
*/
public static $serializer = 'Flarum\Api\Serializers\GroupSerializer';
/**
* @inheritdoc
*/
public static $include = [];
/**
* @inheritdoc
*/
public static $link = [];
/**
* @inheritdoc
*/
public static $limitMax = 50;
/**
* @inheritdoc
*/
public static $limit = 20;
/**
* @inheritdoc
*/
public static $sortFields = [];
/**
* @inheritdoc
*/
public static $sort;
/**
* Get the groups, ready to be serialized and assigned to the document
* response.

View File

@ -14,16 +14,12 @@ class IndexAction extends SerializeCollectionAction
protected $notifications;
/**
* The name of the serializer class to output results with.
*
* @var string
* @inheritdoc
*/
public static $serializer = 'Flarum\Api\Serializers\NotificationSerializer';
/**
* The relations that are included by default.
*
* @var array
* @inheritdoc
*/
public static $include = [
'sender' => true,
@ -32,19 +28,30 @@ class IndexAction extends SerializeCollectionAction
];
/**
* The maximum number of records that can be requested.
*
* @var integer
* @inheritdoc
*/
public static $link = [];
/**
* @inheritdoc
*/
public static $limitMax = 50;
/**
* The number of records included by default.
*
* @var integer
* @inheritdoc
*/
public static $limit = 10;
/**
* @inheritdoc
*/
public static $sortFields = [];
/**
* @inheritdoc
*/
public static $sort;
/**
* Instantiate the action.
*

View File

@ -14,12 +14,40 @@ class UpdateAction extends SerializeResourceAction
protected $bus;
/**
* The name of the serializer class to output results with.
*
* @var string
* @inheritdoc
*/
public static $serializer = 'Flarum\Api\Serializers\NotificationSerializer';
/**
* @inheritdoc
*/
public static $include = [];
/**
* @inheritdoc
*/
public static $link = [];
/**
* @inheritdoc
*/
public static $limitMax = 50;
/**
* @inheritdoc
*/
public static $limit = 20;
/**
* @inheritdoc
*/
public static $sortFields = [];
/**
* @inheritdoc
*/
public static $sort;
/**
* Instantiate the action.
*

View File

@ -14,16 +14,42 @@ class CreateAction extends BaseCreateAction
protected $bus;
/**
* The name of the serializer class to output results with.
*
* @var string
* @inheritdoc
*/
public static $serializer = 'Flarum\Api\Serializers\PostSerializer';
/**
* @inheritdoc
*/
public static $include = [
'user' => true
];
/**
* @inheritdoc
*/
public static $link = [];
/**
* @inheritdoc
*/
public static $limitMax = 50;
/**
* @inheritdoc
*/
public static $limit = 20;
/**
* @inheritdoc
*/
public static $sortFields = [];
/**
* @inheritdoc
*/
public static $sort;
/**
* Instantiate the action.
*

View File

@ -15,17 +15,12 @@ class IndexAction extends SerializeCollectionAction
protected $posts;
/**
* The name of the serializer class to output results with.
*
* @var string
* @inheritdoc
*/
public static $serializer = 'Flarum\Api\Serializers\PostSerializer';
/**
* The relationships that are available to be included, and which ones are
* included by default.
*
* @var array
* @inheritdoc
*/
public static $include = [
'user' => true,
@ -35,6 +30,31 @@ class IndexAction extends SerializeCollectionAction
'discussion' => true
];
/**
* @inheritdoc
*/
public static $link = [];
/**
* @inheritdoc
*/
public static $limitMax = 50;
/**
* @inheritdoc
*/
public static $limit = 20;
/**
* @inheritdoc
*/
public static $sortFields = [];
/**
* @inheritdoc
*/
public static $sort;
/**
* Instantiate the action.
*

View File

@ -14,17 +14,12 @@ class ShowAction extends SerializeResourceAction
protected $posts;
/**
* The name of the serializer class to output results with.
*
* @var string
* @inheritdoc
*/
public static $serializer = 'Flarum\Api\Serializers\PostSerializer';
/**
* The relationships that are available to be included, and which ones are
* included by default.
*
* @var array
* @inheritdoc
*/
public static $include = [
'user' => true,
@ -34,6 +29,31 @@ class ShowAction extends SerializeResourceAction
'discussion' => false
];
/**
* @inheritdoc
*/
public static $link = [];
/**
* @inheritdoc
*/
public static $limitMax = 50;
/**
* @inheritdoc
*/
public static $limit = 20;
/**
* @inheritdoc
*/
public static $sortFields = [];
/**
* @inheritdoc
*/
public static $sort;
/**
* Instantiate the action.
*

View File

@ -14,12 +14,40 @@ class UpdateAction extends SerializeResourceAction
protected $bus;
/**
* The name of the serializer class to output results with.
*
* @var string
* @inheritdoc
*/
public static $serializer = 'Flarum\Api\Serializers\PostSerializer';
/**
* @inheritdoc
*/
public static $include = [];
/**
* @inheritdoc
*/
public static $link = [];
/**
* @inheritdoc
*/
public static $limitMax = 50;
/**
* @inheritdoc
*/
public static $limit = 20;
/**
* @inheritdoc
*/
public static $sortFields = [];
/**
* @inheritdoc
*/
public static $sort;
/**
* Instantiate the action.
*

View File

@ -23,12 +23,40 @@ class CreateAction extends BaseCreateAction
protected $forum;
/**
* The name of the serializer class to output results with.
*
* @var string
* @inheritdoc
*/
public static $serializer = 'Flarum\Api\Serializers\UserSerializer';
/**
* @inheritdoc
*/
public static $include = [];
/**
* @inheritdoc
*/
public static $link = [];
/**
* @inheritdoc
*/
public static $limitMax = 50;
/**
* @inheritdoc
*/
public static $limit = 20;
/**
* @inheritdoc
*/
public static $sortFields = [];
/**
* @inheritdoc
*/
public static $sort;
/**
* Instantiate the action.
*

View File

@ -14,9 +14,7 @@ class DeleteAvatarAction extends SerializeResourceAction
protected $bus;
/**
* The name of the serializer class to output results with.
*
* @var string
* @inheritdoc
*/
public static $serializer = 'Flarum\Api\Serializers\UserSerializer';

View File

@ -23,6 +23,43 @@ class IndexAction extends SerializeCollectionAction
*/
protected $url;
/**
* @inheritdoc
*/
public static $serializer = 'Flarum\Api\Serializers\UserSerializer';
/**
* @inheritdoc
*/
public static $include = [
'groups' => true
];
/**
* @inheritdoc
*/
public static $link = [];
/**
* @inheritdoc
*/
public static $limitMax = 50;
/**
* @inheritdoc
*/
public static $limit = 20;
/**
* @inheritdoc
*/
public static $sortFields = ['username', 'postsCount', 'discussionsCount', 'lastSeenTime', 'joinTime'];
/**
* @inheritdoc
*/
public static $sort;
/**
* Instantiate the action.
*
@ -35,30 +72,6 @@ class IndexAction extends SerializeCollectionAction
$this->url = $url;
}
/**
* The name of the serializer class to output results with.
*
* @var string
*/
public static $serializer = 'Flarum\Api\Serializers\UserSerializer';
/**
* The relationships that are available to be included, and which ones are
* included by default.
*
* @var array
*/
public static $include = [
'groups' => true
];
/**
* The fields that are available to be sorted by.
*
* @var array
*/
public static $sortFields = ['username', 'postsCount', 'discussionsCount', 'lastSeenTime', 'joinTime'];
/**
* Get the user results, ready to be serialized and assigned to the
* document response.
@ -77,15 +90,11 @@ class IndexAction extends SerializeCollectionAction
$results = $this->searcher->search($criteria, $request->limit, $request->offset, $request->include);
if (($total = $results->getTotal()) !== null) {
$document->addMeta('total', $total);
}
static::addPaginationLinks(
$document,
$request,
$this->url->toRoute('flarum.api.users.index'),
$total ?: $results->areMoreResults()
$results->areMoreResults()
);
return $results->getUsers();

View File

@ -13,24 +13,42 @@ class ShowAction extends SerializeResourceAction
protected $users;
/**
* The name of the serializer class to output results with.
*
* @var string
* @inheritdoc
*/
public static $serializer = 'Flarum\Api\Serializers\CurrentUserSerializer';
/**
* The relationships that are available to be included, and which ones are
* included by default.
*
* @var array
* @inheritdoc
*/
public static $include = [
'groups' => true
];
/**
* @inheritdoc
*/
public static $link = [];
/**
* @inheritdoc
*/
public static $limitMax = 50;
/**
* @inheritdoc
*/
public static $limit = 20;
/**
* @inheritdoc
*/
public static $sortFields = [];
/**
* @inheritdoc
*/
public static $sort;
/**
* Instantiate the action.
*

View File

@ -14,12 +14,40 @@ class UpdateAction extends SerializeResourceAction
protected $bus;
/**
* The name of the serializer class to output results with.
*
* @var string
* @inheritdoc
*/
public static $serializer = 'Flarum\Api\Serializers\UserSerializer';
/**
* @inheritdoc
*/
public static $include = [];
/**
* @inheritdoc
*/
public static $link = [];
/**
* @inheritdoc
*/
public static $limitMax = 50;
/**
* @inheritdoc
*/
public static $limit = 20;
/**
* @inheritdoc
*/
public static $sortFields = [];
/**
* @inheritdoc
*/
public static $sort;
/**
* Instantiate the action.
*

View File

@ -14,12 +14,40 @@ class UploadAvatarAction extends SerializeResourceAction
protected $bus;
/**
* The name of the serializer class to output results with.
*
* @var string
* @inheritdoc
*/
public static $serializer = 'Flarum\Api\Serializers\UserSerializer';
/**
* @inheritdoc
*/
public static $include = [];
/**
* @inheritdoc
*/
public static $link = [];
/**
* @inheritdoc
*/
public static $limitMax = 50;
/**
* @inheritdoc
*/
public static $limit = 20;
/**
* @inheritdoc
*/
public static $sortFields = [];
/**
* @inheritdoc
*/
public static $sort;
/**
* Instantiate the action.
*