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])
Afficher le fichier Open project: horde/horde Class Usage Examples

Protected Properties

Свойство 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.

Méthodes publiques

Méthode 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.

Méthodes protégées

Méthode 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 méthode

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 méthode

TODO
protected _doReplace ( $replace )

_doSearch() protected méthode

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

_generatePHPVar() protected méthode

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

_parse() protected méthode

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

_parseAssociativeTags() protected méthode

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

_parseGettext() protected méthode

Parses gettext tags.
protected _parseGettext ( )

_parseIf() protected méthode

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

_parseLoop() protected méthode

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 méthode

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

fetch() public méthode

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.
Résultat string The parsed template.

get() public méthode

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

getOption() public méthode

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

parse() public méthode

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

set() public méthode

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 méthode

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 méthode

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
Résultat array

$_basepath protected_oe property

Directory that templates should be read from.
protected string $_basepath
Résultat string

$_cache protected_oe property

The Horde_Cache object to use.
protected Horde_Cache $_cache
Résultat Horde_Cache

$_foreachMap protected_oe property

Foreach variable mappings.
protected array $_foreachMap
Résultat array

$_foreachVar protected_oe property

Foreach variable incrementor.
protected int $_foreachVar
Résultat integer

$_logger protected_oe property

Logger.
protected Horde_Log_Logger $_logger
Résultat Horde_Log_Logger

$_options protected_oe property

Option values.
protected array $_options
Résultat array

$_pregcache protected_oe property

preg_match() cache.
protected array $_pregcache
Résultat array

$_scalars protected_oe property

Tag (scalar) values.
protected array $_scalars
Résultat array

$_template protected_oe property

Template source.
protected string $_template
Résultat string

$_templateFile protected_oe property

Path to template source.
protected string $_templateFile
Résultat string