Skip to content

DeferredSlotRenderable

A slot whose action is not dispatched until its content is actually asked for.

Returned by View::slot(), which captures the target module, action, parameters and output type and hands the template this object. Because it is \Stringable, echoing it inside a template is what triggers the dispatch; a slot a template never prints costs nothing. The rendered content is memoized, so the slot action runs at most once per instance.

Dispatch resolves the parent WebRequest and the SlotDispatcher from the container at that moment. A failure is rethrown so the error-handling middleware decides what the client sees, and nothing is memoized.

DeferredSlotRenderable::getModule(), DeferredSlotRenderable::getAction(), DeferredSlotRenderable::getOutputType() and DeferredSlotRenderable::getArguments() describe the pending dispatch without performing it; DeferredSlotRenderable::toArray() does perform it, since it reports the content length.

class DeferredSlotRenderable implements SlotRenderable, Stringable

ImplementsSlotRenderable, Stringable
SourceExecution/DeferredSlotRenderable.php

public function __construct(Context $context, string $module, string $action, array<string, mixed> $parameters = [], ?string $outputType = null): mixed

ParameterTypeDescription
$contextContext
$modulestring
$actionstring
$parametersarray``<``string``, ``mixed``>
$outputType?``string

Returns mixed

MethodDescription
__toString(): string
getAction(): stringReturns the name of the slot action to dispatch.
getArguments(): array<string, mixed>
getContent(): stringRenders the slot on first call and returns its content.
getModule(): stringReturns the module the slot action will be dispatched from.
getOutputType(): ?stringReturns the output type the slot will render for, or null to let dispatch pick one.
toArray(): array<string, mixed>

public function __toString(): string

Returns string

public function getAction(): string

Returns the name of the slot action to dispatch.

Returns string

public function getArguments(): array<string, mixed>

Returns array``<``string``, ``mixed``>

public function getContent(): string

Renders the slot on first call and returns its content.

The result is memoized, so the slot action is dispatched at most once per instance no matter how often a template stringifies it. Dispatch resolves the parent WebRequest and the SlotDispatcher from the container and hands them the module, action, parameters and output type captured at construction. A failure during dispatch is recorded to PHP’s own error log with the slot’s identity and a truncated trace when debug logging is on, then rethrown so the error-handling middleware decides what the client sees; nothing is memoized in that case.

Returns string

public function getModule(): string

Returns the module the slot action will be dispatched from.

Returns string

public function getOutputType(): ?string

Returns the output type the slot will render for, or null to let dispatch pick one.

Returns ?``string

public function toArray(): array<string, mixed>

Returns array``<``string``, ``mixed``>