Packageindex Classtrees Modulegroups Elementlist Report XML Files

File: /home/cch/www/pear/PHPDoc/redist/IT.php
PEAR Repository -

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 that
supports 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>
Version1.1 28/09/00

 
Direct known subclasses: IntegratedTemplateExtension

Public Method Summary

void

IntegratedTemplate([ string $root ])

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

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( $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, [ string $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 template
class from this one.

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

See Also setRoot()

get

public void get( [ string $block ] )

  Returns a block with all replacements done.

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

See Also show()

parse

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

  Parses the given block.

Parameter
string $block = >>"__global__"<<
name of the block to be parsed
boolean $flag_recursion
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
string 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__"<<
name 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 function
when a new template is given. Don't use this function
unless 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 the
template manually using this function.

Parameter
string $template
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
name of the template file, full path!
boolean $removeUnknownVariables = >>true<<
remove unknown/unused variables?
boolean $removeEmptyBlocks = >>true<<
remove empty blocks?
Returns boolean

false on failure, otherwise true

See Also $template, setTemplate()

setRoot

public void setRoot( $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 class
on windows.

Parameter
$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
Returns void


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
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
Filename
Returns string

Filecontent


halt

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

  Error Handling function.

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

See Also $err

Public Field Details

$err

public array $err

>>array()<<

See Also halt(), $printError, $haltOnError

$printError

public boolean $printError

>>false<<

See Also halt(), $haltOnError, $err

$haltOnError

public boolean $haltOnError

>>false<<

See Also halt(), $printError, $err

$openingDelimiter

public string $openingDelimiter

>>"{"<<

See Also $closingDelimiter, $blocknameRegExp, $variablenameRegExp

$closingDelimiter

public string $closingDelimiter

>>"}"<<

See Also $openingDelimiter, $blocknameRegExp, $variablenameRegExp

$blocknameRegExp

public string $blocknameRegExp

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

See Also $variablenameRegExp, $openingDelimiter, $closingDelimiter

$variablenameRegExp

public string $variablenameRegExp

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

See Also $blocknameRegExp, $openingDelimiter, $closingDelimiter

Private Field Details

$clearCache

private boolean $clearCache

>>false<<


$variablesRegExp

private string $variablesRegExp

>>""<<

See Also IntegratedTemplate()

$blockRegExp

private string $blockRegExp

>>""<<

See Also IntegratedTemplate()

$currentBlock

private string $currentBlock

>>"__global__"<<


$template

private string $template

>>""<<


$blocklist

private array $blocklist

>>array()<<

See Also findBlocks()

$blockdata

private array $blockdata

>>array()<<


$blockvariables

private array $blockvariables

>>array()<<


$blockinner

private array $blockinner

>>array()<<


$blocktypes

private array $blocktypes

>>array()<<


$variableCache

private array $variableCache

>>array()<<

See Also setVariable(), $clearCacheOnParse

$clearCacheOnParse

private boolean $clearCacheOnParse

>>true<<


$removeUnknownVariables

private boolean $removeUnknownVariables

>>true<<


$removeEmptyBlocks

private boolean $removeEmptyBlocks

>>true<<


$fileRoot

private string $fileRoot

>>""<<

See Also IntegratedTemplate(), setRoot()

$flagBlocktrouble

private boolean $flagBlocktrouble

>>false<<


$flagGlobalParsed

private boolean $flagGlobalParsed

>>false<<



Packageindex Classtrees Modulegroups Elementlist Report XML Files
PHPDoc 1.0beta