Skip to content

ImmutableViewInitContext

The ViewInitContext a view is initialized with: a fixed snapshot of the dispatch that produced it.

Built by the executor, ViewFactory and the view test harness once the action has finished, from the view module and name, the output type, the originating action’s module and name, and the action’s attributes at that moment. The attributes are copied into the inherited AttributeHolder so View::getAttribute() works, and View treats a ViewInitContext as immutable, ignoring later setAttribute() calls.

ImmutableViewInitContext::getPsrResponse() wraps the WebResponse in a PsrResponseAdapter on first use unless a PSR-7 response was supplied at construction.

The getModuleName(), getOutputType(), getParameter() and getParameters() members serve views written against a container-style API: no parameters are stored here, so those two answer the supplied default and an empty array respectively — raw request parameters are not reachable from a view through this object.

final class ImmutableViewInitContext extends AttributeHolder implements ViewInitContext

ExtendsAttributeHolder
ImplementsViewInitContext
SourceExecution/ImmutableViewInitContext.php

public function __construct(Context $context, string $viewModule, string $viewName, string $outputType, ?string $actionModule, ?string $actionName, array<string, mixed> $actionAttributes, WebResponse $response, ?ResponseInterface $psrResponse = null, ?ValidationManager $validationManager = null): mixed

Constructor.

An array of parameters to be set right away.

ParameterTypeDescription
$contextContext
$viewModulestring
$viewNamestring
$outputTypestring
$actionModule?``string
$actionName?``string
$actionAttributesarray``<``string``, ``mixed``>
$responseWebResponse
$psrResponse?ResponseInterface
$validationManager?ValidationManager

Returns mixed

MethodDescription
getActionAttributes(): array<string, mixed>
getActionModuleName(): ?stringReturns the module of the action that selected this view.
getActionName(): ?stringReturns the name of the action that selected this view, or null when there was none.
getContext(): ContextReturns the application Context the view is rendering under.
getModuleName(): stringReturn action module name for legacy code that called getModuleName().
getOutputType(): OutputTypeNameProviderReturn legacy-style output type object proxy requirement: legacy code sometimes dereferenced $this->container->getOutputType()->getName().
getOutputTypeName(): stringReturns the lowercase name of the output type the view renders for.
getParameter(mixed $name, mixed $default = null): mixedLegacy parameter bag access – always returns $default (no parameters are stored in immutable context).
getParameters(): array<string, mixed>Expose an empty parameter array for completeness.
getPsrResponse(): ResponseInterfaceReturns the PSR-7 response backing this context, never null.
getResponse(): WebResponseReturns the response the view writes its rendered output into.
getValidationManager(): ?ValidationManagerReturn the validation manager, preferring the one injected at construction time (which carries the live error state from the current request).
getViewModuleName(): stringReturns the canonical name of the module hosting the view.
getViewName(): stringReturns the canonical name of the view being rendered.

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

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

public function getActionModuleName(): ?string

Returns the module of the action that selected this view.

Null when the view was reached without an originating action, so callers that need a module name should fall back to the view module.

Returns ?``string

public function getActionName(): ?string

Returns the name of the action that selected this view, or null when there was none.

Returns ?``string

public function getContext(): Context

Returns the application Context the view is rendering under.

Returns Context

public function getModuleName(): string

Return action module name for legacy code that called getModuleName().

Returns string

public function getOutputType(): OutputTypeNameProvider

Return legacy-style output type object proxy requirement: legacy code sometimes dereferenced $this->container->getOutputType()->getName().

We can’t cheaply recreate the output type object here without a controller reference, so omit for now; views should use View::getCurrentOutputType().

Returns OutputTypeNameProvider — An anonymous object exposing getName(): string.

public function getOutputTypeName(): string

Returns the lowercase name of the output type the view renders for.

Returns string

public function getParameter(mixed $name, mixed $default = null): mixed

Legacy parameter bag access – always returns $default (no parameters are stored in immutable context).

Slot/layout code that checks flags like ‘is_slot’ will simply see the default (false) and continue.

ParameterTypeDescription
$namemixed
$defaultmixed

Returns mixed

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

Expose an empty parameter array for completeness.

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

public function getPsrResponse(): ResponseInterface

Returns the PSR-7 response backing this context, never null.

An explicitly supplied response is returned as-is. Otherwise the WebResponse is wrapped in a PsrResponseAdapter on first call and that adapter is retained, so repeated calls hand back the same instance.

Returns ResponseInterface

public function getResponse(): WebResponse

Returns the response the view writes its rendered output into.

Returns WebResponse

public function getValidationManager(): ?ValidationManager

Return the validation manager, preferring the one injected at construction time (which carries the live error state from the current request).

Falls back to creating a fresh instance only when none was supplied — callers that need error messages (e.g. JSON error views) must pass the validation manager explicitly via the constructor.

Returns ?ValidationManager

public function getViewModuleName(): string

Returns the canonical name of the module hosting the view.

Returns string

public function getViewName(): string

Returns the canonical name of the view being rendered.

Returns string

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

MethodDeclared inDescription
appendAttribute()AttributeHolderAppend an attribute.
appendAttributeByRef()AttributeHolderAppend an attribute by reference.
appendParameter()ParameterHolderAppend a parameter.
appendParameterByRef()ParameterHolderAppend a parameter by reference.
clearAttributes()AttributeHolderClear all attributes.
clearParameters()ParameterHolderClear all parameters associated with this request.
getAttribute()AttributeHolderRetrieve an attribute.
getAttributeNames()AttributeHolderRetrieve an array of attribute names.
getAttributeNamespace()AttributeHolderRetrieve all attributes within a namespace.
getAttributeNamespaces()AttributeHolderRetrieve an array of attribute namespaces.
getAttributes()AttributeHolderRetrieve all attributes within a namespace.
getDefaultNamespace()AttributeHolderGet the default namespace name
getFlatAttributeNames()AttributeHolderRetrieve an array of flattened attribute names.
getFlatParameterNames()ParameterHolderRetrieve an array of flattened parameter names.
getParameterNames()ParameterHolderRetrieve an array of parameter names.
hasAttribute()AttributeHolderIndicates whether or not an attribute exists.
hasAttributeNamespace()AttributeHolderIndicates whether or not an attribute namespace exists.
hasParameter()ParameterHolderIndicates whether or not a parameter exists.
removeAttribute()AttributeHolderRemove an attribute.
removeAttributeNamespace()AttributeHolderRemove an attribute namespace and all of its associated attributes.
removeParameter()ParameterHolderRemove a parameter.
reset()ParameterHolderRemoves every parameter held, leaving the holder empty for reuse.
setAttribute()AttributeHolderSet an attribute.
setAttributeByRef()AttributeHolderSet an attribute by reference.
setAttributes()AttributeHolderSet an array of attributes.
setAttributesByRef()AttributeHolderSet an array of attributes by reference.
setParameter()ParameterHolderSet a parameter.
setParameterByRef()ParameterHolderSet a parameter by reference.
setParameters()ParameterHolderSet an array of parameters.
setParametersByRef()ParameterHolderSet an array of parameters by reference.