class ApiController implements ExtenderInterface

Methods

__construct(string $controllerClass)

No description

prepareDataQuery(callable|string $callback)

No description

prepareDataForSerialization(callable|string $callback)

No description

setSerializer(string $serializerClass, callable|string|null $callback = null)

Set the serializer that will serialize data for the endpoint.

addInclude($name, callable|string|null $callback = null)

Include the given relationship by default.

removeInclude($name, callable|string|null $callback = null)

Don't include the given relationship by default.

addOptionalInclude($name, callable|string|null $callback = null)

Make the given relationship available for inclusion.

removeOptionalInclude($name, callable|string|null $callback = null)

Don't allow the given relationship to be included.

setLimit(int $limit, callable|string|null $callback = null)

Set the default number of results.

setMaxLimit(int $max, callable|string|null $callback = null)

Set the maximum number of results.

addSortField(string|array $field, callable|string|null $callback = null)

Allow sorting results by the given field.

removeSortField(string|array $field, callable|string|null $callback = null)

Disallow sorting results by the given field.

setSort(array $sort, callable|string|null $callback = null)

Set the default sort order for the results.

load(string|string[] $relations)

Eager loads relationships needed for serializer logic.

loadWhere(string $relation, callable $callback)

Allows loading a relationship with additional query modification.

extend(Container $container, Extension $extension = null)

No description

Details

__construct(string $controllerClass)

Parameters

string $controllerClass

ApiController prepareDataQuery(callable|string $callback)

Parameters

callable|string $callback The callback can be a closure or an invokable class, and should accept: - $controller: An instance of this controller.

Return Value

ApiController

ApiController prepareDataForSerialization(callable|string $callback)

Parameters

callable|string $callback The callback can be a closure or an invokable class, and should accept: - $controller: An instance of this controller. - $data: Mixed, can be an array of data or an object (like an instance of Collection or AbstractModel). - $request: An instance of \Psr\Http\Message\ServerRequestInterface. - $document: An instance of \Tobscure\JsonApi\Document. The callable should return: - An array of additional data to merge with the existing array. Or a modified $data array.

Return Value

ApiController

ApiController setSerializer(string $serializerClass, callable|string|null $callback = null)

Set the serializer that will serialize data for the endpoint.

Parameters

string $serializerClass
callable|string|null $callback The optional callback can be a closure or an invokable class, and should accept: - $controller: An instance of this controller. The callable should return: - A boolean value to determine if this applies.

Return Value

ApiController

ApiController addInclude($name, callable|string|null $callback = null)

Include the given relationship by default.

Parameters

$name
callable|string|null $callback The optional callback can be a closure or an invokable class, and should accept: - $controller: An instance of this controller. The callable should return: - A boolean value to determine if this applies.

Return Value

ApiController

ApiController removeInclude($name, callable|string|null $callback = null)

Don't include the given relationship by default.

Parameters

$name
callable|string|null $callback The optional callback can be a closure or an invokable class, and should accept: - $controller: An instance of this controller. The callable should return: - A boolean value to determine if this applies.

Return Value

ApiController

ApiController addOptionalInclude($name, callable|string|null $callback = null)

Make the given relationship available for inclusion.

Parameters

$name
callable|string|null $callback The optional callback can be a closure or an invokable class, and should accept: - $controller: An instance of this controller. The callable should return: - A boolean value to determine if this applies.

Return Value

ApiController

ApiController removeOptionalInclude($name, callable|string|null $callback = null)

Don't allow the given relationship to be included.

Parameters

$name
callable|string|null $callback The optional callback can be a closure or an invokable class, and should accept: - $controller: An instance of this controller. The callable should return: - A boolean value to determine if this applies.

Return Value

ApiController

ApiController setLimit(int $limit, callable|string|null $callback = null)

Set the default number of results.

Parameters

int $limit
callable|string|null $callback The optional callback can be a closure or an invokable class, and should accept: - $controller: An instance of this controller. The callable should return: - A boolean value to determine if this applies.

Return Value

ApiController

ApiController setMaxLimit(int $max, callable|string|null $callback = null)

Set the maximum number of results.

Parameters

int $max
callable|string|null $callback The optional callback can be a closure or an invokable class, and should accept: - $controller: An instance of this controller. The callable should return: - A boolean value to determine if this applies.

Return Value

ApiController

ApiController addSortField(string|array $field, callable|string|null $callback = null)

Allow sorting results by the given field.

Parameters

string|array $field
callable|string|null $callback The optional callback can be a closure or an invokable class, and should accept: - $controller: An instance of this controller. The callable should return: - A boolean value to determine if this applies.

Return Value

ApiController

ApiController removeSortField(string|array $field, callable|string|null $callback = null)

Disallow sorting results by the given field.

Parameters

string|array $field
callable|string|null $callback The optional callback can be a closure or an invokable class, and should accept: - $controller: An instance of this controller. The callable should return: - A boolean value to determine if this applies.

Return Value

ApiController

ApiController setSort(array $sort, callable|string|null $callback = null)

Set the default sort order for the results.

Parameters

array $sort
callable|string|null $callback The optional callback can be a closure or an invokable class, and should accept: - $controller: An instance of this controller. The callable should return: - A boolean value to determine if this applies.

Return Value

ApiController

ApiController load(string|string[] $relations)

Eager loads relationships needed for serializer logic.

First level relationships will be loaded regardless of whether they are included in the response. Sublevel relationships will only be loaded if the upper level was included or manually loaded.

Parameters

string|string[] $relations

Return Value

ApiController

ApiController loadWhere(string $relation, callable $callback)

Allows loading a relationship with additional query modification.

Parameters

string $relation
callable $callback

Return Value

ApiController

extend(Container $container, Extension $extension = null)

Parameters

Container $container
Extension $extension