KMP PHP API Reference

ApiDataRegistry
in package

Registry for API response data providers.

Plugins register callbacks that inject additional data into API detail responses. Follows the same registration pattern as ViewCellRegistry but for REST API endpoints instead of view cells.

Table of Contents

Properties

$initialized  : bool
$providers  : array<string, array{callback: callable, routes: array}>

Methods

clear()  : void
Clear all providers (for testing).
collect()  : array<string, mixed>
Collect additional data from all matching providers.
getRegisteredSources()  : array<string|int, string>
Get registered source names.
register()  : void
Register an API data provider.
unregister()  : void
Remove a registered provider.
ensureInitialized()  : void
Ensure initialized.
matchesRoute()  : bool

Properties

$providers

private static array<string, array{callback: callable, routes: array}> $providers = []

Methods

clear()

Clear all providers (for testing).

public static clear() : void

collect()

Collect additional data from all matching providers.

public static collect(string $controller, string $action, mixed $entity) : array<string, mixed>
Parameters
$controller : string

Controller name (e.g., 'Branches')

$action : string

Action name (e.g., 'view')

$entity : mixed

The primary entity being returned

Return values
array<string, mixed>

Merged provider data keyed by provider-chosen keys

getRegisteredSources()

Get registered source names.

public static getRegisteredSources() : array<string|int, string>
Return values
array<string|int, string>

register()

Register an API data provider.

public static register(string $source, callable $callback, array<string|int, mixed> $routes) : void
Parameters
$source : string

Source identifier (e.g., 'Officers', 'Awards')

$callback : callable

fn(string $controller, string $action, mixed $entity): array

$routes : array<string|int, mixed>

List of [controller, action] pairs this provider applies to

unregister()

Remove a registered provider.

public static unregister(string $source) : void
Parameters
$source : string

ensureInitialized()

Ensure initialized.

private static ensureInitialized() : void

matchesRoute()

private static matchesRoute(array<string|int, mixed> $routes, string $controller, string $action) : bool
Parameters
$routes : array<string|int, mixed>

Registered route patterns

$controller : string

Current controller

$action : string

Current action

Return values
bool

        
On this page

Search results