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.
Synopsis
Section titled “Synopsis”class OutputType extends ParameterHolder implements Stringable
| Extends | ParameterHolder |
| Implements | Stringable |
| Source | Controller/OutputType.php |
Methods
Section titled “Methods”| Method | Description |
|---|---|
__toString(): string | |
getDefaultLayoutName(): ?string | Get the name of the default layout. |
getExceptionTemplate(): ?string | Get the exception template filename for this renderer. |
getLayout(?string $name = null): array<string, mixed> | Get a layout. |
getName(): string | Get the name of the Output Type. |
getRenderer(?string $name = null): ?Renderer | Get a renderer instance. |
hasRenderers(): bool | Checks 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): void | Initialize the Output Type. |
reset(): void | Reset output type state for FrankenPHP worker compatibility. |
__toString()
Section titled “__toString()”final public function __toString(): string
Returns string
getDefaultLayoutName()
Section titled “getDefaultLayoutName()”public function getDefaultLayoutName(): ?string
Get the name of the default layout.
Returns ?``string — The name of the default layout, or null if none defined.
getExceptionTemplate()
Section titled “getExceptionTemplate()”public function getExceptionTemplate(): ?string
Get the exception template filename for this renderer.
Returns ?``string — A path to the exception template, or null if undefined.
getLayout()
Section titled “getLayout()”public function getLayout(?string $name = null): array<string, mixed>
Get a layout.
The optional name of the layout to fetch.
| Parameter | Type | Description |
|---|---|---|
$name | ?``string | The optional name of the layout to fetch. |
Returns array``<``string``, ``mixed``> — An array of layout information.
| Throws | When |
|---|---|
QuioteException | If the layout doesn’t exist. |
getName()
Section titled “getName()”public function getName(): string
Get the name of the Output Type.
Returns string — The name of the Output Type.
getRenderer()
Section titled “getRenderer()”public function getRenderer(?string $name = null): ?Renderer
Get a renderer instance.
The optional name of the Renderer to fetch.
| Parameter | Type | Description |
|---|---|---|
$name | ?``string | The optional name of the Renderer to fetch. |
Returns ?Renderer — A Renderer instance or null if none defined.
hasRenderers()
Section titled “hasRenderers()”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.
initialize()
Section titled “initialize()”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.
| Parameter | Type | Description |
|---|---|---|
$context | Context | The current Context instance. |
$parameters | array``<``string``, ``mixed``> | An array of initialization parameters. |
$name | string | The name of the Output Type. |
$renderers | array``<``string``, ``array``<``string``, ``mixed``>``> | An array of Renderers (settings and instances). |
$defaultRenderer | ?``string | The name of the default Renderer, if set. |
$layouts | array``<``string``, ``array``<``string``, ``mixed``>``> | An array of configured layouts. |
$defaultLayout | ?``string | The name of the default layout, if set. |
$exceptionTemplate | ?``string | The name of the exception template for this output type. |
reset()
Section titled “reset()”public function reset(): void
Reset output type state for FrankenPHP worker compatibility.
Clears output type properties that could leak between requests.
Inherited methods
Section titled “Inherited methods”These come from an ancestor and are documented where they are declared.
| Method | Declared in | Description |
|---|---|---|
appendParameter() | ParameterHolder | Append a parameter. |
appendParameterByRef() | ParameterHolder | Append a parameter by reference. |
clearParameters() | ParameterHolder | Clear all parameters associated with this request. |
getFlatParameterNames() | ParameterHolder | Retrieve an array of flattened parameter names. |
getParameter() | ParameterHolder | Retrieve a parameter. |
getParameterNames() | ParameterHolder | Retrieve an array of parameter names. |
getParameters() | ParameterHolder | Retrieve an array of parameters. |
hasParameter() | ParameterHolder | Indicates whether or not a parameter exists. |
removeParameter() | ParameterHolder | Remove a parameter. |
setParameter() | ParameterHolder | Set a parameter. |
setParameterByRef() | ParameterHolder | Set a parameter by reference. |
setParameters() | ParameterHolder | Set an array of parameters. |
setParametersByRef() | ParameterHolder | Set an array of parameters by reference. |