PHP Класс 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.
См. также: lithium\template\View
См. также: lithium\template\adapter\File
См. также: lithium\template\adapter\Simple
Наследование: extends lithium\core\Object
Показать файл Открыть проект Примеры использования класса

Защищенные свойства (Protected)

Свойство Тип Описание
$_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.

Открытые методы

Метод Описание
__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); ?>.

Защищенные методы

Метод Описание
_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.

Описание методов

__call() публичный Метод

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.
См. также: lithium\template\view\Renderer::$_context
См. также: lithium\template\view\Renderer::$_handlers
См. также: 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
Результат mixed

__construct() публичный Метод

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`.
Результат void

__get() публичный Метод

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.
Результат mixed

__isset() публичный Метод

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.
Результат boolean True if set, false otherwise.

_init() защищенный Метод

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
См. также: lithium\net\http\Router::match()
См. также: lithium\net\http\Media::asset()
См. также: lithium\template\Helper::_attributes()
protected _init ( ) : void
Результат void

_render() защищенный Метод

Shortcut method used to render elements and other nested templates from inside the templating layer.
См. также: lithium\template\View::$_processes
См. также: 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()`.
Результат string Returns a the rendered template content as a string.

applyHandler() публичный Метод

- 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.
См. также: lithium\template\view\Renderer::handlers()
См. также: 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.
Результат mixed The transformed value of `$value`, after it has been processed by a handler.

context() публичный Метод

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.
См. также: 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.
Результат mixed A string or array, depending on whether `$property` is specified.

data() публичный Метод

Returns all variables and their values that have been set.
public data ( ) : array
Результат array Key/value pairs of data that has been set.

handlers() публичный Метод

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().
См. также: lithium\template\view\Renderer::applyHandler()
См. также: 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.
Результат mixed Returns an array of handlers or a single handler reference, depending on the value of `$handlers`.

helper() публичный Метод

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
Результат object

render() абстрактный публичный Метод

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
Результат string Returns the result of the rendered template.

request() публичный Метод

Returns the Request object associated with this rendering context.
public request ( ) : object
Результат 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() публичный Метод

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`.
Результат boolean Returns `true` if the method can be called, `false` otherwise.

response() публичный Метод

Returns the Response object associated with this rendering context.
public response ( ) : object
Результат 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() публичный Метод

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.
Результат void

strings() публичный Метод

Manages template strings.
public strings ( mixed $strings = null ) : mixed
$strings mixed
Результат mixed

view() публичный Метод

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
Результат object

Описание свойств

$_autoConfig защищенное свойство

These configuration variables will automatically be assigned to their corresponding protected properties when the object is initialized.
protected array $_autoConfig
Результат array

$_classes защищенное свойство

Renderer's dependencies. These classes are used by the output handlers to generate URLs for dynamic resources and static assets.
См. также: Renderer::$_handlers
protected array $_classes
Результат array

$_context защищенное свойство

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
Результат array

$_data защищенное свойство

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.
См. также: lithium\template\view\Renderer::set()
protected array $_data
Результат array

$_handlers защищенное свойство

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.
См. также: lithium\template\view\Renderer::applyHandler()
См. также: lithium\template\view\Renderer::handlers()
protected array $_handlers
Результат array

$_helpers защищенное свойство

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
Результат array

$_options защищенное свойство

Available options accepted by template\View::render(), used when rendering.
См. также: lithium\template\View::render()
protected array $_options
Результат array

$_request защищенное свойство

The Request object instance, if applicable.
protected $_request

$_response защищенное свойство

The Response object instance, if applicable.
protected $_response

$_strings защищенное свойство

Aggregates named string templates used by helpers. Can be overridden to change the default strings a helper uses.
protected array $_strings
Результат array

$_vars защищенное свойство

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

$_view защищенное свойство

Holds an instance of the View object that created this rendering context. See the view() method for more details.
См. также: lithium\template\view\Renderer::view()
protected object $_view
Результат object