PHP Class lithium\template\view\Renderer

When in a view, the local scope is that of an instance of Renderer - meaning that $this in views is an instance of the current renderer adapter. For more information about implementing your own template loaders or renderers, see the lithium\template\View class.
See also: lithium\template\View
See also: lithium\template\adapter\File
See also: lithium\template\adapter\Simple
Inheritance: extends lithium\core\Object
Afficher le fichier Open project: unionofrad/lithium Class Usage Examples

Protected Properties

Свойство Type Description
$_autoConfig array These configuration variables will automatically be assigned to their corresponding protected properties when the object is initialized.
$_classes array Renderer's dependencies. These classes are used by the output handlers to generate URLs for dynamic resources and static assets.
$_context array Context values that exist across all templates rendered in this context. These values are usually rendered in the layout template after all other values have rendered.
$_data array An array containing any additional variables to be injected into view templates. This allows local variables to be communicated between multiple templates (i.e. an element and a layout) which are using the same rendering context.
$_handlers array Automatically matches up template strings by name to output handlers. A handler can either be a string, which represents a method name of the helper, or it can be a closure or callable object. A handler takes 3 parameters: the value to be filtered, the name of the helper method that triggered the handler, and the array of options passed to the _render(). These handlers are shared among all helper objects, and are automatically triggered whenever a helper method renders a template string (using _render()) and a key which is to be embedded in the template string matches an array key of a corresponding handler.
$_helpers array Contains the list of helpers currently in use by this rendering context. Helpers are loaded via the helper() method, which is called by Renderer::__get(), allowing for on-demand loading of helpers.
$_options array Available options accepted by template\View::render(), used when rendering.
$_request The Request object instance, if applicable.
$_response The Response object instance, if applicable.
$_strings array Aggregates named string templates used by helpers. Can be overridden to change the default strings a helper uses.
$_vars Variables that have been set from a view/element/layout/etc. that should be available to the same rendering context.
$_view object Holds an instance of the View object that created this rendering context. See the view() method for more details.

Méthodes publiques

Méthode Description
__call ( string $method, array $params ) : mixed Dispatches method calls for (a) rendering context values or (b) applying handlers to pieces of content. If $method is a key in Renderer::$_context, the corresponding context value will be returned (with the value run through a matching handler if one is available). If $method is a key in Renderer::$_handlers, the value passed as the first parameter in the method call will be passed through the handler and returned.
__construct ( array $config = [] ) : void Constructor.
__get ( string $property ) : mixed Returns a helper object or context value by name.
__isset ( string $property ) : boolean Magic __isset method.
applyHandler ( object $helper, string $method, string $name, mixed $value, array $options = [] ) : mixed Filters a piece of content through a content handler. A handler can be: - a string containing the name of a method defined in $helper. The method is called with 3 parameters: the value to be handled, the helper method called ($method) and the $options that were passed into applyHandler.
context ( string $property = null ) : mixed Returns either one or all context values for this rendering context. Context values persist across all templates rendered in the current context, and are usually outputted in a layout template.
data ( ) : array Returns all variables and their values that have been set.
handlers ( mixed $handlers = null ) : mixed Gets or adds content handlers from/to this rendering context, depending on the value of $handlers. For more on how to implement handlers and the various types, see applyHandler().
helper ( string $name, array $config = [] ) : object Brokers access to helpers attached to this rendering context, and loads helpers on-demand if they are not available.
render ( string $template, array | string $data = [], array $options = [] ) : string Render the template with given data. Abstract; must be added to subclasses.
request ( ) : object Returns the Request object associated with this rendering context.
respondsTo ( string $method, boolean $internal = false ) : boolean Determines if a given method can be called.
response ( ) : object Returns the Response object associated with this rendering context.
set ( array $data = [] ) : void Allows variables to be set by one template and used in subsequent templates rendered using the same context. For example, a variable can be set in a template and used in an element rendered within a template, or an element or template could set a variable which would be made available in the layout.
strings ( mixed $strings = null ) : mixed Manages template strings.
view ( ) : object Retuns the View object that controls this rendering context's instance. This can be used, for example, to render view elements, i.e. view()->render('element' $name); ?>.

Méthodes protégées

Méthode Description
_init ( ) : void Sets the default output handlers for string template inputs.
_render ( string $type, string $template, array $data = [], array $options = [] ) : string Shortcut method used to render elements and other nested templates from inside the templating layer.

Method Details

__call() public méthode

Dispatches method calls for (a) rendering context values or (b) applying handlers to pieces of content. If $method is a key in Renderer::$_context, the corresponding context value will be returned (with the value run through a matching handler if one is available). If $method is a key in Renderer::$_handlers, the value passed as the first parameter in the method call will be passed through the handler and returned.
See also: lithium\template\view\Renderer::$_context
See also: lithium\template\view\Renderer::$_handlers
See also: lithium\template\view\Renderer::applyHandler()
public __call ( string $method, array $params ) : mixed
$method string The method name to call, usually either a rendering context value or a content handler.
$params array
Résultat mixed

__construct() public méthode

Constructor.
public __construct ( array $config = [] ) : void
$config array Available configuration options are: - `view`: The `View` object associated with this renderer. - `strings`: String templates used by helpers. - `handlers`: An array of output handlers for string template inputs. - `request`: The `Request` object associated with this renderer and passed to the defined handlers. - `response`: The `Response` object associated with this renderer. - `context`: An array of the current rendering context data, including `content`, `title`, `scripts`, `head` and `styles`.
Résultat void

__get() public méthode

Returns a helper object or context value by name.
public __get ( string $property ) : mixed
$property string The name of the helper or context value to return.
Résultat mixed

__isset() public méthode

Is triggered by calling isset() or empty() on inaccessible properties, and performs an isset() check on for keys in the current context.
public __isset ( string $property ) : boolean
$property string The accessed property.
Résultat boolean True if set, false otherwise.

_init() protected méthode

The default handlers available are: - url: Allows generating escaped and routed URLs using Router::match(). Note that all falsey values, which includes an empty array, will result in '/' being returned. For empty arrays this behavior is slightly different from using Router::match() directly. - path: Generates an asset path. - options: Converts a set of parameters to HTML attributes into a string. - title: Returns the escaped title. - value: Returns an escaped value. - scripts: Returns a markup string of styles from context. - styles: Returns a markup string of scripts from context. - head
See also: lithium\net\http\Router::match()
See also: lithium\net\http\Media::asset()
See also: lithium\template\Helper::_attributes()
protected _init ( ) : void
Résultat void

_render() protected méthode

Shortcut method used to render elements and other nested templates from inside the templating layer.
See also: lithium\template\View::$_processes
See also: lithium\template\View::render()
protected _render ( string $type, string $template, array $data = [], array $options = [] ) : string
$type string The type of template to render, usually either `'element'` or `'template'`. Indicates the process used to render the content. See `lithium\template\View::$_processes` for more info.
$template string The template file name. For example, if `'header'` is passed, and `$type` is set to `'element'`, then the template rendered will be `views/elements/header.html.php` (assuming the default configuration).
$data array An array of any other local variables that should be injected into the template. By default, only the values used to render the current template will be sent. If `$data` is non-empty, both sets of variables will be merged.
$options array Any options accepted by `template\View::render()`.
Résultat string Returns a the rendered template content as a string.

applyHandler() public méthode

- an array where the first element is an object reference, and the second element is a method name. The method name given will be called on the object with the same parameters as above. - a closure, which takes the value as the first parameter, an array containing an instance of the calling helper and the calling method name as the second, and $options as the third. In all cases, handlers should return the transformed version of $value.
See also: lithium\template\view\Renderer::handlers()
See also: lithium\template\view\Renderer::$_handlers
public applyHandler ( object $helper, string $method, string $name, mixed $value, array $options = [] ) : mixed
$helper object The instance of the object (usually a helper) that is invoking
$method string The object (helper) method which is applying the handler to the content
$name string The name of the value to which the handler is applied, i.e. `'url'`, `'path'` or `'title'`.
$value mixed The value to be transformed by the handler, which is ultimately returned.
$options array Any options which should be passed to the handler used in this call.
Résultat mixed The transformed value of `$value`, after it has been processed by a handler.

context() public méthode

Returns either one or all context values for this rendering context. Context values persist across all templates rendered in the current context, and are usually outputted in a layout template.
See also: lithium\template\view\Renderer::$_context
public context ( string $property = null ) : mixed
$property string If unspecified, an associative array of all context values is returned. If a string is specified, the context value matching the name given will be returned, or `null` if that name does not exist.
Résultat mixed A string or array, depending on whether `$property` is specified.

data() public méthode

Returns all variables and their values that have been set.
public data ( ) : array
Résultat array Key/value pairs of data that has been set.

handlers() public méthode

Gets or adds content handlers from/to this rendering context, depending on the value of $handlers. For more on how to implement handlers and the various types, see applyHandler().
See also: lithium\template\view\Renderer::applyHandler()
See also: lithium\template\view\Renderer::$_handlers
public handlers ( mixed $handlers = null ) : mixed
$handlers mixed If `$handlers` is empty or no value is provided, the current list of handlers is returned. If `$handlers` is a string, the handler with the name matching the string will be returned, or null if one does not exist. If `$handlers` is an array, the handlers named in the array will be merged into the list of handlers in this rendering context, with the pre-existing handlers taking precedence over those newly added.
Résultat mixed Returns an array of handlers or a single handler reference, depending on the value of `$handlers`.

helper() public méthode

Brokers access to helpers attached to this rendering context, and loads helpers on-demand if they are not available.
public helper ( string $name, array $config = [] ) : object
$name string Helper name
$config array
Résultat object

render() abstract public méthode

Render the template with given data. Abstract; must be added to subclasses.
abstract public render ( string $template, array | string $data = [], array $options = [] ) : string
$template string
$data array | string
$options array
Résultat string Returns the result of the rendered template.

request() public méthode

Returns the Request object associated with this rendering context.
public request ( ) : object
Résultat object Returns an instance of `lithium\action\Request`, which provides the context for URLs, etc. which are generated in any templates rendered by this context.

respondsTo() public méthode

Determines if a given method can be called.
public respondsTo ( string $method, boolean $internal = false ) : boolean
$method string Name of the method.
$internal boolean Provide `true` to perform check from inside the class/object. When `false` checks also for public visibility; defaults to `false`.
Résultat boolean Returns `true` if the method can be called, `false` otherwise.

response() public méthode

Returns the Response object associated with this rendering context.
public response ( ) : object
Résultat object Returns an instance of `lithium\action\Response`, which provides the i.e. the encoding for the document being the result of templates rendered by this context.

set() public méthode

Allows variables to be set by one template and used in subsequent templates rendered using the same context. For example, a variable can be set in a template and used in an element rendered within a template, or an element or template could set a variable which would be made available in the layout.
public set ( array $data = [] ) : void
$data array An array of key/value pairs representing local variables that should be made available to all other templates rendered in this rendering context.
Résultat void

strings() public méthode

Manages template strings.
public strings ( mixed $strings = null ) : mixed
$strings mixed
Résultat mixed

view() public méthode

Retuns the View object that controls this rendering context's instance. This can be used, for example, to render view elements, i.e. view()->render('element' $name); ?>.
public view ( ) : object
Résultat object

Property Details

$_autoConfig protected_oe property

These configuration variables will automatically be assigned to their corresponding protected properties when the object is initialized.
protected array $_autoConfig
Résultat array

$_classes protected_oe property

Renderer's dependencies. These classes are used by the output handlers to generate URLs for dynamic resources and static assets.
See also: Renderer::$_handlers
protected array $_classes
Résultat array

$_context protected_oe property

Context values that exist across all templates rendered in this context. These values are usually rendered in the layout template after all other values have rendered.
protected array $_context
Résultat array

$_data protected_oe property

An array containing any additional variables to be injected into view templates. This allows local variables to be communicated between multiple templates (i.e. an element and a layout) which are using the same rendering context.
See also: lithium\template\view\Renderer::set()
protected array $_data
Résultat array

$_handlers protected_oe property

Automatically matches up template strings by name to output handlers. A handler can either be a string, which represents a method name of the helper, or it can be a closure or callable object. A handler takes 3 parameters: the value to be filtered, the name of the helper method that triggered the handler, and the array of options passed to the _render(). These handlers are shared among all helper objects, and are automatically triggered whenever a helper method renders a template string (using _render()) and a key which is to be embedded in the template string matches an array key of a corresponding handler.
See also: lithium\template\view\Renderer::applyHandler()
See also: lithium\template\view\Renderer::handlers()
protected array $_handlers
Résultat array

$_helpers protected_oe property

Contains the list of helpers currently in use by this rendering context. Helpers are loaded via the helper() method, which is called by Renderer::__get(), allowing for on-demand loading of helpers.
protected array $_helpers
Résultat array

$_options protected_oe property

Available options accepted by template\View::render(), used when rendering.
See also: lithium\template\View::render()
protected array $_options
Résultat array

$_request protected_oe property

The Request object instance, if applicable.
protected $_request

$_response protected_oe property

The Response object instance, if applicable.
protected $_response

$_strings protected_oe property

Aggregates named string templates used by helpers. Can be overridden to change the default strings a helper uses.
protected array $_strings
Résultat array

$_vars protected_oe property

Variables that have been set from a view/element/layout/etc. that should be available to the same rendering context.
protected $_vars

$_view protected_oe property

Holds an instance of the View object that created this rendering context. See the view() method for more details.
See also: lithium\template\view\Renderer::view()
protected object $_view
Résultat object