Skip to content
docsv0.31.1

XhtmlComponentCompiler

Compiles a fragment of `<milpa:*>` / `<milpa-*>` XHTML markup into rendered HTML by parsing it as XML, resolving each Milpa element to its registered component + renderer, and recursively rendering non-Milpa children as plain escaped/passthrough markup. This is the bridge between authoring component trees as markup and the {@see ComponentRendererInterface} pipeline every renderer in this package implements. Declared views (greenhouse decisions/0211): every renderer met while compiling — root or nested — that implements {@see DeclaresClientAssets} contributes its {@see ClientAssets}; they are merged (deduplicated by URL, first-seen order) into the result's {@see RenderResult::clientAssets()}, so the host emits each file once through `LiveBoot::html()`. The legacy string-keyed {@see RenderResult::$assets} bag keeps its `array_merge` semantics untouched.

XhtmlComponentCompiler::__construct()

public function __construct(Milpa\Live\Contracts\Component\ComponentRegistryInterface $components, Milpa\Live\Rendering\ComponentRendererRegistry|array $renderers, array $defaults = []):

Parameters

Parameters of __construct()
NameTypeDescription
$componentsMilpa\Live\Contracts\Component\ComponentRegistryInterface
$renderers(array<string, ComponentRendererInterface> | ComponentRendererRegistry)component name => renderer, or a registry answering {@see ComponentRendererRegistry::resolveFor()} per name (its `registerFor()`ed renderers only — like the array, no fallback)
$defaultsarray<string, array<string, mixed>>

XhtmlComponentCompiler::compile()

public function compile(string $markup, Milpa\Live\ValueObjects\ComponentContext $context): Milpa\Live\ValueObjects\RenderResult

Compiles markup that MUST contain exactly one root Milpa component element; throws `RuntimeException` for zero or more than one root.

Parameters

Parameters of compile()
NameTypeDescription
$markupstring
$contextMilpa\Live\ValueObjects\ComponentContext

XhtmlComponentCompiler::compileFragment()

public function compileFragment(string $markup, Milpa\Live\ValueObjects\ComponentContext $context): Milpa\Live\ValueObjects\RenderResult

Compiles markup that may contain multiple sibling root Milpa component elements, concatenating their rendered output. The returned {@see RenderResult}'s `state`/`format` are taken from the first node rendered; `assets` are merged across every node (`array_merge`, legacy string keys), and the declared {@see ClientAssets} of every renderer met are merged by URL.

Parameters

Parameters of compileFragment()
NameTypeDescription
$markupstring
$contextMilpa\Live\ValueObjects\ComponentContext