PHP Class lithium\template\Helper

Supplies the basic functionality of _render and _options, as well as escaping.
Inheritance: extends lithium\core\Object
显示文件 Open project: unionofrad/lithium Class Usage Examples

Public Properties

Property Type Description
$contentMap array Maps helper method names to content types as defined by the Media class, where key are method names, and values are the content type that the method name outputs a link to.

Protected Properties

Property Type Description
$_autoConfig array Auto configuration properties.
$_classes array This property can be overwritten with any class dependencies a helper subclass has.
$_context lithium\template\view\Renderer The Renderer object this Helper is bound to.
$_minimized array List of minimized HTML attributes.
$_strings array Holds string templates which will be merged into the rendering context.

Public Methods

Method Description
__construct ( array $config = [] ) : void Constructor.
escape ( string $value, mixed $method = null, array $options = [] ) : mixed Escapes values according to the output type of the rendering context. Helpers that output to non-HTML/XML contexts should override this method accordingly.

Protected Methods

Method Description
_attribute ( string $key, mixed $value, array $options = [] ) : string Convert a key/value pair to a valid HTML attribute.
_attributes ( array | string $params, string $method = null, array $options = [] ) : string Converts a set of parameters to HTML attributes into a string.
_init ( ) : void Imports local string definitions into rendering context.
_options ( array $defaults, array $scope ) : array Takes the defaults and current options, merges them and returns options which have the default keys removed and full set of options as the scope.
_render ( string $method, string $string, array $params, array $options = [] ) : string Render a string template after applying context filters Use examples in the Html::link() method: return $this->_render(__METHOD__, 'link', compact('title', 'url', 'options'), $scope);

Method Details

__construct() public method

Constructor.
public __construct ( array $config = [] ) : void
$config array Configuration options.
return void

_attribute() protected method

Convert a key/value pair to a valid HTML attribute.
protected _attribute ( string $key, mixed $value, array $options = [] ) : string
$key string The key name of the HTML attribute.
$value mixed The HTML attribute value.
$options array The options used when converting the key/value pair to attributes: - `'escape'` _boolean_: Indicates whether `$key` and `$value` should be HTML-escaped. Defaults to `true`. - `'format'` _string_: The format string. Defaults to `'%s="%s"'`.
return string Returns an HTML attribute/value pair, in the form of `'$key="$value"'`.

_attributes() protected method

Converts a set of parameters to HTML attributes into a string.
See also: lithium\template\view\Renderer::__call()
protected _attributes ( array | string $params, string $method = null, array $options = [] ) : string
$params array | string The parameters where key is the attribute name and the value the attribute value. When string will simply prepend with the prepend-string (by default `' '`) unless $params is falsey in which case an empty string is returned. This alternative syntax is used by the method internally.
$method string When used as a context handler, the method the handler was called for I.e. `'wrap'`. Currently not used by the method.
$options array Available options are: - `'escape'` _boolean_: Indicates whether the output should be HTML-escaped. Defaults to `true`. - `'prepend'` _string_: String to prepend to each attribute pair. and the final result. Defaults to `' '`. - `'append'` _string_: String to append to result. Defaults to `''`.
return string Attribute string.

_init() protected method

Imports local string definitions into rendering context.
protected _init ( ) : void
return void

_options() protected method

Takes the defaults and current options, merges them and returns options which have the default keys removed and full set of options as the scope.
protected _options ( array $defaults, array $scope ) : array
$defaults array
$scope array the complete set of options
return array $scope, $options

_render() protected method

Render a string template after applying context filters Use examples in the Html::link() method: return $this->_render(__METHOD__, 'link', compact('title', 'url', 'options'), $scope);
protected _render ( string $method, string $string, array $params, array $options = [] ) : string
$method string name of method that is calling the render (for context filters)
$string string template key (in Helper::_strings) to render
$params array associated array of template inserts {:key} will be replaced by value
$options array Available options: - `'handlers'` _array_: Before inserting `$params` inside the string template, `$this->_context`'s handlers are applied to each value of `$params` according to the key (e.g `$params['url']`, which is processed by the `'url'` handler via `$this->_context->applyHandler()`). The `'handlers'` option allow to set custom mapping beetween `$params`'s key and `$this->_context`'s handlers. e.g. the following handler: `'handlers' => array('url' => 'path')` will make `$params['url']` to be processed by the `'path'` handler instead of the `'url'` one.
return string Rendered HTML

escape() public method

Escapes values according to the output type of the rendering context. Helpers that output to non-HTML/XML contexts should override this method accordingly.
public escape ( string $value, mixed $method = null, array $options = [] ) : mixed
$value string
$method mixed
$options array
return mixed

Property Details

$_autoConfig protected_oe property

Auto configuration properties.
protected array $_autoConfig
return array

$_classes protected_oe property

This property can be overwritten with any class dependencies a helper subclass has.
protected array $_classes
return array

$_context protected_oe property

The Renderer object this Helper is bound to.
See also: lithium\template\view\Renderer
protected lithium\template\view\Renderer $_context
return lithium\template\view\Renderer

$_minimized protected_oe property

List of minimized HTML attributes.
protected array $_minimized
return array

$_strings protected_oe property

Holds string templates which will be merged into the rendering context.
protected array $_strings
return array

$contentMap public_oe property

Maps helper method names to content types as defined by the Media class, where key are method names, and values are the content type that the method name outputs a link to.
public array $contentMap
return array