PHP Class SMlite, atk4

- completely remove any code from templates - make templates editable with HTML editor
Author: Romans ([email protected])
Inheritance: extends AbstractModel
Show file Open project: atk4/atk4 Class Usage Examples

Public Properties

Property Type Description
$origin_filename Which file template is coming from.
$settings private
$tags This array contains list of all tags found inside template.
$template This is a parsed contents of the template.
$template_type Type of resource to look for pathFinder
$top_tag When cloning region inside a template, it's tag becomes a top_tag of a new template. Since SMlite 1.1 it's present in new template and can be used.
$updated_tag_list list of updated tags with values.

Protected Properties

Property Type Description
$tmp_template

Public Methods

Method Description
__clone ( )
append ( $tag, $value, $encode = true ) This appends static content to region refered by a tag. This function is useful when you are adding more rows to a list or table.
appendHTML ( $tag, $value )
cloneRegion ( $tag )
debugRender ( ) : string
debugRenderRegion ( &$chunk ) : string
del ( $tag )
dumpTags ( ) Misc functions
eachTag ( $tag, $callable )
exception ( $message = 'Undefined Exception', $type = null, $code = null )
findTemplate ( $template_name ) template loading and parsing
get ( $tag ) Finds tag and returns contents.
getDefaultSettings ( ) : array This function specifies default settings for SMlite. Use 2nd argument for constructor to redefine those settings.
getTagVal ( $tag )
hasTag ( $tag ) Check if tag is present inside template
init ( ) Template creation, interface functions
isTopTag ( $tag ) : boolean
is_set ( $tag )
loadTemplate ( string $template_name, string $ext = null )
loadTemplateFromString ( string $template_string )
myStrTok ( &$string, string $tok ) : string
parseTemplate ( &$template, integer $level, integer $pc ) : string
rebuildTags ( ) Rebuild tags of existing array structure
rebuildTagsRegion ( &$branch )
registerTag ( $key, $npk, &$ref )
render ( ) : string | array Template rendering (array -> string)
renderRegion ( &$chunk ) : string | array
set ( $tag, $value = null, $encode = true )
setHTML ( $tag, $value = null )
setMessage ( $tag, $args = [] ) Provided that the HTML tag contains ICU-compatible message format string, it will be localized then integrated with passed arguments.
tryDel ( $tag )
trySet ( $tag, $value = null, $encode = true )
trySetHTML ( $tag, $value = null )

Method Details

__clone() public method

public __clone ( )

append() public method

If tag is used for several regions inside template, they all will be appended with new data.
public append ( $tag, $value, $encode = true )

appendHTML() public method

public appendHTML ( $tag, $value )

cloneRegion() public method

public cloneRegion ( $tag )

debugRender() public method

public debugRender ( ) : string
return string

debugRenderRegion() public method

public debugRenderRegion ( &$chunk ) : string
return string

del() public method

public del ( $tag )

dumpTags() public method

Misc functions
public dumpTags ( )

eachTag() public method

public eachTag ( $tag, $callable )

exception() public method

public exception ( $message = 'Undefined Exception', $type = null, $code = null )

findTemplate() public method

template loading and parsing
public findTemplate ( $template_name )

get() public method

THIS FUNTION IS DANGEROUS! - if you want a rendered region, use renderRegion() - if you want a sub-template use cloneRegion() - if you want to copy part of template to other SMlite object, do not forget to call rebuildTags() if you plan to refer them. Not calling rebuildTags() will render template properly anyway. If tag is defined multiple times, first region is returned.
public get ( $tag )

getDefaultSettings() public method

A small note why I decided on .html extension. I want to point out that template files are and should be valid HTML documents. With .html extension those files will be properly rendered inside web browser, properly understood inside text editor or will be properly treated with wysiwyg html editors.
public getDefaultSettings ( ) : array
return array

getTagVal() public method

public getTagVal ( $tag )

hasTag() public method

Check if tag is present inside template
public hasTag ( $tag )

init() public method

Template creation, interface functions
public init ( )

isTopTag() public method

public isTopTag ( $tag ) : boolean
return boolean

is_set() public method

public is_set ( $tag )

loadTemplate() public method

public loadTemplate ( string $template_name, string $ext = null )
$template_name string
$ext string

loadTemplateFromString() public method

public loadTemplateFromString ( string $template_string )
$template_string string

myStrTok() public method

public myStrTok ( &$string, string $tok ) : string
$tok string
return string

parseTemplate() public method

public parseTemplate ( &$template, integer $level, integer $pc ) : string
$level integer
$pc integer
return string

rebuildTags() public method

This function walks through template and rebuilds list of tags. You need it in case you changed already parsed template.
public rebuildTags ( )

rebuildTagsRegion() public method

public rebuildTagsRegion ( &$branch )

registerTag() public method

public registerTag ( $key, $npk, &$ref )

render() public method

Template rendering (array -> string)
public render ( ) : string | array
return string | array

renderRegion() public method

public renderRegion ( &$chunk ) : string | array
return string | array

set() public method

public set ( $tag, $value = null, $encode = true )

setHTML() public method

public setHTML ( $tag, $value = null )

setMessage() public method

Provided that the HTML tag contains ICU-compatible message format string, it will be localized then integrated with passed arguments.
public setMessage ( $tag, $args = [] )

tryDel() public method

public tryDel ( $tag )

trySet() public method

public trySet ( $tag, $value = null, $encode = true )

trySetHTML() public method

public trySetHTML ( $tag, $value = null )

Property Details

$origin_filename public property

Which file template is coming from.
public $origin_filename

$settings public property

private
public $settings

$tags public property

This array contains list of all tags found inside template.
public $tags

$template public property

This is a parsed contents of the template.
public $template

$template_type public property

Type of resource to look for pathFinder
public $template_type

$tmp_template protected property

protected $tmp_template

$top_tag public property

When cloning region inside a template, it's tag becomes a top_tag of a new template. Since SMlite 1.1 it's present in new template and can be used.
public $top_tag

$updated_tag_list public property

list of updated tags with values.
public $updated_tag_list