PHP Class Horde_Template, horde

Horde_Template provides a basic template engine with tags, loops, and if conditions. However, it is also a simple interface with several essential functions: set(), fetch(), and parse(). Subclasses or decorators can implement (or delegate) these three methods, plus the options api, and easily implement other template engines (PHP code, XSLT, etc.) without requiring usage changes. Compilation code adapted from code written by Bruno Pedro . Copyright 2002-2016 Horde LLC (http://www.horde.org/) See the enclosed file COPYING for license information (LGPL). If you did not receive this file, see http://www.horde.org/licenses/lgpl21.
Author: Chuck Hagenbuch ([email protected])
Author: Michael Slusarz ([email protected])
Exibir arquivo Open project: horde/horde Class Usage Examples

Protected Properties

Property Type Description
$_arrays array Loop tag values.
$_basepath string Directory that templates should be read from.
$_cache Horde_Cache The Horde_Cache object to use.
$_foreachMap array Foreach variable mappings.
$_foreachVar integer Foreach variable incrementor.
$_logger Horde_Log_Logger Logger.
$_options array Option values.
$_pregcache array preg_match() cache.
$_scalars array Tag (scalar) values.
$_template string Template source.
$_templateFile string Path to template source.

Public Methods

Method Description
__construct ( array $params = [] ) Constructor.
fetch ( string $filename = null ) : string Fetches a template from the specified file and return the parsed contents.
get ( string $tag ) : mixed Returns the value of a tag or loop.
getOption ( string $option ) : mixed Returns an option's value.
parse ( string $contents = null ) : string Parses all variables/tags in the template.
set ( string | array $tag, mixed $var ) Sets a tag, loop, or if variable.
setOption ( string $option, mixed $val ) Sets an option.
setTemplate ( string $template ) Set the template contents to a string.

Protected Methods

Method Description
_doReplace ( $replace ) TODO
_doSearch ( $tag, $key, $noclose = false ) TODO
_generatePHPVar ( $tag, $key ) Output the correct PHP variable string for use in template space.
_parse ( ) Parses all variables/tags in the template.
_parseAssociativeTags ( ) Parse associative tags (i.e. ).
_parseGettext ( ) Parses gettext tags.
_parseIf ( string $key = null ) Parses 'if' statements.
_parseLoop ( string $key = null ) Parses the given array for any loops or other uses of the array.
_parseTags ( string $key = null ) Replaces 'tag' tags with their PHP equivalents.

Method Details

__construct() public method

Constructor.
public __construct ( array $params = [] )
$params array The following configuration options:
'basepath' - (string) The directory where templates are read from.
'cacheob' - (Horde_Cache) A caching object used to cache the output.
'logger' - (Horde_Log_Logger) A logger object.

_doReplace() protected method

TODO
protected _doReplace ( $replace )

_doSearch() protected method

TODO
protected _doSearch ( $tag, $key, $noclose = false )

_generatePHPVar() protected method

Output the correct PHP variable string for use in template space.
protected _generatePHPVar ( $tag, $key )

_parse() protected method

Parses all variables/tags in the template.
protected _parse ( )

_parseAssociativeTags() protected method

Parse associative tags (i.e. ).
protected _parseAssociativeTags ( )

_parseGettext() protected method

Parses gettext tags.
protected _parseGettext ( )

_parseIf() protected method

Parses 'if' statements.
protected _parseIf ( string $key = null )
$key string The key prefix to parse.

_parseLoop() protected method

Parses the given array for any loops or other uses of the array.
protected _parseLoop ( string $key = null )
$key string The key prefix to parse.

_parseTags() protected method

Replaces 'tag' tags with their PHP equivalents.
protected _parseTags ( string $key = null )
$key string The key prefix to parse.

fetch() public method

Fetches a template from the specified file and return the parsed contents.
public fetch ( string $filename = null ) : string
$filename string The file to fetch the template from.
return string The parsed template.

get() public method

Returns the value of a tag or loop.
public get ( string $tag ) : mixed
$tag string The tag name.
return mixed The tag value or null if the tag hasn't been set yet.

getOption() public method

Returns an option's value.
public getOption ( string $option ) : mixed
$option string The option name.
return mixed The option's value.

parse() public method

Parses all variables/tags in the template.
public parse ( string $contents = null ) : string
$contents string The unparsed template.
return string The parsed template.

set() public method

Sets a tag, loop, or if variable.
public set ( string | array $tag, mixed $var )
$tag string | array Either the tag name or a hash with tag names as keys and tag values as values.
$var mixed The value to replace the tag with.

setOption() public method

Currently available options are:
'debug' - Output debugging information to screen
'forcecompile' - Force a compilation on every page load
'gettext' - Activate gettext detection
        
public setOption ( string $option, mixed $val )
$option string The option name.
$val mixed The option's value.

setTemplate() public method

Set the template contents to a string.
public setTemplate ( string $template )
$template string The template text.

Property Details

$_arrays protected_oe property

Loop tag values.
protected array $_arrays
return array

$_basepath protected_oe property

Directory that templates should be read from.
protected string $_basepath
return string

$_cache protected_oe property

The Horde_Cache object to use.
protected Horde_Cache $_cache
return Horde_Cache

$_foreachMap protected_oe property

Foreach variable mappings.
protected array $_foreachMap
return array

$_foreachVar protected_oe property

Foreach variable incrementor.
protected int $_foreachVar
return integer

$_logger protected_oe property

Logger.
protected Horde_Log_Logger $_logger
return Horde_Log_Logger

$_options protected_oe property

Option values.
protected array $_options
return array

$_pregcache protected_oe property

preg_match() cache.
protected array $_pregcache
return array

$_scalars protected_oe property

Tag (scalar) values.
protected array $_scalars
return array

$_template protected_oe property

Template source.
protected string $_template
return string

$_templateFile protected_oe property

Path to template source.
protected string $_templateFile
return string