Skip to content
docsv0.25.1

ComponentRendererRegistry

The default in-memory {@see ComponentRendererRegistryInterface}: resolves a renderer by target, preferring the most recently {@see register()}ed renderer that {@see ComponentRendererInterface::supportsTarget()} it. It is also the pair of a {@see \Milpa\Live\Runtime\CompositeComponentRegistry} (greenhouse decisions/0211): a renderer may be registered FOR a component name ({@see registerFor()}), and {@see resolveFor()} answers "who renders * this component at this target" — the per-name renderer when it supports the target, else nothing. The target-wide {@see resolve()} is a different question and is deliberately NOT its fallback: every shipped HTML renderer is single-family and throws for the rest, so handing a name to whatever renderer happens to support the target turns a missing registration into an uncaught exception in the endpoint instead of a null. A host with a general renderer registers it for each name it serves. That is how one live endpoint re-renders every plugin's components without a hand-wired name → renderer array — the registry answers exactly what the array did.

ComponentRendererRegistry::register()

public function register(Milpa\Live\Contracts\Rendering\ComponentRendererInterface $renderer): void

Registers `$renderer`, taking precedence over any already-registered renderer for the same target.

Parameters

Parameters of register()
NameTypeDescription
$rendererMilpa\Live\Contracts\Rendering\ComponentRendererInterface

ComponentRendererRegistry::registerFor()

public function registerFor(string $componentName, Milpa\Live\Contracts\Rendering\ComponentRendererInterface $renderer): void

Registers `$renderer` for the component named `$componentName` — it takes precedence, for that name, over any target-wide renderer and over any renderer registered for the name earlier.

Parameters

Parameters of registerFor()
NameTypeDescription
$componentNamestring
$rendererMilpa\Live\Contracts\Rendering\ComponentRendererInterface

ComponentRendererRegistry::resolve()

public function resolve(Milpa\Live\ValueObjects\RenderTarget $target): ?Milpa\Live\Contracts\Rendering\ComponentRendererInterface

Returns the most recently registered renderer that supports `$target`, or `null` if none does.

Parameters

Parameters of resolve()
NameTypeDescription
$targetMilpa\Live\ValueObjects\RenderTarget

ComponentRendererRegistry::resolveFor()

public function resolveFor(string $componentName, Milpa\Live\ValueObjects\RenderTarget $target): ?Milpa\Live\Contracts\Rendering\ComponentRendererInterface

The renderer for `$componentName` at `$target`: the most recently {@see registerFor()}ed one that supports the target, else `null`. A target-wide {@see register()}ed renderer is not consulted — see the class docblock for why.

Parameters

Parameters of resolveFor()
NameTypeDescription
$componentNamestring
$targetMilpa\Live\ValueObjects\RenderTarget