Gumbo_Template_Engine



Abstract Template Engine Class

A Template Engine defines common methods involved in running template systems. There are many different ways to use template (PHP includes, string replacement, Smarty). A Template system will basically load a file, replacing keywords with values defined inside the program. Each Engine will define a specific implementation for parsing Template files.

The class provides a basic implementation. This allows an Engine to only override certain methods for custom implementation. The common methods allow access to Template variables (and assignment), setting the Template file name (file name or full path), setting the Template directory path (including extra Smarty defined paths), loading global Template settings, and setting the surrounding characters of keywords inside the Template file.

To create a new Template_Engine, simply extend this class, placing the new file into the 'gumbo/template/engine/*' directory. The name should be unique 'Gumbo_Template_Engine_[Name]'. The new Engine will be responsible for parsing a particular type of Template file. Details on how to use the Engine should be defined inside the class.

Template File The Template File can either be a simple file name (combined with the Template Directory) or a full path. When the Template File is parsed, the 'getFullPath' should be used.

 $this->setFile ("my_file.txt");
 $this->setDirTpl ("/path/to/file/");
 ...
 $this->getFullPath (); // outputs '/path/to/file/my_file.txt', if file exists

Template Variables Template Variables are assigned keywords referencing a value determined by the program code. The assigned keys are paired with the Template file, replacing the 'keyword' with the value. Template Variables can be any type, however check the specific Engine on any restrictions defined.

 $this->assign ("key", my_value);
 $this->key = my_value;

Delimeters This is simply a left and right character string surrounding keywords, helping to separate raw text. Inside a basic string replacement Engine, curly braces could surround the keyword '{keyword}' (or any other characters). The parser (if used) should find these replacements.

Author(s): Michael Luster <mluster79@yahoo.com>
License:New BSD License
Copyright:Copyright (c) 2007, iBayou, Michael Luster
Link:http://sourceforge.net/projects/phpgumbo
Version:0.0.1

Implements interfaces:

Child classes:

Class Variables

string $_dir_cache [line 94]
string $_dir_compile [line 92]
string $_dir_config [line 96]
string $_dir_tpl [line 90]
string $_file [line 87]
bool $_formatted [line 104]
string $_left_del [line 99]
string $_output [line 106]
string $_right_del [line 101]
array $_vars = array () [line 84]

Class Methods

public void assign ( string|array $key, [mixed $val] ) [line 208]

Assigns a template variable with a value

Parameter(s):

  • (string|array) $key :: template file reference
  • (mixed) $val
  • throws:  Gumbo_Exception
Overridden in child classes as:
Gumbo_Template_Engine_Basic::assign()
Assigns a template variable with a value


[ Top ]
public void display ( ) [line 162]

Displays the formatted template file


[ Top ]
public bool exists ( ) [line 613]

Returns if the template file exists


[ Top ]
public string fetch ( [bool $reload] ) [line 173]

Returns the formatted template file string

Parameter(s):

  • (bool) $reload :: parses the template file again
  • precondition:  exists()
  • throws:  Gumbo_Exception

[ Top ]
public string getDirCache ( ) [line 532]

Returns the template file cache directory


[ Top ]
public string getDirCompile ( ) [line 524]

Returns the template file compile directory


[ Top ]
public string getDirConfig ( ) [line 540]

Returns the template file config directory


[ Top ]
public string getDirTpl ( ) [line 516]

Returns the template file directory


[ Top ]
public string getFile ( ) [line 508]

Returns the template file name


[ Top ]
public string getFullPath ( ) [line 497]

Returns the full path to the Template file


[ Top ]
public string getLeftDelimeter ( ) [line 579]

Returns the left delimeter


[ Top ]
protected string getOutput ( ) [line 603]

Returns the formatted output template string


[ Top ]
public string getRightDelimeter ( ) [line 587]

Returns the right delimeter


[ Top ]
public mixed getVar ( string $key ) [line 550]

Returns the value of the key reference

Parameter(s):

  • (string) $key :: reference key
  • throws:  Gumbo_Exception

[ Top ]
public array getVars ( ) [line 571]

Returns all the template variables


[ Top ]
protected bool isFormatted ( ) [line 595]

Returns if the template has been formatted


[ Top ]
public void loadGlobals ( [bool $assign_global_vars] ) [line 269]

Loads the global template variables (does not load global Template variables)

Parameter(s):

  • (bool) $assign_global_vars :: also assigns global variables

[ Top ]
protected void parse ( ) [line 117]

Parses the template file into an HTML string

  • abstract:  
  • precondition:  setOutput (null)
  • postcondition:  isFormatted ()
  • precondition:  setFormatted (false)
Overridden in child classes as:
Gumbo_Template_Engine_Basic::parse()
Parses the template file into an HTML string
Gumbo_Template_Engine_Internal::parse()
Parses the template file into an HTML string


[ Top ]
public void reset ( ) [line 258]

Resets the template variables (useful for reloading a List)

  • postcondition:  !isFormatted()
  • postcondition:  !getVars()

[ Top ]
public void setDirCache ( string $loc ) [line 370]

Sets the template file cache directory

Parameter(s):

  • (string) $loc
  • precondition:  is_dir ($loc)
  • throws:  Gumbo_Exception

[ Top ]
public void setDirCompile ( string $loc ) [line 346]

Sets the template file compile directory

Parameter(s):

  • (string) $loc
  • precondition:  is_dir ($loc)
  • throws:  Gumbo_Exception

[ Top ]
public void setDirConfig ( string $loc ) [line 394]

Sets the template file config directory

Parameter(s):

  • (string) $loc
  • precondition:  is_dir ($loc)
  • throws:  Gumbo_Exception

[ Top ]
public void setDirTpl ( string $loc ) [line 323]

Sets the template file directory

Parameter(s):

  • (string) $loc
  • precondition:  is_dir ($loc)
  • throws:  Gumbo_Exception

[ Top ]
public void setFile ( string $file ) [line 303]

Sets the template file name

Parameter(s):

  • (string) $file

[ Top ]
protected void setFormatted ( bool $val ) [line 457]

Sets the template file as formatted

Parameter(s):

  • (bool) $val
  • throws:  Gumbo_Exception

[ Top ]
public void setLeftDelimeter ( string $val ) [line 417]

Sets the left delimeter value

Parameter(s):

  • (string) $val
  • throws:  Gumbo_Exception

[ Top ]
protected void setOutput ( string $output ) [line 476]

Sets the formatted output template string

Parameter(s):

  • (string) $output
  • throws:  Gumbo_Exception

[ Top ]
public void setRightDelimeter ( string $val ) [line 437]

Sets the right delimeter value

Parameter(s):

  • (string) $val
  • throws:  Gumbo_Exception

[ Top ]
public void unassign ( string $key ) [line 236]

Unassigns a template variable

Parameter(s):

  • (string) $key
  • throws:  Gumbo_Exception

[ Top ]
public mixed __get ( string $key ) [line 135]

Returns the value of a template key reference

Parameter(s):

  • (string) $key

[ Top ]
public bool __isset ( string $key ) [line 144]

Returns if the template reference key isset

Parameter(s):

  • (string) $key

[ Top ]
public void __set ( string $key, mixed $val ) [line 126]

Assigns a template variable with a value

Parameter(s):

  • (string) $key :: template file reference
  • (mixed) $val :: primitive type or Gumbo_Interface_Output

[ Top ]
public void __unset ( string $key ) [line 152]

Unassigns a template reference key

Parameter(s):

  • (string) $key

[ Top ]