DotLibrary
[ class tree: DotLibrary ] [ index: DotLibrary ] [ all elements ]

Class: Dot_Template

Source Location: /library/Dot/Template.php

Class Overview


Template engine, based on PHPLIB library


Author(s):

Variables

Methods


Child classes:

View
View Model

Class Details

[line 21]
Template engine, based on PHPLIB library

Template engine, based on PHPLIB library




Tags:

author:  DotKernel Team <team@dotkernel.com>


[ Top ]


Class Variables

static $_instance =  null

[line 122]

Singleton instance

Singleton instance




Tags:

access:  protected

Type:   Dot_Template


[ Top ]

$debug =  false

[line 28]

If set, echo assignments

If set, echo assignments




Tags:

access:  private

Type:   bool


[ Top ]

$debugBlock =  false

[line 34]

If set, echo blocks time parse

If set, echo blocks time parse




Tags:

access:  private

Type:   bool


[ Top ]

$endTime = array()

[line 115]

End time

End time




Tags:

access:  private

Type:   array


[ Top ]

$file = array()

[line 46]

$file[handle] = 'filename';

$file[handle] = 'filename';




Tags:

access:  private

Type:   array


[ Top ]

$fileFallbacks = array()

[line 52]

fallback paths that should be defined in a child class

fallback paths that should be defined in a child class




Tags:

access:  private

Type:   array


[ Top ]

$filenameComments =  false

[line 95]

Determines whether Template outputs filename comments.

Determines whether Template outputs filename comments. false = no filename outputs true = HTML comments (e.g. <!-- START FILE $filename -->) placed in output




Tags:

access:  private

Type:   string


[ Top ]

$haltOnError =  'yes'

[line 80]

'yes' => halt,

'yes' => halt, 'report' => report error, continue, 'no' => ignore error quietly




Tags:

access:  private

Type:   string


[ Top ]

$lastError =  ''

[line 87]

The last error message is retained here

The last error message is retained here




Tags:

see:  Dot_Template::halt()
access:  private

Type:   string


[ Top ]

$root =  '..'

[line 40]

Relative filenames are relative to this pathname

Relative filenames are relative to this pathname




Tags:

access:  private

Type:   string


[ Top ]

$start_time = array()

[line 109]

Start time

Start time




Tags:

access:  private

Type:   array


[ Top ]

$unknownRegexp =  'loose'

[line 103]

Determines the regular expression used to find unknown variable tags.

Determines the regular expression used to find unknown variable tags. 'loose' = traditional match all curly braces with no whitespace between 'strict' = adopts PHP's variable naming rules




Tags:

access:  private

Type:   bool


[ Top ]

$unknowns =  'remove'

[line 72]

'remove' => remove undefined variables

'remove' => remove undefined variables 'comment' => replace undefined variables with comments 'keep' => keep undefined variables




Tags:

access:  private

Type:   string


[ Top ]

$varkeys = array()

[line 58]

$varkeys[key] = 'key'

$varkeys[key] = 'key'




Tags:

access:  private

Type:   array


[ Top ]

$varvals = array()

[line 64]

$varvals[key] = 'value';

$varvals[key] = 'value';




Tags:

access:  private

Type:   array


[ Top ]



Class Methods


static method getInstance [line 153]

static Dot_Template getInstance( [string $root = '.'], [string $unknowns = 'remove'], [array $fallback = ''])

Returns an instance of Dot_View

Returns an instance of Dot_View Singleton pattern implementation




Tags:

access:  public


Overridden in child classes as:

View::getInstance()
Returns an instance of Dot_View

Parameters:

string   $root   Template root directory
string   $unknowns   How to handle unknown variables
array   $fallback   Fallback paths

[ Top ]

constructor __construct [line 131]

void __construct( [string $root = '.'], [string $unknowns = 'remove'], [array $fallback = ''])

Singleton pattern implementation makes 'new' unavailable

Singleton pattern implementation makes 'new' unavailable




Tags:

access:  protected


Overridden in child classes as:

Page_View::__construct()
Constructor
User_View::__construct()
Constructor

Parameters:

string   $root   Template root directory
string   $unknowns   How to handle unknown variables
array   $fallback   Fallback paths

[ Top ]

method endTimer [line 199]

float endTimer( $varname)

Return the end time

Return the end time




Tags:

access:  private


Parameters:

   $varname  

[ Top ]

method exists [line 226]

bool exists( string|array $var)

Inspired From PEAR HTML_Template_PHPLIB 1. Checks if the given variable exists.

Inspired From PEAR HTML_Template_PHPLIB 1.4.0 Checks if the given variable exists. When an array is given, it is checked if all variables exist.




Tags:

access:  public


Parameters:

string|array   $var   Variable to check

[ Top ]

method filename [line 730]

string filename( string $filename)

When called with a relative pathname, this function will return the pathname with $this->root prepended.

When called with a relative pathname, this function will return the pathname with $this->root prepended. Absolute pathnames are returned unchanged. RETURNS: a string containing an absolute pathname. USAGE: filename(string $filename)




Tags:

see:  set_root
access:  private


Parameters:

string   $filename  

[ Top ]

method finish [line 675]

string finish( string $str)

Returns the finished version of $str.

Returns the finished version of $str. USAGE: finish(string $str)




Tags:

access:  public


Parameters:

string   $str  

[ Top ]

method get [line 716]

void get( string $varname)

Returns the finished version of the value of the variable named by $varname.

Returns the finished version of the value of the variable named by $varname. USAGE: get(string $varname)




Tags:

access:  public


Parameters:

string   $varname  

[ Top ]

method getLastError [line 857]

boolean|string getLastError( )

Returns the last error message if any

Returns the last error message if any




Tags:

return:  Last error message if any
access:  public


[ Top ]

method getUndefined [line 637]

array getUndefined( string $varname)

Returns a hash of unresolved variable names in $varname, keyed by their names (that is, the hash has the form $a[$name] = $name).

Returns a hash of unresolved variable names in $varname, keyed by their names (that is, the hash has the form $a[$name] = $name). USAGE: getUndefined(string $varname)




Tags:

return:  or false
access:  public


Parameters:

string   $varname  

[ Top ]

method getVar [line 603]

mixed getVar( mixed $varname)

Returns the value of the variable named by $varname.

Returns the value of the variable named by $varname. If $varname references a file and that file has not been loaded yet, the variable will be reported as empty. When called with an array of variable names this public function will return a a hash of variable values keyed by their names. USAGE: getVar(string $varname) or USAGE: getVar(array $varname)




Tags:

access:  public


Parameters:

mixed   $varname  

[ Top ]

method getVars [line 581]

array getVars( )

Returns an associative array of all defined variables with the name as the key and the value of the variable as the value.

Returns an associative array of all defined variables with the name as the key and the value of the variable as the value. This is mostly useful for debugging. Also note that $this->debug can be used to echo all variable assignments as they occur and to trace execution. USAGE: getVars()




Tags:

access:  public


[ Top ]

method halt [line 816]

bool halt( string $msg)

Is called whenever an error occurs and will handle the error according to the policy defined in $this->haltOnError. in $this->lastError.

Is called whenever an error occurs and will handle the error according to the policy defined in $this->haltOnError. Additionally the error message will be saved in $this->lastError. USAGE: halt(string $msg)




Tags:

access:  private


Parameters:

string   $msg  

[ Top ]

method haltMsg [line 838]

void haltMsg( string $msg)

Prints an error message.

Prints an error message. It can be overridden by your subclass of Template. It will be called with an error message to display. USAGE: haltMsg(string $msg)




Tags:

access:  private


Parameters:

string   $msg  

[ Top ]

method initBlock [line 934]

bool initBlock( mixed $target, [mixed $value = ''], [ $append = false], string $name)

Initialize a block A variable $parent may contain a variable block defined by: &lt;!-- BEGIN $varname --&gt; content &lt;!-- END $varname --&gt;.

Initialize a block A variable $parent may contain a variable block defined by: &lt;!-- BEGIN $varname --&gt; content &lt;!-- END $varname --&gt;. This public function removes that block from $parent and replaces it with a variable reference named $name. The block is inserted into the varkeys and varvals hashes. If $name is omitted, it is assumed to be the same as $varname. Blocks may be nested but care must be taken to extract the blocks in order from the innermost block to the outermost block. USAGE: setBlock(string $parent, string $varname, [string $name = ''])




Tags:

access:  public


Parameters:

mixed   $target  
mixed   $value  
string   $name  
   $append  

[ Top ]

method initVar [line 888]

void initVar( mixed $varname, [mixed $value = ''], [bool $append = false])

Initialize the value of a variable.

Initialize the value of a variable. It may be called with either a varname and a value as two strings or an an associative array with the key being the varname and the value being the new variable value. The public function inserts the new value of the variable into the $varkeys and $varvals hashes. It is not necessary for a variable to exist in these hashes before calling this public function. An optional third parameter allows the value for each varname to be appended to the existing variable instead of replacing it. The default is to replace. USAGE: initVar(string $varname, [string $value = ''], [boolean $append = false]) or USAGE: initVar(array $varname = (string $varname => string $value), [mixed $dummy_var], [boolean $append = false]) or USAGE: initVar(array $varname = (string $value), [mixed $dummy_var], [boolean $append = false])




Tags:

access:  public


Parameters:

mixed   $varname  
mixed   $value  
bool   $append  

[ Top ]

method loadFile [line 779]

bool loadFile( string $varname)

If a variable's value is undefined and the variable has a filename stored in $this->file[$varname] then the backing file will be loaded and the file's contents will be assigned as the variable's value.

If a variable's value is undefined and the variable has a filename stored in $this->file[$varname] then the backing file will be loaded and the file's contents will be assigned as the variable's value. USAGE: loadFile(string $varname)




Tags:

access:  private


Parameters:

string   $varname  

[ Top ]

method p [line 705]

void p( string $varname)

Prints the finished version of the value of the variable named by $varname.

Prints the finished version of the value of the variable named by $varname. USAGE: p(string $varname)




Tags:

access:  public


Parameters:

string   $varname  

[ Top ]

method parse [line 510]

mixed parse( string $target, mixed $varname, [bool $append = false])

Substitutes the values of all defined variables in the variable named $varname and stores or appends the result in the variable named $target.

Substitutes the values of all defined variables in the variable named $varname and stores or appends the result in the variable named $target. It may be called with either a target and a varname as two strings or a target as a string and an array of variable names in varname. The public function inserts the new value of the variable into the $varkeys and $varvals hashes. It is not necessary for a variable to exist in these hashes before calling this public function. An optional third parameter allows the value for each varname to be appended to the existing target variable instead of replacing it. The default is to replace. If $target and $varname are both strings, the substituted value of the variable $varname is inserted into or appended to $target. If $handle is an array of variable names the variables named by $handle are sequentially substituted and the result of each substitution step is inserted into or appended to in $target. The resulting substitution is available in the variable named by $target, as is each intermediate step for the next $varname in sequence. Note that while it is possible, it is only rarely desirable to call this public function with an array of varnames and with $append = true. USAGE: parse(string $target, string $varname, [boolean $append]) or USAGE: parse(string $target, array $varname = (string $varname), [boolean $append])




Tags:

access:  public


Parameters:

string   $target  
mixed   $varname  
bool   $append  

[ Top ]

method pparse [line 557]

bool pparse( string $target, mixed $varname, [bool $append = false])

This is shorthand for print $this->parse(.

This is shorthand for print $this->parse(...) and is public functionally identical. USAGE: pparse(string $target, string $varname, [boolean $append]) or USAGE: pparse(string $target, array $varname = (string $varname), [boolean $append])




Tags:

return:  FALSE
access:  public


Parameters:

string   $target  
mixed   $varname  
bool   $append  

[ Top ]

method psubst [line 476]

bool psubst( string $varname)

This is shorthand for print $this->subst($varname).

This is shorthand for print $this->subst($varname). See subst for further details. USAGE: psubst(string $varname)




Tags:

access:  public


Parameters:

string   $varname  

[ Top ]

method setBlock [line 301]

bool setBlock( string $parent, string $varname, [string $name = ''])

A variable $parent may contain a variable block defined by: &lt;!-- BEGIN $varname --&gt; content &lt;!-- END $varname --&gt;.

A variable $parent may contain a variable block defined by: &lt;!-- BEGIN $varname --&gt; content &lt;!-- END $varname --&gt;. This public function removes that block from $parent and replaces it with a variable reference named $name. The block is inserted into the varkeys and varvals hashes. If $name is omitted, it is assumed to be the same as $varname. Blocks may be nested but care must be taken to extract the blocks in order from the innermost block to the outermost block. USAGE: setBlock(string $parent, string $varname, [string $name = ''])




Tags:

access:  public


Parameters:

string   $parent  
string   $varname  
string   $name  

[ Top ]

method setFile [line 256]

bool setFile( string $varname, [string $filename = ''])

Defines a filename for the initial value of a variable.

Defines a filename for the initial value of a variable. It may be passed either a varname and a file name as two strings or a hash of strings with the key being the varname and the value being the file name. The new mappings are stored in the array $this->file. The files are not loaded yet, but only when needed. USAGE: setFile(array $filelist = (string $varname => string $filename)) or USAGE: setFile(string $varname, string $filename)




Tags:

access:  public


Parameters:

string   $varname  
string   $filename  

[ Top ]

method setRoot [line 168]

bool setRoot( $root)

Checks that $root is a valid directory and if so sets this directory as the base directory from which templates are loaded by storing the value in $this->root.

Checks that $root is a valid directory and if so sets this directory as the base directory from which templates are loaded by storing the value in $this->root. Relative filenames are prepended with the path in $this->root.




Tags:

access:  public


Parameters:

   $root  

[ Top ]

method setUnknowns [line 214]

void setUnknowns( [string $unknowns = 'remove'])

Sets the policy for dealing with unresolved variable names.

Sets the policy for dealing with unresolved variable names.




Tags:

access:  public


Parameters:

string   $unknowns   - default = 'remove'

[ Top ]

method setVar [line 353]

bool setVar( mixed $varname, [mixed $value = ''], [bool $append = false])

Sets the value of a variable.

Sets the value of a variable. It may be called with either a varname and a value as two strings or an an associative array with the key being the varname and the value being the new variable value. The public function inserts the new value of the variable into the $varkeys and $varvals hashes. It is not necessary for a variable to exist in these hashes before calling this public function. An optional third parameter allows the value for each varname to be appended to the existing variable instead of replacing it. The default is to replace. This feature was introduced after the 7.2d release. USAGE: setVar(string $varname, [string $value = ''], [boolean $append = false]) or USAGE: setVar(array $varname = (string $varname => string $value), [mixed $dummy_var], [boolean $append = false])




Tags:

access:  public


Parameters:

mixed   $varname  
mixed   $value  
bool   $append  

[ Top ]

method startTimer [line 187]

array startTimer( )

Start the time to measure something

Start the time to measure something




Tags:

access:  private


[ Top ]

method subst [line 451]

mixed subst( mixed $varname)

Fills in all the variables contained within the variable named $varname. original value of the variable varname is not changed. is not 'finished'.

Fills in all the variables contained within the variable named $varname. The resulting value is returned as the public function result and the original value of the variable varname is not changed. The resulting string is not 'finished'. RETURNS: the value of the variable $varname with all variables substituted or FALSE if halted USAGE: subst(string $varname)




Tags:

access:  public


Parameters:

mixed   $varname  

[ Top ]

method unsetVar [line 409]

void unsetVar( mixed $varname)

Unsets a variable completely.

Unsets a variable completely. It may be called with either a varname as a string or an array with the values being the varnames to be cleared. The public function removes the variable from the $varkeys and $varvals hashes. It is not necessary for a variable to exist in these hashes before calling this public function. USAGE: unsetVar(string $varname) or USAGE: unsetVar(array $varname = (string $varname))




Tags:

access:  public


Parameters:

mixed   $varname  

[ Top ]

method varname [line 766]

string varname( string $varname)

Will construct a regexp for a given variable name with any special chars quoted.

Will construct a regexp for a given variable name with any special chars quoted.




Tags:

access:  private


Parameters:

string   $varname  

[ Top ]

method __clone [line 142]

void __clone( )

Singleton pattern implementation makes 'clone' unavailable

Singleton pattern implementation makes 'clone' unavailable




Tags:

access:  protected


[ Top ]


Documentation generated on Wed, 21 Jul 2010 07:34:44 +0000 by phpDocumentor 1.4.3