Skip to content

OutputType

One configured output type — html, json, or whatever else output_types.xml declares — together with the renderers, layouts and parameters that belong to it.

The Controller builds and initializes one instance per declared output type when it initializes and hands them out through Controller::getOutputType(); an application receives an instance rather than constructing or subclassing one. What it carries is the presentation side of a response: the renderers a template layer can be rendered with (OutputType::getRenderer(), OutputType::hasRenderers()), the layouts a view can load (OutputType::getLayout(), OutputType::getDefaultLayoutName()), the template used when an exception has to be rendered in this type (OutputType::getExceptionTemplate()), and the type’s own parameter bag inherited from ParameterHolder.

A renderer is constructed and initialized on first request, and kept for later requests only when it declares itself reusable through IReusableRenderer; one that does not is rebuilt on every call. Asking for a renderer or a layout by an unconfigured name, or by no name when the type declares no default, throws rather than returning null. The object stringifies to its own name, so it can stand in wherever the name is expected.

class OutputType extends ParameterHolder implements Stringable

ExtendsParameterHolder
ImplementsStringable
SourceController/OutputType.php
MethodDescription
__toString(): string
getDefaultLayoutName(): ?stringGet the name of the default layout.
getExceptionTemplate(): ?stringGet the exception template filename for this renderer.
getLayout(?string $name = null): array<string, mixed>Get a layout.
getName(): stringGet the name of the Output Type.
getRenderer(?string $name = null): ?RendererGet a renderer instance.
hasRenderers(): boolChecks whether or not any renderers are defined for this Output Type.
initialize(Context $context, array<string, mixed> $parameters, string $name, array<string, array<string, mixed>> $renderers, ?string $defaultRenderer, array<string, array<string, mixed>> $layouts, ?string $defaultLayout, ?string $exceptionTemplate = null): voidInitialize the Output Type.
reset(): voidReset output type state for FrankenPHP worker compatibility.

final public function __toString(): string

Returns string

public function getDefaultLayoutName(): ?string

Get the name of the default layout.

Returns ?``string — The name of the default layout, or null if none defined.

public function getExceptionTemplate(): ?string

Get the exception template filename for this renderer.

Returns ?``string — A path to the exception template, or null if undefined.

public function getLayout(?string $name = null): array<string, mixed>

Get a layout.

The optional name of the layout to fetch.

ParameterTypeDescription
$name?``stringThe optional name of the layout to fetch.

Returns array``<``string``, ``mixed``> — An array of layout information.

ThrowsWhen
QuioteExceptionIf the layout doesn’t exist.

public function getName(): string

Get the name of the Output Type.

Returns string — The name of the Output Type.

public function getRenderer(?string $name = null): ?Renderer

Get a renderer instance.

The optional name of the Renderer to fetch.

ParameterTypeDescription
$name?``stringThe optional name of the Renderer to fetch.

Returns ?Renderer — A Renderer instance or null if none defined.

public function hasRenderers(): bool

Checks whether or not any renderers are defined for this Output Type.

Returns bool — True, if renderers are defined, false otherwise.

public function initialize(Context $context, array<string, mixed> $parameters, string $name, array<string, array<string, mixed>> $renderers, ?string $defaultRenderer, array<string, array<string, mixed>> $layouts, ?string $defaultLayout, ?string $exceptionTemplate = null): void

Initialize the Output Type.

The name of the exception template for this output type.

ParameterTypeDescription
$contextContextThe current Context instance.
$parametersarray``<``string``, ``mixed``>An array of initialization parameters.
$namestringThe name of the Output Type.
$renderersarray``<``string``, ``array``<``string``, ``mixed``>``>An array of Renderers (settings and instances).
$defaultRenderer?``stringThe name of the default Renderer, if set.
$layoutsarray``<``string``, ``array``<``string``, ``mixed``>``>An array of configured layouts.
$defaultLayout?``stringThe name of the default layout, if set.
$exceptionTemplate?``stringThe name of the exception template for this output type.

public function reset(): void

Reset output type state for FrankenPHP worker compatibility.

Clears output type properties that could leak between requests.

These come from an ancestor and are documented where they are declared.

MethodDeclared inDescription
appendParameter()ParameterHolderAppend a parameter.
appendParameterByRef()ParameterHolderAppend a parameter by reference.
clearParameters()ParameterHolderClear all parameters associated with this request.
getFlatParameterNames()ParameterHolderRetrieve an array of flattened parameter names.
getParameter()ParameterHolderRetrieve a parameter.
getParameterNames()ParameterHolderRetrieve an array of parameter names.
getParameters()ParameterHolderRetrieve an array of parameters.
hasParameter()ParameterHolderIndicates whether or not a parameter exists.
removeParameter()ParameterHolderRemove a parameter.
setParameter()ParameterHolderSet a parameter.
setParameterByRef()ParameterHolderSet a parameter by reference.
setParameters()ParameterHolderSet an array of parameters.
setParametersByRef()ParameterHolderSet an array of parameters by reference.