PHP Class GiTemplate, atk4

- completely remove any code from templates - speed up template parsing and manipulation speed
Author: Romans ([email protected])
Inheritance: extends AbstractModel, implements ArrayAccess
Show file Open project: atk4/atk4

Public Properties

Property Type Description
$default_exception string
$origin_filename Which file template is loaded from.
$settings array Settings are populated from the configuration file, if found.
$tags array This array contains list of all tags found inside template implementing faster access when manipulating the template.
$template array This is a parsed contents of the template organized inside an array. This structure makes it very simple to modify any part of the array.
$template_file
$template_source
$template_type
$top_tags

Public Methods

Method Description
__clone ( )
_getDumpTags ( &$template )
append ( $tag, $value, $encode = true ) Add more content inside a tag.
appendHTML ( $tag, $value )
cloneRegion ( $tag )
del ( $tag ) Empty contents of specified region. If region contains sub-hierarchy, it will be also removed.
dumpTags ( )
eachTag ( $tag, $callable )
exception ( string $message = 'Undefined Exception', string $type = null, string $code = null ) : Exception_Template Returns relevant exception class. Use this method with "throw".
findTemplate ( $template_name ) template loading and parsing
get ( $tag ) Get value of the tag. Note that this may contain an array if tag contains a structure.
getDefaultSettings ( ) This function specifies default settings for SMlite.
getTagRef ( $tag, &$template ) This is a helper method which populates an array pointing to the place in the template referenced by a said tag.
getTagRefList ( $tag, &$template ) For methods which execute action on several tags, this method will return array of templates. You can then iterate through the array and update all the template values.
hasTag ( $tag ) Checks if template has defined a specified tag.
init ( ) Template creation, interface functions
isTopTag ( string $tag ) : boolean Returns true if specified tag is a top-tag of the template.
is_set ( $tag ) Obsolete due to inconsistent naming.
loadTemplate ( $template_name, $ext = null )
loadTemplateFromString ( string $str ) Initialize current template from the supplied string.
offsetExists ( $name ) {{{ ArrayAccess support
offsetGet ( $name )
offsetSet ( $name, $val )
offsetUnset ( $name )
parseTemplate ( $str )
parseTemplateRecursive ( &$input, &$template )
rebuildTags ( )
rebuildTagsRegion ( &$template )
recursiveRender ( &$template )
regTag ( $tag )
reload ( ) Causes the template to be refreshed from it's original source
render ( $region = null )
renderRegion ( &$chunk )
set ( $tag, $value = null, $encode = true ) This function will replace region refered by $tag to a new content.
setHTML ( $tag, $value = null )
tryDel ( $tag ) Similar to del() but won't throw exception if tag is not present.
trySet ( $tag, $value = null, $encode = true ) Check if tag is present inside template. If it does, execute set(); See documentation for set().
trySetHTML ( $tag, $value = null ) Attempt to set value of a tag to a HTML variable. The value is inserted as-is, while regular set() would HTML-encode the values to avoid injection.

Method Details

__clone() public method

public __clone ( )

_getDumpTags() public method

public _getDumpTags ( &$template )

append() public method

Add more content inside a tag.
public append ( $tag, $value, $encode = true )

appendHTML() public method

public appendHTML ( $tag, $value )

cloneRegion() public method

public cloneRegion ( $tag )

del() public method

TODO: This does not dispose of the tags which were previously inside the region. This causes some severe pitfalls for the users and ideally must be checked and proper errors must be generated.
public del ( $tag )

dumpTags() public method

public dumpTags ( )

eachTag() public method

public eachTag ( $tag, $callable )

exception() public method

Returns relevant exception class. Use this method with "throw".
public exception ( string $message = 'Undefined Exception', string $type = null, string $code = null ) : Exception_Template
$message string Static text of exception.
$type string Exception class or class postfix
$code string Optional error code
return Exception_Template

findTemplate() public method

template loading and parsing
public findTemplate ( $template_name )

get() public method

Get value of the tag. Note that this may contain an array if tag contains a structure.
public get ( $tag )

getDefaultSettings() public method

This function specifies default settings for SMlite.
public getDefaultSettings ( )

getTagRef() public method

Because there might be multiple tags and getTagRef is returning only one template, it will return the first occurence: {greeting}hello{/}, {greeting}world{/} calling getTagRef('greeting',$template) will point second argument towards &array('hello');
public getTagRef ( $tag, &$template )

getTagRefList() public method

{greeting}hello{/}, {greeting}world{/} calling getTagRefList('greeting',$template) will point second argument towards array(&array('hello'),&array('world')); If $tag is specified as array, then $templates will contain all occurences of all tags from the array.
public getTagRefList ( $tag, &$template )

hasTag() public method

Checks if template has defined a specified tag.
public hasTag ( $tag )

init() public method

Template creation, interface functions
public init ( )

isTopTag() public method

Since Agile Toolkit 4.3 this tag is always called _top
public isTopTag ( string $tag ) : boolean
$tag string
return boolean

is_set() public method

Obsolete due to inconsistent naming.
public is_set ( $tag )

loadTemplate() public method

public loadTemplate ( $template_name, $ext = null )

loadTemplateFromString() public method

Initialize current template from the supplied string.
public loadTemplateFromString ( string $str )
$str string

offsetExists() public method

{{{ ArrayAccess support
public offsetExists ( $name )

offsetGet() public method

public offsetGet ( $name )

offsetSet() public method

public offsetSet ( $name, $val )

offsetUnset() public method

public offsetUnset ( $name )

parseTemplate() public method

public parseTemplate ( $str )

parseTemplateRecursive() public method

public parseTemplateRecursive ( &$input, &$template )

rebuildTags() public method

public rebuildTags ( )

rebuildTagsRegion() public method

public rebuildTagsRegion ( &$template )

recursiveRender() public method

public recursiveRender ( &$template )

regTag() public method

public regTag ( $tag )

reload() public method

Causes the template to be refreshed from it's original source
public reload ( )

render() public method

public render ( $region = null )

renderRegion() public method

public renderRegion ( &$chunk )

set() public method

If tag is found inside template several times, all occurences are replaced. ALTERNATIVE USE(2) of this function is to pass associative array as a single argument. This will assign multiple tags with one call. Sample use is: set($_GET); would read and set multiple region values from $_GET array.
public set ( $tag, $value = null, $encode = true )

setHTML() public method

public setHTML ( $tag, $value = null )

tryDel() public method

Similar to del() but won't throw exception if tag is not present.
public tryDel ( $tag )

trySet() public method

Check if tag is present inside template. If it does, execute set(); See documentation for set().
public trySet ( $tag, $value = null, $encode = true )

trySetHTML() public method

Attempt to set value of a tag to a HTML variable. The value is inserted as-is, while regular set() would HTML-encode the values to avoid injection.
public trySetHTML ( $tag, $value = null )

Property Details

$default_exception public property

public string $default_exception
return string

$origin_filename public property

Which file template is loaded from.
public $origin_filename

$settings public property

Settings are populated from the configuration file, if found.
public array $settings
return array

$tags public property

This array contains list of all tags found inside template implementing faster access when manipulating the template.
public array $tags
return array

$template public property

This is a parsed contents of the template organized inside an array. This structure makes it very simple to modify any part of the array.
public array $template
return array

$template_file public property

public $template_file

$template_source public property

public $template_source

$template_type public property

public $template_type

$top_tags public property

public $top_tags