PHP API: IR/Node

Classes in the IR/Node namespace.

ComponentNode

Source: ComponentNode.php

IR node for mounting a component template with props and slots.

The template node is reused as the component body, while props and slots are passed as runtime inputs for each component instance.

Group: IR/Node

Example

PHP

$node = new ComponentNode(
    $cardTemplate,
    ['title' => Expr::val('Docs')],
    ['default' => [new TextNode('Body')]]
);

Methods

__construct

PHP

public function __construct(
        public readonly Node $template,
        public readonly array $props = [],
        public readonly array $slots = [],
        public readonly ?Expr $key = null,
    ) 

Build a component IR node.

Parameters

  • Node $template Component template node.
  • array<string, Expr> $props Component prop expressions.
  • array<string, array<int, Node>> $slots Slot content keyed by slot name.
  • Expr|null $key Optional stable key expression.

collectAtoms

PHP

public function collectAtoms(callable $collect): void

Collect atom-related dependencies used by template, props, slots, and key.

Parameters

  • callable $collect Collector callback that receives dependency nodes.

Returns: void

jsonSerialize

PHP

public function jsonSerialize(): mixed

Encode this component node as runtime IR payload.

Returns: array<string, mixed>

withProp

PHP

public function withProp(string $name, Expr $expr): self 

Return a cloned component node with one prop updated.

Parameters

  • string $name Prop name.
  • Expr $expr Prop expression.

Returns: self

withSlots

PHP

public function withSlots(Node ...$slots): self 

Return a cloned component node with slot children replaced.

Returns: self

EffectNode

Source: EffectNode.php

IR node for declarative effects.

Binds one or more triggers to one or more runtime actions, optionally scoped to a specific effect target.

Group: IR/Node

Example

PHP

$node = new EffectNode(
    [$trigger],
    [$action]
);

Methods

__construct

PHP

public function __construct(
        public readonly array $triggers,
        public readonly array $actions,
        public readonly ?EffectTarget $target = null
    ) 

Build an effect IR node.

Parameters

  • array<int, EffectTrigger> $triggers Effect trigger list.
  • array<int, Action> $actions Effect action list.
  • EffectTarget|null $target Optional effect target.

collectAtoms

PHP

public function collectAtoms(callable $collect): void

Collect atom dependencies referenced by actions and watch triggers.

Parameters

  • callable $collect Collector callback that receives dependency nodes.

Returns: void

jsonSerialize

PHP

public function jsonSerialize(): array

Encode this effect node as runtime IR payload.

Returns: array<string, mixed>

ElNode

Source: ElNode.php

IR node for a standard HTML element.

Stores element tag, normalized props helpers, child nodes, and optional render target metadata.

Group: IR/Node

Example

PHP

$node = new ElNode(
    'button',
    [['attrs', ['type' => 'button']], ['cls', 'btn btn-primary']],
    [new TextNode('Save')]
);

Methods

__construct

PHP

public function __construct(
        public string $tag,
        public array $props = [],
        public array $children = [],
        public ?array $render = null
    ) 

Build an element IR node.

Parameters

  • string $tag Element tag name.
  • array<string, mixed> $props Props helper payload.
  • array<int, Node> $children Child IR nodes.
  • array<string, string>|null $render Optional render metadata.

collectAtoms

PHP

public function collectAtoms(callable $collect): void

Collect atom-related dependencies referenced by this node.

Parameters

  • callable $collect Collector callback that receives dependency nodes.

Returns: void

jsonSerialize

PHP

public function jsonSerialize(): mixed 

Encode this node as runtime IR payload.

Returns: array<string, mixed>

encodeProps

PHP

private function encodeProps(array $props): array 

Normalize props into the runtime wire format.

Parameters

  • array<string, mixed> $props

Returns: array<string, mixed>

FragmentNode

Source: FragmentNode.php

IR node for grouping children without creating a wrapper element.

Fragment nodes are transparent at the DOM level and only serve as a structural container in the IR tree.

Group: IR/Node

Example

PHP

$node = new FragmentNode([
    new TextNode('A'),
    new TextNode('B'),
]);

Methods

__construct

PHP

public function __construct(public array $children)
    

Build a fragment IR node.

Parameters

  • array<int, Node> $children Child nodes rendered in sequence.

collectAtoms

PHP

public function collectAtoms(callable $collect): void

Collect atom dependencies from child nodes.

Parameters

  • callable $collect Collector callback that receives dependency nodes.

Returns: void

jsonSerialize

PHP

public function jsonSerialize(): mixed

Encode this fragment node as runtime IR payload.

Returns: array<string, mixed>

HtmlNode

Source: HtmlNode.php

IR node for trusted/raw HTML content.

Accepts either a static string or an expression resolved at runtime.

Group: IR/Node

Example

PHP

$node = new HtmlNode('<strong>Hello</strong>');

Methods

__construct

PHP

public function __construct(public Expr|string $value) 

Build an HTML node.

Parameters

  • Expr|string $value Raw HTML value or expression.

jsonSerialize

PHP

public function jsonSerialize(): mixed 

Encode this HTML node as runtime IR payload.

Returns: array<string, mixed>

LinkNode

Source: LinkNode.php

IR node for declarative navigation links.

Encodes destination expression, link props, and child nodes for runtime navigation handling.

Group: IR/Node

Example

PHP

$node = new LinkNode(
    Expr::val('/docs'),
    [['cls', 'link-light']],
    [new TextNode('Docs')]
);

Methods

__construct

PHP

public function __construct(
        public Expr $to,
        public array $props = [],
        public array $children = [],
    ) 

Build a link IR node.

Parameters

  • Expr $to Destination expression.
  • array<int, mixed> $props Link props helper payload.
  • array<int, Node> $children Child IR nodes.

jsonSerialize

PHP

public function jsonSerialize(): mixed 

Encode this link node as runtime IR payload.

Returns: array<string, mixed>

ListNode

Source: ListNode.php

IR node for list/repeat rendering.

Repeats a template node for each item in an items expression with a key expression used for stable identity.

Group: IR/Node

Example

PHP

$node = new ListNode(
    Expr::read($items),
    Expr::val('id'),
    new TextNode('Item')
);

Methods

__construct

PHP

public function __construct(
        public Expr $items,
        public Expr $key,
        public Node $template
    ) 

Build a list/repeat IR node.

Parameters

  • Expr $items Items expression.
  • Expr $key Key expression for each item.
  • Node $template Template node rendered per item.

collectAtoms

PHP

public function collectAtoms(callable $collect): void

Collect atom dependencies used by items, key, and template.

Parameters

  • callable $collect Collector callback that receives dependency nodes.

Returns: void

jsonSerialize

PHP

public function jsonSerialize(): mixed

Encode this list node as runtime IR payload.

Returns: array<string, mixed>

Node

Source: Node.php

Base IR node type.

All IR node variants extend this class and must be JSON serializable so they can be encoded and sent to the runtime.

Group: IR/Node

Example

PHP

final class MyNode extends Node {
    public function jsonSerialize(): mixed {
        return ['k' => 'my'];
    }
}

Methods

setRenderContext

PHP

public function setRenderContext(array $node, array $ctx, array $atoms, callable $renderNodeFn): void

Parameters

  • array<string,mixed> $node @param array<string,mixed> $ctx @param array<int,mixed> $atoms

renderNodes

PHP

public function renderNodes(array $nodes, array $ctx): string

Parameters

  • array<int, mixed> $nodes

normalizeProps

PHP

protected function normalizeProps(mixed $props): array

Returns: array{attrs:array<string,mixed>,cls:mixed,style:array<string,mixed>}

RouteNode

Source: RouteNode.php

IR node for route matching and view selection.

Compiles path patterns to regex once on the PHP side and serializes route table metadata for runtime navigation.

Group: IR/Node

Example

PHP

$node = new RouteNode(
    ['/docs' => new TextNode('Docs')],
    new TextNode('Not found')
);

Methods

__construct

PHP

public function __construct(
        public array $table,
        public Node  $fallback,
        public string $base = '/', // optional, default '/'
    ) 

Parameters

  • array<string, Node> $table Map of path patterns to view Nodes (author order = match priority).
  • Node $fallback View to render when no pattern matches (404).
  • string $base Optional base path (default '/'), stripped before matching.

compilePattern

PHP

private static function compilePattern(string $pat): array 

Compile a route pattern (e.g., "/auction/:id") into a regex and ordered param keys.

Parameters

  • string $pat

Returns: array{0:string,1:array<int,string>} Tuple [regex, keys].

jsonSerialize

PHP

public function jsonSerialize(): mixed

k: 'route',

Returns: array{

ShowNode

Source: ShowNode.php

IR node for conditional rendering.

Renders a child node only when the condition evaluates to truthy.

Group: IR/Node

Example

PHP

$node = new ShowNode(
    Expr::val(true),
    new TextNode('Visible')
);

Methods

__construct

PHP

public function __construct(public Expr|bool $cond, public Node $child) 

Build a conditional IR node.

Parameters

  • Expr|bool $cond Condition expression or literal.
  • Node $child Node rendered when condition is true.

collectAtoms

PHP

public function collectAtoms(callable $collect): void

Collect atom dependencies used by condition and child node.

Parameters

  • callable $collect Collector callback that receives dependency nodes.

Returns: void

jsonSerialize

PHP

public function jsonSerialize(): mixed 

Encode this conditional node as runtime IR payload.

Returns: array<string, mixed>

SlotNode

Source: SlotNode.php

SlotNode represents a placeholder inside a component template

where children content will be injected at runtime. JSON shape: { "k": "slot", "name": "default" // optional; omitted for default slot }

Group: IR/Node

Example

PHP

$node = new SlotNode('header');

Methods

__construct

PHP

public function __construct(public readonly ?string $name = null) 

Build a slot placeholder node.

Parameters

  • string|null $name Slot name, or null for default slot.

withName

PHP

public function withName(string $name): self 

Return a slot node with normalized name.

Parameters

  • string $name Slot name.

Returns: self

jsonSerialize

PHP

public function jsonSerialize(): mixed

Encode this slot node as runtime IR payload.

Returns: array<string, string>

TextNode

Source: TextNode.php

IR node for text content.

Stores either a literal string or an expression resolved at runtime.

Group: IR/Node

Example

PHP

$node = new TextNode('Hello');

Methods

__construct

PHP

public function __construct(public Expr|string $value) 

Build a text node.

Parameters

  • Expr|string $value Text value or expression.

collectAtoms

PHP

public function collectAtoms(callable $collect):void

Collect atom dependencies from text expression values.

Parameters

  • callable $collect Collector callback that receives dependency nodes.

Returns: void

jsonSerialize

PHP

public function jsonSerialize(): mixed 

Encode this text node as runtime IR payload.

Returns: array<string, mixed>