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.
Synopsis
Section titled “Synopsis”final class ImmutableViewInitContext extends AttributeHolder implements ViewInitContext
| Extends | AttributeHolder |
| Implements | ViewInitContext |
| Source | Execution/ImmutableViewInitContext.php |
Constructor
Section titled “Constructor”__construct()
Section titled “__construct()”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.
| Parameter | Type | Description |
|---|---|---|
$context | Context | |
$viewModule | string | |
$viewName | string | |
$outputType | string | |
$actionModule | ?``string | |
$actionName | ?``string | |
$actionAttributes | array``<``string``, ``mixed``> | |
$response | WebResponse | |
$psrResponse | ?ResponseInterface | |
$validationManager | ?ValidationManager |
Returns mixed
Methods
Section titled “Methods”| Method | Description |
|---|---|
getActionAttributes(): array<string, mixed> | |
getActionModuleName(): ?string | Returns the module of the action that selected this view. |
getActionName(): ?string | Returns the name of the action that selected this view, or null when there was none. |
getContext(): Context | Returns the application Context the view is rendering under. |
getModuleName(): string | Return action module name for legacy code that called getModuleName(). |
getOutputType(): OutputTypeNameProvider | Return legacy-style output type object proxy requirement: legacy code sometimes dereferenced $this->container->getOutputType()->getName(). |
getOutputTypeName(): string | Returns the lowercase name of the output type the view renders for. |
getParameter(mixed $name, mixed $default = null): mixed | Legacy 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(): ResponseInterface | Returns the PSR-7 response backing this context, never null. |
getResponse(): WebResponse | Returns the response the view writes its rendered output into. |
getValidationManager(): ?ValidationManager | Return the validation manager, preferring the one injected at construction time (which carries the live error state from the current request). |
getViewModuleName(): string | Returns the canonical name of the module hosting the view. |
getViewName(): string | Returns the canonical name of the view being rendered. |
getActionAttributes()
Section titled “getActionAttributes()”public function getActionAttributes(): array<string, mixed>
Returns array``<``string``, ``mixed``>
getActionModuleName()
Section titled “getActionModuleName()”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
getActionName()
Section titled “getActionName()”public function getActionName(): ?string
Returns the name of the action that selected this view, or null when there was none.
Returns ?``string
getContext()
Section titled “getContext()”public function getContext(): Context
Returns the application Context the view is rendering under.
Returns Context
getModuleName()
Section titled “getModuleName()”public function getModuleName(): string
Return action module name for legacy code that called getModuleName().
Returns string
getOutputType()
Section titled “getOutputType()”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.
getOutputTypeName()
Section titled “getOutputTypeName()”public function getOutputTypeName(): string
Returns the lowercase name of the output type the view renders for.
Returns string
getParameter()
Section titled “getParameter()”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.
| Parameter | Type | Description |
|---|---|---|
$name | mixed | |
$default | mixed |
Returns mixed
getParameters()
Section titled “getParameters()”public function getParameters(): array<string, mixed>
Expose an empty parameter array for completeness.
Returns array``<``string``, ``mixed``>
getPsrResponse()
Section titled “getPsrResponse()”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
getResponse()
Section titled “getResponse()”public function getResponse(): WebResponse
Returns the response the view writes its rendered output into.
Returns WebResponse
getValidationManager()
Section titled “getValidationManager()”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
getViewModuleName()
Section titled “getViewModuleName()”public function getViewModuleName(): string
Returns the canonical name of the module hosting the view.
Returns string
getViewName()
Section titled “getViewName()”public function getViewName(): string
Returns the canonical name of the view being rendered.
Returns string
Inherited methods
Section titled “Inherited methods”These come from an ancestor and are documented where they are declared.
| Method | Declared in | Description |
|---|---|---|
appendAttribute() | AttributeHolder | Append an attribute. |
appendAttributeByRef() | AttributeHolder | Append an attribute by reference. |
appendParameter() | ParameterHolder | Append a parameter. |
appendParameterByRef() | ParameterHolder | Append a parameter by reference. |
clearAttributes() | AttributeHolder | Clear all attributes. |
clearParameters() | ParameterHolder | Clear all parameters associated with this request. |
getAttribute() | AttributeHolder | Retrieve an attribute. |
getAttributeNames() | AttributeHolder | Retrieve an array of attribute names. |
getAttributeNamespace() | AttributeHolder | Retrieve all attributes within a namespace. |
getAttributeNamespaces() | AttributeHolder | Retrieve an array of attribute namespaces. |
getAttributes() | AttributeHolder | Retrieve all attributes within a namespace. |
getDefaultNamespace() | AttributeHolder | Get the default namespace name |
getFlatAttributeNames() | AttributeHolder | Retrieve an array of flattened attribute names. |
getFlatParameterNames() | ParameterHolder | Retrieve an array of flattened parameter names. |
getParameterNames() | ParameterHolder | Retrieve an array of parameter names. |
hasAttribute() | AttributeHolder | Indicates whether or not an attribute exists. |
hasAttributeNamespace() | AttributeHolder | Indicates whether or not an attribute namespace exists. |
hasParameter() | ParameterHolder | Indicates whether or not a parameter exists. |
removeAttribute() | AttributeHolder | Remove an attribute. |
removeAttributeNamespace() | AttributeHolder | Remove an attribute namespace and all of its associated attributes. |
removeParameter() | ParameterHolder | Remove a parameter. |
reset() | ParameterHolder | Removes every parameter held, leaving the holder empty for reuse. |
setAttribute() | AttributeHolder | Set an attribute. |
setAttributeByRef() | AttributeHolder | Set an attribute by reference. |
setAttributes() | AttributeHolder | Set an array of attributes. |
setAttributesByRef() | AttributeHolder | Set an array of attributes by reference. |
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. |