Packageindex Classtrees Modulegroups Elementlist Report XML Files

File: c:/www/apache/doc2//redist/IT.php
PHPDOC 2000/12/03 - PHPDoc

IntegratedTemplate

IntegratedTemplate

Integrated Template - IT

 

public class IntegratedTemplate

Integrated Template - IT
Well there's not much to say about it. I needed a template class thatsupports a single template file with multiple (nested) blocks inside.Usage:$tpl = new IntegratedTemplate( [string filerootdir] );// load a template or set it with setTemplate()$tpl->loadTemplatefile( string filename [, boolean removeUnknownVariables, boolean removeEmptyBlocks] )// set "global" Variables meaning variables not beeing within a (inner) block$tpl->setVariable( string variablename, mixed value );// like with the Isotopp Templates there's a second way to use setVariable()$tpl->setVariable( array ( string varname => mixed value ) );// Let's use any block, even a deeply nested one$tpl->setCurrentBlock( string blockname );// repeat this as often as you neer.$tpl->setVariable( array ( string varname => mixed value ) );$tpl->parseCurrentBlock();// get the parsed template or print it: $tpl->show()$tpl->get();

AuthorsUlf Wendel <uw@netuse.de>
Version$Id: $

 
Direct known subclasses: IntegratedTemplateExtension

Public Method Summary

void

IntegratedTemplate([ string $root ])

Builds some complex regular expressions and optinally sets the file root directory.
string

get([ string $block ])

Returns a block with all replacements done.
void

parse([ string $block ], boolean $flag_recursion)

Parses the given block.
void

parseCurrentBlock()

Parses the current block
void

setVariable(mixed $variable)

Sets a variable value.
boolean

setCurrentBlock([ string $block ])

Sets the name of the current block that is the block where variables are added.
void

init()

Clears all datafields of the object and rebuild the internal blocklist
void

free()

Clears all datafields of the object.
void

setTemplate(string $template)

Sets the template.
boolean

loadTemplatefile(string $filename, [ boolean $removeUnknownVariables, boolean $removeEmptyBlocks ])

Reads a template file from the disk.
void

setRoot(string $root)

Sets the file root. The file root gets prefixed to all filenames passed to the object.

Private Method Summary

void

show([ string $block ])

Print a certain block with all replacements done.
void

buildBlockvariablelist()

Build a list of all variables within a block
void

getGlobalvariables()

Returns a list of all
void

findBlocks(string $string)

Recusively builds a list of all blocks within the template.
string

getFile(string $filename)

Reads a file from disk and returns its content.
void

halt(string $message, [ mixed $file, integer $line ])

Error Handling function.

Public Field Summary

array

$err

Contains the error objects
boolean

$printError

Print error messages?
boolean

$haltOnError

Call die() on error?
string

$openingDelimiter

First character of a variable placeholder ( _ ).
string

$closingDelimiter

Last character of a variable placeholder ( _ ).
string

$blocknameRegExp

RegExp matching a block in the template.
string

$variablenameRegExp

RegExp matching a variable placeholder in the template.

Private Field Summary

boolean

$clearCache

Clear cache on get()?
string

$variablesRegExp

Full RegExp used to find variable placeholder, filled by the constructor.
string

$blockRegExp

Full RegExp used to find blocks an their content, filled by the constructor.
string

$currentBlock

Name of the current block.
string

$template

Content of the template.
array

$blocklist

Array of all blocks and their content.
array

$blockdata

Array with the parsed content of a block.
array

$blockvariables

Array of variables in a block.
array

$blockinner

Array of inner blocks of a block.
array

$blocktypes

Future versions will use this...
array

$variableCache

Variable cache.
boolean

$clearCacheOnParse

boolean

$removeUnknownVariables

Controls the handling of unknown variables, default is remove.
boolean

$removeEmptyBlocks

Controls the handling of empty blocks, default is remove.
string

$fileRoot

Root directory for all file operations.
boolean

$flagBlocktrouble

Internal flag indicating that a blockname was used multiple times.
boolean

$flagGlobalParsed

Flag indicating that the global block was parsed.

Public Method Details

IntegratedTemplate

public void IntegratedTemplate( [ string $root ] )

  Builds some complex regular expressions and optinally sets the file root directory.
Make sure that you call this constructor if you derive your templateclass from this one.

Parameter
string $root = >>""<<
root directory, prefix for all filenames given to the object.
Returns void

See Also setRoot()

get

public string get( [ string $block ] )

  Returns a block with all replacements done.

Parameter
string $block = >>"__global__"<<
of the block
Returns string

See Also show()

parse

public void parse( [ string $block ], boolean $flag_recursion )

  Parses the given block.

Parameter
string $block = >>"__global__"<<
of the block to be parsed
boolean $flag_recursion
Warning: documentation is missing.
Returns void

See Also parseCurrentBlock()

parseCurrentBlock

public void parseCurrentBlock( )

  Parses the current block

Returns void

See Also parse(), setCurrentBlock(), $currentBlock

setVariable

public void setVariable( mixed $variable )

  Sets a variable value.
The function can be used eighter like setVariable( "varname", "value")or with one array $variables["varname"] = "value" given setVariable($variables)quite like phplib templates set_var().

Parameter
mixed $variable
with the variable name or an array %variables["varname"] = "value"
Returns void


setCurrentBlock

public boolean setCurrentBlock( [ string $block ] )

  Sets the name of the current block that is the block where variables are added.

Parameter
string $block = >>"__global__"<<
of the block
Returns boolean

false on failure otherwise true


init

public void init( )

  Clears all datafields of the object and rebuild the internal blocklist
LoadTemplatefile() and setTemplate() automatically call this functionwhen a new template is given. Don't use this functionunless you know what you're doing.

Returns void

See Also free()

free

public void free( )

  Clears all datafields of the object.
Don't use this function unless you know what you're doing.

Returns void

See Also init()

setTemplate

public void setTemplate( string $template )

  Sets the template.
You can eighter load a template file from disk with LoadTemplatefile() or set thetemplate manually using this function.

Parameter
string $template
content
Returns void

See Also LoadTemplatefile(), $template

loadTemplatefile

public boolean loadTemplatefile( string $filename, [ boolean $removeUnknownVariables, boolean $removeEmptyBlocks ] )

  Reads a template file from the disk.

Parameter
string $filename
of the template file, full path!
boolean $removeUnknownVariables = >>true<<
unknown/unused variables?
boolean $removeEmptyBlocks = >>true<<
empty blocks?
Returns boolean

false on failure, otherwise true

See Also $template, setTemplate()

setRoot

public void setRoot( string $root )

  Sets the file root. The file root gets prefixed to all filenames passed to the object.
Make sure that you override this function when using the classon windows.

Parameter
string $root
Returns void

See Also IntegratedTemplate()

Private Method Details

show

private void show( [ string $block ] )

  Print a certain block with all replacements done.

Parameter
string $block = >>"__global__"<<
of the block
Returns void

See Also show()

buildBlockvariablelist

private void buildBlockvariablelist( )

  Build a list of all variables within a block

Returns void


getGlobalvariables

private void getGlobalvariables( )

  Returns a list of all

Returns void


findBlocks

private void findBlocks( string $string )

  Recusively builds a list of all blocks within the template.

Parameter
string $string
that gets scanned
Returns void

See Also $blocklist

getFile

private string getFile( string $filename )

  Reads a file from disk and returns its content.

Parameter
string $filename
Returns string

Filecontent


halt

private void halt( string $message, [ mixed $file, integer $line ] )

  Error Handling function.

Parameter
string $message
message
mixed $file = >>""<<
where the error occured
integer $line = >>0<<
where the error occured
Returns void

See Also $err

Public Field Details

$err

public array $err

>>array()<<

Contains the error objects

See Also halt(), $printError, $haltOnError

$printError

public boolean $printError

>>false<<

Print error messages?

See Also halt(), $haltOnError, $err

$haltOnError

public boolean $haltOnError

>>false<<

Call die() on error?

See Also halt(), $printError, $err

$openingDelimiter

public string $openingDelimiter

>>"{"<<

First character of a variable placeholder ( _ ).

See Also $closingDelimiter, $blocknameRegExp, $variablenameRegExp

$closingDelimiter

public string $closingDelimiter

>>"}"<<

Last character of a variable placeholder ( _ ).

See Also $openingDelimiter, $blocknameRegExp, $variablenameRegExp

$blocknameRegExp

public string $blocknameRegExp

>>"[0-9A-Za-z_-]+"<<

RegExp matching a block in the template.
Per default "sm" is used as the regexp modifier, "i" is missing.That means a case sensitive search is done.

See Also $variablenameRegExp, $openingDelimiter, $closingDelimiter

$variablenameRegExp

public string $variablenameRegExp

>>"[0-9A-Za-z_-]+"<<

RegExp matching a variable placeholder in the template.
Per default "sm" is used as the regexp modifier, "i" is missing.That means a case sensitive search is done.

See Also $blocknameRegExp, $openingDelimiter, $closingDelimiter

Private Field Details

$clearCache

private boolean $clearCache

>>false<<

Clear cache on get()?


$variablesRegExp

private string $variablesRegExp

>>""<<

Full RegExp used to find variable placeholder, filled by the constructor.

See Also IntegratedTemplate()

$blockRegExp

private string $blockRegExp

>>""<<

Full RegExp used to find blocks an their content, filled by the constructor.

See Also IntegratedTemplate()

$currentBlock

private string $currentBlock

>>"__global__"<<

Name of the current block.


$template

private string $template

>>""<<

Content of the template.


$blocklist

private array $blocklist

>>array()<<

Array of all blocks and their content.

See Also findBlocks()

$blockdata

private array $blockdata

>>array()<<

Array with the parsed content of a block.


$blockvariables

private array $blockvariables

>>array()<<

Array of variables in a block.


$blockinner

private array $blockinner

>>array()<<

Array of inner blocks of a block.


$blocktypes

private array $blocktypes

>>array()<<

Future versions will use this...


$variableCache

private array $variableCache

>>array()<<

Variable cache.
Variables get cached before any replacement is done.Advantage: empty blocks can be removed automatically.Disadvantage: might take some more memory

See Also setVariable(), $clearCacheOnParse

$clearCacheOnParse

private boolean $clearCacheOnParse

>>true<<



$removeUnknownVariables

private boolean $removeUnknownVariables

>>true<<

Controls the handling of unknown variables, default is remove.


$removeEmptyBlocks

private boolean $removeEmptyBlocks

>>true<<

Controls the handling of empty blocks, default is remove.


$fileRoot

private string $fileRoot

>>""<<

Root directory for all file operations.
The string gets prefixed to all filenames given.

See Also IntegratedTemplate(), setRoot()

$flagBlocktrouble

private boolean $flagBlocktrouble

>>false<<

Internal flag indicating that a blockname was used multiple times.


$flagGlobalParsed

private boolean $flagGlobalParsed

>>false<<

Flag indicating that the global block was parsed.



Packageindex Classtrees Modulegroups Elementlist Report XML Files
PHPDoc 1.0beta