Skip to content
docsv0.1.0

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

Parameters of __construct()
NameTypeDescription
$componentsMilpa\Live\Contracts\Component\ComponentRegistryInterface
$renderersarray<string, ComponentRendererInterface>
$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.

Parameters

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