Concrete renderer for JSON output.

Handles rendering of different types of controller responses.

package XenForo_Mvc

 Methods

Constructor

__construct(\XenForo_Dependencies_Abstract $dependencies, \Zend_Controller_Response_Http $response, \Zend_Controller_Request_Http $request) 

see \global\XenForo_ViewRenderer_Abstract::__construct()

Parameters

$dependencies

XenForo_Dependencies_Abstract

$response

Zend_Controller_Response_Http

$request

Zend_Controller_Request_Http

Helper method to create a template object for rendering.

createTemplateObject(string $templateName, array $params) : \XenForo_Template_Abstract
Inherited

Templates only represent HTML output, so no response type is needed. However, they can be used in any response type.

inherited_from \XenForo_ViewRenderer_Abstract::createTemplateObject()

Parameters

$templateName

string

Name of the template to create

$params

array

Key-value parameters to pass to the template

Returns

Builds the default data to be returned by the JSON view, including an HTML-rendered template, array of required JS and CSS, title and h1 parameters and the navigation array.

getDefaultOutputArray(string $viewName, array $params, string $templateName) : array

Parameters

$viewName

string

$params

array

$templateName

string

Returns

array

Gets the dependencies handler object.

getDependencyHandler() : \XenForo_Dependencies_Abstract
Inherited

inherited_from \XenForo_ViewRenderer_Abstract::getDependencyHandler()

Returns

Gets the 'needs container' setting.

getNeedsContainer() : boolean
Inherited

inherited_from \XenForo_ViewRenderer_Abstract::getNeedsContainer()

Returns

boolean

JSON encodes an input for direct output.

jsonEncodeForOutput(mixed $input, $addDefaultParams) : string

This renders any objects with string representations to strings.

Parameters

$input

mixed

Data to JSON encode. Likely an array, but not always.

$addDefaultParams

Returns

stringJSON encoded output

Preloads a template with the template handler for use later.

preloadTemplate(string $templateName) 
Inherited

inherited_from \XenForo_ViewRenderer_Abstract::preloadTemplate()

Parameters

$templateName

string

Template name

Renders the container.

renderContainer($contents, array $params) : string

This often represents the "chrome" of a page, including aspects like the header and footer. The content from the other render methods will generally be put inside this.

Note that not all response types will have a container. In which case, they should return the inner contents directly.

see \global\XenForo_ViewRenderer_Abstract::renderContainer()

Parameters

$contents

string

$params

array

Returns

string

Renders an error.

renderError(string | array $error) : string

see \global\XenForo_ViewRenderer_Abstract::renderError()

Parameters

$error

stringarray

Error message

Returns

stringJSON-encoded array

Renders a message.

renderMessage(string $message) : string | false

see \global\XenForo_ViewRenderer_Abstract::renderMessage()

Parameters

$message

string

Text of the message to render

Returns

stringfalseRendered output. False if rendering wasn't possible (see {@link renderUnrepresentable()}).

Simple handler for JSON redirects - do not redirect, just send status:ok and redirect:$redirectTarget

renderRedirect(integer $redirectType, string $redirectTarget, mixed $redirectMessage, array $redirectParams) : string

Most renderers will actually redirect, but some may not.

Parameters

$redirectType

integer

Type of redirect. See {@link XenForo_ControllerResponse_Redirect}

$redirectTarget

string

Target to redirect to

$redirectMessage

mixed

Redirect message

$redirectParams

array

Redirect parameters

Returns

stringJSON-encoded array

Renders a sub or child view.

renderSubView(\XenForo_ControllerResponse_View $subView) : string | \XenForo_Template_Abstract | false
Inherited

inherited_from \XenForo_ViewRenderer_Abstract::renderSubView()

Parameters

Returns

Fallback for rendering an "unrepresentable" message.

renderUnrepresentable() : string

Method is called when the concrete rendering function returns false or no concrete rendering function is available.

see \global\XenForo_ViewRenderer_Abstract::renderUnrepresentable()

Returns

stringJSON-encoded array

Renders a view.

renderView(string $viewName, array $params, string $templateName, \XenForo_ControllerResponse_View $subView) : string | \XenForo_Template_Abstract | false

Should instantiate the view object and render it. Note that depending on response type, this class may have to manipulate the view name or instantiate a different object.

see \global\XenForo_ViewRenderer_Abstract::renderView()

Parameters

$viewName

string

Name of the view to create

$params

array

Key-value array of parameters for the view.

$templateName

string

Name of the template that will be used to display (may be ignored by view)

$subView

\XenForo_ControllerResponse_Viewnull

A sub-view that will be rendered internal to this view

Returns

string\XenForo_Template_AbstractfalseRendered output. False if rendering wasn't possible (see {@link renderUnrepresentable()}).

General helper method to create and render a view object for the specified response type.

renderViewObject(string $class, string $responseType, array $params, string $templateName) : string | false | null
Inherited

Returns null if no class can be loaded or no view method has been defined. Otherwise, the return is defined by the view render method, which should return either a string (rendered content) or false (unrepresentable).

inherited_from \XenForo_ViewRenderer_Abstract::renderViewObject()

Parameters

$class

string

View class name

$responseType

string

Response type (translated to method name as render$type)

$params

array

Key-value parameters to pass to view. May be modified by the prepareParams call within.

$templateName

string

Template name to pass to view (may be ignored by view)

Returns

stringfalsenull

Replaces the place holders for required externals with the actual requirements.

replaceRequiredExternalPlaceholders(\XenForo_Template_Abstract $template, string $rendered) : string
Inherited

This approach is needed to ensure that all requirements are properly included, even if they are included after the comment has been rendered.

inherited_from \XenForo_ViewRenderer_Abstract::replaceRequiredExternalPlaceholders()

Parameters

$template

\XenForo_Template_Abstract

The container template object; used to get the requirements

$rendered

string

Already rendered output

Returns

string

Sets the 'needs container' setting

setNeedsContainer(boolean $required) : boolean
Inherited

inherited_from \XenForo_ViewRenderer_Abstract::setNeedsContainer()

Parameters

$required

boolean

Returns

boolean

Add default parameters to the provided parameters array

_addDefaultParams(array $params) : array

Parameters

$params

array

Returns

array

Data that should be preloaded for the container.

_preloadContainerData() 
Inherited

Templates/phrases may be accidentally (or intentionally) rendered in the view or before the container is set to be rendered. Preloading data here can allow all the data to be fetched at once.

inherited_from \XenForo_ViewRenderer_Abstract::_preloadContainerData()

Loops through the given array (recursively) and stringifies any objects it can.

_stringifyObjectsInArray(array $array) : array

Parameters

$array

array

Array to search

Returns

arrayArray with objects stringified

 Properties

 

Application dependencies.

$_dependencies : \XenForo_Dependencies_Abstract
Inherited

inherited_from \XenForo_ViewRenderer_Abstract::$$_dependencies
 

Determines whether the container needs to be rendered.

$_needsContainer : boolean
Inherited

This may apply to an entire renderer or just individual render types.

inherited_from \XenForo_ViewRenderer_Abstract::$$_needsContainer
 

Request object.

$_request : \Zend_Controller_Request_Http
Inherited

Can be used to manipulate output based in input parameters AT YOUR OWN RISK. Strictly, making use of this breaks MVC principles, so avoid it if you can.

inherited_from \XenForo_ViewRenderer_Abstract::$$_request
 

Response object.

$_response : \Zend_Controller_Response_Http
Inherited

Generally should only be used to manipulate response codes if needed.

inherited_from \XenForo_ViewRenderer_Abstract::$$_response