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.
XhtmlComponentCompiler::__construct()
public function __construct(Milpa\Live\Contracts\Component\ComponentRegistryInterface $components, array $renderers, array $defaults = []):Parameters
| Name | Type | Description |
|---|---|---|
| $components | Milpa\Live\Contracts\Component\ComponentRegistryInterface | |
| $renderers | array<string, ComponentRendererInterface> | |
| $defaults | array<string, array<string, mixed>> |
XhtmlComponentCompiler::compile()
public function compile(string $markup, Milpa\Live\ValueObjects\ComponentContext $context): Milpa\Live\ValueObjects\RenderResultCompiles markup that MUST contain exactly one root Milpa component element; throws `RuntimeException` for zero or more than one root.
Parameters
| Name | Type | Description |
|---|---|---|
| $markup | string | |
| $context | Milpa\Live\ValueObjects\ComponentContext |
XhtmlComponentCompiler::compileFragment()
public function compileFragment(string $markup, Milpa\Live\ValueObjects\ComponentContext $context): Milpa\Live\ValueObjects\RenderResultCompiles 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.
Parameters
| Name | Type | Description |
|---|---|---|
| $markup | string | |
| $context | Milpa\Live\ValueObjects\ComponentContext |