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
| Name | Type | Description |
|---|---|---|
| $name | string | |
| $callback | callable(DataSourceRequest): mixed |
CallbackDataSource::supports()
public function supports(string $source): boolTrue when `$source` matches this data source's registered name.
Parameters
| Name | Type | Description |
|---|---|---|
| $source | string |
CallbackDataSource::resolve()
public function resolve(Milpa\Live\ValueObjects\DataSourceRequest $request): Milpa\Live\ValueObjects\DataSourceResultInvokes the wrapped callback with `$request`; accepts either a {@see DataSourceResult} back (returned as-is) or a plain item array (wrapped in one).
Parameters
| Name | Type | Description |
|---|---|---|
| $request | Milpa\Live\ValueObjects\DataSourceRequest |
Throws
\RuntimeException If the callback returns anything else.