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)

<p>Set the serializer that will serialize data for the endpoint.</p>

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

<p>Include the given relationship by default.</p>

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

<p>Don't include the given relationship by default.</p>

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

<p>Make the given relationship available for inclusion.</p>

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

<p>Don't allow the given relationship to be included.</p>

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

<p>Set the default number of results.</p>

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

<p>Set the maximum number of results.</p>

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

<p>Allow sorting results by the given field.</p>

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

<p>Disallow sorting results by the given field.</p>

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

<p>Set the default sort order for the results.</p>

load(string|string[] $relations)

<p>Eager loads relationships needed for serializer logic.</p>

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

No description

Details

__construct(string $controllerClass)

Parameters

string $controllerClass

ApiController prepareDataQuery(callable|string $callback)

Parameters

callable|string $callback <p>The callback can be a closure or an invokable class, and should accept:</p> <ul> <li>$controller: An instance of this controller.</li> </ul>

Return Value

ApiController

ApiController prepareDataForSerialization(callable|string $callback)

Parameters

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

Return Value

ApiController

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

<p>Set the serializer that will serialize data for the endpoint.</p>

Parameters

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

Return Value

ApiController

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

<p>Include the given relationship by default.</p>

Parameters

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

Return Value

ApiController

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

<p>Don't include the given relationship by default.</p>

Parameters

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

Return Value

ApiController

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

<p>Make the given relationship available for inclusion.</p>

Parameters

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

Return Value

ApiController

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

<p>Don't allow the given relationship to be included.</p>

Parameters

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

Return Value

ApiController

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

<p>Set the default number of results.</p>

Parameters

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

Return Value

ApiController

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

<p>Set the maximum number of results.</p>

Parameters

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

Return Value

ApiController

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

<p>Allow sorting results by the given field.</p>

Parameters

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

Return Value

ApiController

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

<p>Disallow sorting results by the given field.</p>

Parameters

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

Return Value

ApiController

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

<p>Set the default sort order for the results.</p>

Parameters

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

Return Value

ApiController

ApiController load(string|string[] $relations)

<p>Eager loads relationships needed for serializer logic.</p>

<p>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.</p>

Parameters

string|string[] $relations

Return Value

ApiController

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

Parameters

Container $container
Extension $extension