JSONViewRenderer
in package
implements
ViewRenderer
An implementation of the ViewRenderer interface for rendering registered viewvariables as JSON
Tags
Table of Contents
Interfaces
- ViewRenderer
- An interface defining a ViewRenderer ViewRenderers are utilized by controllers and handle the presentation of data to the user Built in implementations are HTMLViewRenderer and JSONViewRenderer
Properties
- $appContext : array<string|int, mixed>
- $encodeErrors : array<string|int, string>
- $variables : array<string|int, mixed>
Methods
- getAppContextProperty() : mixed|null
- Returns the requested appContext variable
- getViewVariable() : mixed
- Get a single view variable by its name
- getViewVariables() : array<string|int, mixed>
- Get the registered view variables
- registerAppContextProperty() : void
- Push to the array of registered appContext variables
- registerViewVariable() : void
- Push to the array of registered view variables
- renderView() : void
- Render as JSON any registered view variables
- setPage() : void
- An implmentation is required by the ViewRenderer interface, but this method is not currently used by JSONViewRenderer
- setView() : void
- setViewVariables() : void
- Set all variables associated with the view at once.
- getEncodeErrors() : array<string|int, string>
- Return an array of potential JSON encode errors
Properties
$appContext
private
array<string|int, mixed>
$appContext
= null
An array of data for the views geared toward the app environment (User session, server paths, config)
$encodeErrors
private
static array<string|int, string>
$encodeErrors
= array(JSON_ERROR_NONE => 'No error has occurred', JSON_ERROR_DEPTH => 'The maximum stack depth has been exceeded', JSON_ERROR_STATE_MISMATCH => 'Invalid or malformed JSON', JSON_ERROR_CTRL_CHAR => 'Control character error, possibly incorrectly encoded', JSON_ERROR_SYNTAX => 'Syntax error', JSON_ERROR_UTF8 => 'Malformed UTF-8 characters, possibly incorrectly encoded', JSON_ERROR_RECURSION => 'One or more recursive references in the value to be encoded', JSON_ERROR_INF_OR_NAN => 'One or more NAN or INF values in the value to be encoded', JSON_ERROR_UNSUPPORTED_TYPE => 'A value of a type that cannot be encoded was given', JSON_ERROR_INVALID_PROPERTY_NAME => 'A property name that cannot be encoded was given', JSON_ERROR_UTF16 => 'Malformed UTF-16 characters, possibly incorrectly encoded')
An array of potential JSON encoding errors
$variables
private
array<string|int, mixed>
$variables
= array()
An array of application data to provide to the views
Methods
getAppContextProperty()
Returns the requested appContext variable
public
getAppContextProperty(string $name) : mixed|null
Parameters
- $name : string
-
The name of the variable
Return values
mixed|null —Returns the variable or null if it was not found
getViewVariable()
Get a single view variable by its name
public
getViewVariable(mixed $name) : mixed
Parameters
- $name : mixed
-
The name of the variable
Return values
mixed —$viewVariable
getViewVariables()
Get the registered view variables
public
getViewVariables() : array<string|int, mixed>
Return values
array<string|int, mixed> —$viewVariables
registerAppContextProperty()
Push to the array of registered appContext variables
public
registerAppContextProperty(mixed $name, mixed $data) : void
Parameters
- $name : mixed
-
- The name of the variable
- $data : mixed
-
- The value(s) of the view variable
registerViewVariable()
Push to the array of registered view variables
public
registerViewVariable(mixed $name, mixed $data) : void
Parameters
- $name : mixed
-
- The name of the variable
- $data : mixed
-
- The value(s) of the view variable
renderView()
Render as JSON any registered view variables
public
renderView() : void
setPage()
An implmentation is required by the ViewRenderer interface, but this method is not currently used by JSONViewRenderer
public
setPage(SitePage $page) : void
Parameters
- $page : SitePage
-
The current SitePage
setView()
public
setView(mixed $viewFile[, mixed $isAdmin = false ]) : void
Parameters
- $viewFile : mixed
- $isAdmin : mixed = false
-
Define the view as admin or standard
setViewVariables()
Set all variables associated with the view at once.
public
setViewVariables(mixed $data) : void
This can also be expected to overwrite previously set view variables
Parameters
- $data : mixed
getEncodeErrors()
Return an array of potential JSON encode errors
private
getEncodeErrors() : array<string|int, string>