Skip to content
docsv0.1.0

CallbackDataSource

A {@see DataSourceInterface} backed by a caller-supplied `callable` — the escape hatch for a data source that isn't a fixed array (a database query, an HTTP call, …) without needing its own class per case.

CallbackDataSource::__construct()

public function __construct(string $name, ?mixed $callback):

`$callback`'s return is intentionally typed `mixed`, not narrowed to `DataSourceResult|array<int, array<string, mixed>>` — the callable itself is caller-supplied and unenforced at the type level (the property below is `mixed`), so {@see resolve()}'s runtime guard below is a real, reachable defense against a misbehaving callback, not dead code.

Parameters

Parameters of __construct()
NameTypeDescription
$namestring
$callbackcallable(DataSourceRequest): mixed

CallbackDataSource::supports()

public function supports(string $source): bool

True when `$source` matches this data source's registered name.

Parameters

Parameters of supports()
NameTypeDescription
$sourcestring

CallbackDataSource::resolve()

public function resolve(Milpa\Live\ValueObjects\DataSourceRequest $request): Milpa\Live\ValueObjects\DataSourceResult

Invokes the wrapped callback with `$request`; accepts either a {@see DataSourceResult} back (returned as-is) or a plain item array (wrapped in one).

Parameters

Parameters of resolve()
NameTypeDescription
$requestMilpa\Live\ValueObjects\DataSourceRequest

Throws

\RuntimeException If the callback returns anything else.