Class Dwoo

Description

main dwoo class, allows communication between the compiler, template and data classes

 requirements :
  php 5.2.0 or above
  SPL and PCRE extensions (for php versions prior to 5.3.0)
  mbstring extension for some string manipulation plugins (especially if you intend to use UTF-8)
 recommended :
  hash extension (for Dwoo_Template_String - minor performance boost)

 project created :
  2008-01-05

This software is provided 'as-is', without any express or implied warranty. In no event will the authors be held liable for any damages arising from the use of this software.

This file is released under the LGPL "GNU Lesser General Public License" More information can be found here: http://www.gnu.org/copyleft/lesser.html

Located in /Dwoo.php (line 66)


	
			
Direct descendents
Class Description
Dwoo_Smarty__Adapter a Smarty compatibility layer for Dwoo
Class Constant Summary
Variable Summary
Method Summary
Dwoo __construct ([string $compileDir = null], [string $cacheDir = null])
void addFilter (mixed $callback, [bool $autoload = false])
void addPlugin (string $name, callback $callback, [bool $compilable = false])
void addResource (string $name, string $class, [callback $compilerFactory = null])
Dwoo_Block_Plugin addStack (string $blockName, [ $args = array()])
mixed arrayMap (string $callback,  $params)
bool assignInScope (mixed $value, string $scope)
string classCall (string $plugName, [ $params = array()])
int clearCache ([int $olderThan = -1])
void delStack ()
Dwoo_Block_Plugin findBlock (string $type)
array forceScope (mixed $scope)
string get ( $_tpl, [mixed $data = array()], [ $_compiler = null], [ $_output = false], mixed $tpl, Dwoo_ICompiler $compiler, bool $output)
string getCacheDir ()
int getCacheTime ()
string getCharset ()
string getCompileDir ()
array getCustomPlugins ()
array getData ()
callback getDefaultCompilerFactory (string $resourceName)
mixed getObjectPlugin (string $class)
&mixed &getScope ()
bool isArray (mixed $value, [bool $checkIsEmpty = false], [bool $allowNonCountable = false])
bool isCached (Dwoo_ITemplate $tpl)
string output (mixed $tpl, [mixed $data = array()], [Dwoo_ICompiler $compiler = null])
mixed readParentVar (int $parentLevels, [string $varstr = null])
mixed readVar (string $varstr)
mixed readVarInto (string $varstr, mixed $data)
void removeFilter (mixed $callback)
void removePlugin (string $name)
void removeResource (string $name)
void setCacheDir (string $dir)
void setCacheTime (int $seconds)
void setCharset (string $charset)
void setCompileDir (string $dir)
void setDefaultCompilerFactory (string $resourceName, callback $compilerFactory)
void setLoader (Dwoo_ILoader $loader)
void setPluginProxy (Dwoo_IPluginProxy $pluginProxy)
array setScope (mixed $scope, [bool $absolute = false])
void setSecurityPolicy ([Dwoo_Security_Policy $policy = null])
Dwoo_ITemplate templateFactory (string $resourceName, string $resourceId, [int $cacheTime = null], [string $cacheId = null], [string $compileId = null])
void triggerError (string $message, [int $level = E_USER_NOTICE])
void __clone ()
Variables
string $buffer (line 270)

stores the output buffer during template runtime

  • access: protected
string $cacheDir (line 149)

directory where the cached templates are stored

defaults to DWOO_CACHEDIR (= DWOO_DIRECTORY/cache by default)

  • access: protected
int $cacheTime = 0 (line 162)

defines how long (in seconds) the cached files must remain valid

can be overriden on a per-template basis

-1 = never delete

  1. = disabled
>0 = duration in seconds

  • access: protected
string $charset = 'utf-8' (line 113)

character set of the template, used by string manipulation plugins

it must be lowercase, but setCharset() will take care of that

string $compileDir (line 140)

directory where the compiled templates are stored

defaults to DWOO_COMPILEDIR (= DWOO_DIRECTORY/compiled by default)

  • access: protected
Dwoo_Block_Plugin $curBlock (line 263)

stores the current block plugin at the top of the stack during template runtime

  • access: protected
array $data (line 235)

stores the data during template runtime

  • access: protected
array $filters = array() (line 187)

stores the filter callbacks

array $globals (line 131)

global variables that are accessible through $dwoo.* in the templates

default values include:

$dwoo.version - current version number $dwoo.ad - a Powered by Dwoo link pointing to dwoo.org $dwoo.now - the current time $dwoo.template - the current template filename $dwoo.charset - the character set used by the template

on top of that, foreach and other plugins can store special values in there, see their documentation for more details.

  • access: protected
Dwoo_ILoader $loader = null (line 214)

the dwoo loader object used to load plugins by this dwoo instance

  • access: protected
Dwoo_IPluginProxy $pluginProxy (line 277)

stores plugin proxy

  • access: protected
array $plugins = array() (line 178)

stores the custom plugins callbacks

array $resources = array
(
'file' => array
(
'class' => 'Dwoo_Template_File',
'compiler' => null
),'string'=>array('class'=>'Dwoo_Template_String','compiler'=>null))
(line 195)

stores the resource types and associated classes / compiler classes

  • access: protected
array $runtimePlugins (line 228)

stores the instances of the class plugins during template runtime

  • access: protected
mixed $scope (line 242)

stores the current scope during template runtime

  • access: protected
array $scopeTree (line 249)

stores the scope tree during template runtime

  • access: protected
Dwoo_Security_Policy $securityPolicy = null (line 169)

security policy object

  • access: protected
array $stack (line 256)

stores the block plugins stack during template runtime

  • access: protected
Dwoo_ITemplate $template = null (line 221)

currently rendered template, set to null when not-rendering

  • access: protected
Methods
Constructor __construct (line 285)

constructor, sets the cache and compile dir to the default values if not provided

  • access: public
Dwoo __construct ([string $compileDir = null], [string $cacheDir = null])
  • string $compileDir: path to the compiled directory, defaults to lib/compiled
  • string $cacheDir: path to the cache directory, defaults to lib/cache

Redefined in descendants as:
addFilter (line 548)

adds a filter to this Dwoo instance, it will be used to filter the output of all the templates rendered by this instance

  • access: public
void addFilter (mixed $callback, [bool $autoload = false])
  • mixed $callback: a callback or a filter name if it is autoloaded from a plugin directory
  • bool $autoload: if true, the first parameter must be a filter name from one of the plugin directories
addPlugin (line 508)

adds a custom plugin that is not in one of the plugin directories

  • access: public
void addPlugin (string $name, callback $callback, [bool $compilable = false])
  • string $name: the plugin name to be used in the templates
  • callback $callback: the plugin callback, either a function name, a class name or an array containing an object or class name and a method name
  • bool $compilable: if set to true, the plugin is assumed to be compilable
addResource (line 601)

adds a resource or overrides a default one

  • access: public
void addResource (string $name, string $class, [callback $compilerFactory = null])
  • string $name: the resource name
  • string $class: the resource class (which must implement Dwoo_ITemplate)
  • callback $compilerFactory: the compiler factory callback, a function that must return a compiler instance used to compile this resource, if none is provided. by default it will produce a Dwoo_Compiler object
addStack (line 954)

[runtime function] adds a block to the block stack

  • return: the newly created block
  • access: public
Dwoo_Block_Plugin addStack (string $blockName, [ $args = array()])
  • string $blockName: the block name (without Dwoo_Plugin_ prefix)
  • array $args: the arguments to be passed to the block's init() function
arrayMap (line 1123)

[runtime function] calls a php function

  • return: the return value of the called function
  • access: public
mixed arrayMap (string $callback,  $params)
  • string $callback: the function to call
  • array $params: an array of parameters to send to the function
assignInScope (line 1420)

[runtime function] assign the value to the given variable

  • return: true if assigned correctly or false if a problem occured while parsing the var string
  • access: public
bool assignInScope (mixed $value, string $scope)
  • mixed $value: the value to assign
  • string $scope: the variable string, using dwoo variable syntax (i.e. "var.subvar[subsubvar]->property")
classCall (line 1094)

[runtime function] calls the process() method of the given class-plugin name

  • return: the process() return value
  • access: public
string classCall (string $plugName, [ $params = array()])
  • string $plugName: the class plugin name (without Dwoo_Plugin_ prefix)
  • array $params: an array of parameters to send to the process() method
clearCache (line 858)

[util function] clears the cached templates if they are older than the given time

  • return: the amount of templates cleared
  • access: public
int clearCache ([int $olderThan = -1])
  • int $olderThan: minimum time (in seconds) required for a cached template to be cleared
delStack (line 997)

[runtime function] removes the plugin at the top of the block stack

calls the block buffer() function, followed by a call to end() and finally a call to process()

  • access: public
void delStack ()
findBlock (line 1053)

[runtime function] finds the closest block of the given type, starting at the top of the stack

  • return: or false if no plugin of such type is in the stack
  • access: public
Dwoo_Block_Plugin findBlock (string $type)
  • string $type: the type of plugin you want to find
forceScope (line 1536)

[runtime function] forces an absolute scope

  • return: the current scope tree
  • see: Dwoo::setScope()
  • deprecated:
  • access: public
array forceScope (mixed $scope)
  • mixed $scope: a scope as a string or array
get (line 344)

returns the given template rendered using the provided data and optional compiler

  • return: nothing or the template output if $output is true
  • access: public
string get ( $_tpl, [mixed $data = array()], [ $_compiler = null], [ $_output = false], mixed $tpl, Dwoo_ICompiler $compiler, bool $output)
  • mixed $tpl: template, can either be a Dwoo_ITemplate object (i.e. Dwoo_Template_File), a valid path to a template, or a template as a string it is recommended to provide a Dwoo_ITemplate as it will probably make things faster, especially if you render a template multiple times
  • mixed $data: the data to use, can either be a Dwoo_IDataProvider object (i.e. Dwoo_Data) or an associative array. if you're rendering the template from cache, it can be left null
  • Dwoo_ICompiler $compiler: the compiler that must be used to compile the template, if left empty a default Dwoo_Compiler will be used.
  • bool $output: flag that defines whether the function returns the output of the template (false, default) or echoes it directly (true)
  • $_tpl
  • $_compiler
  • $_output
getCacheDir (line 677)

returns the cache directory with a trailing DIRECTORY_SEPARATOR

  • access: public
string getCacheDir ()
getCacheTime (line 723)

returns the default cache time that is used with templates that do not have a cache time set

  • return: the duration in seconds
  • access: public
int getCacheTime ()
getCharset (line 745)

returns the character set used by the string manipulation plugins

the charset is automatically lowercased

  • access: public
string getCharset ()
getCompileDir (line 700)

returns the compile directory with a trailing DIRECTORY_SEPARATOR

  • access: public
string getCompileDir ()
getCustomPlugins (line 667)

returns the custom plugins loaded

used by the Dwoo_ITemplate classes to pass the custom plugins to their Dwoo_ICompiler instance

  • access: public
array getCustomPlugins ()
getData (line 1513)

[runtime function] returns the entire data array

  • access: public
array getData ()
getDefaultCompilerFactory (line 791)

returns the default compiler factory function for the given resource name

  • return: the compiler factory callback
  • access: public
callback getDefaultCompilerFactory (string $resourceName)
  • string $resourceName: the resource name
getLoader (line 651)

returns the current loader object or a default one if none is currently found

  • access: public
void getLoader (Dwoo_ILoader 0)
getObjectPlugin (line 1079)

[runtime function] returns a Dwoo_Plugin of the given class

this is so a single instance of every class plugin is created at each template run, allowing class plugins to have "per-template-run" static variables

  • return: an object of the given class
  • access: protected
mixed getObjectPlugin (string $class)
  • string $class: the class name
getParentBlock (line 1038)

[runtime function] returns the parent block of the given block

  • return: or false if the given block isn't in the stack
  • access: public
Dwoo_Block_Plugin getParentBlock (Dwoo_Block_Plugin $block)
getPluginProxy (line 833)

returns the current plugin proxy object or null by default

  • access: public
void getPluginProxy (Dwoo_IPluginProxy|null 0)
getScope (line 1523)

[runtime function] returns a reference to the current scope

  • access: public
&mixed &getScope ()
getSecurityPolicy (line 813)

returns the current security policy object or null by default

  • return: the security policy object if any
  • access: public
Dwoo_Security_Policy|null getSecurityPolicy ()
getTemplate (line 767)

returns the current template being rendered, when applicable, or null

  • access: public
Dwoo_ITemplate|null getTemplate ()
initGlobals (line 468)

re-initializes the globals array before each template run

  • access: protected
void initGlobals (Dwoo_ITemplate $tpl)

Redefined in descendants as:
initRuntimeVars (line 485)

re-initializes the runtime variables before each template run

  • access: protected
void initRuntimeVars (Dwoo_ITemplate $tpl)
isArray (line 905)

[util function] checks if the input is an array or an iterator object, optionally it can also check if it's empty

  • return: true if it's an array (and not empty) or false if it's not an array (or if it's empty)
  • access: public
bool isArray (mixed $value, [bool $checkIsEmpty = false], [bool $allowNonCountable = false])
  • mixed $value: the variable to check
  • bool $checkIsEmpty: if true, the function will also check if the array is empty
  • bool $allowNonCountable: if true, the function will return true if an object is not empty but does not implement Countable, by default a non- countable object is considered empty, this setting is only used if $checkIsEmpty is true
isCached (line 847)

[util function] checks whether the given template is cached or not

  • access: public
bool isCached (Dwoo_ITemplate $tpl)
output (line 326)

outputs the template instead of returning it, this is basically a shortcut for get(*, *, *, true)

  • return: nothing or the template output if $output is true
  • see: Dwoo::get()
  • access: public
string output (mixed $tpl, [mixed $data = array()], [Dwoo_ICompiler $compiler = null])
  • mixed $tpl: template, can either be a Dwoo_ITemplate object (i.e. Dwoo_Template_File), a valid path to a template, or a template as a string it is recommended to provide a Dwoo_ITemplate as it will probably make things faster, especially if you render a template multiple times
  • mixed $data: the data to use, can either be a Dwoo_IDataProvider object (i.e. Dwoo_Data) or an associative array. if you're rendering the template from cache, it can be left null
  • Dwoo_ICompiler $compiler: the compiler that must be used to compile the template, if left empty a default Dwoo_Compiler will be used.
readParentVar (line 1246)

[runtime function] reads a variable into the parent scope

  • access: public
mixed readParentVar (int $parentLevels, [string $varstr = null])
  • int $parentLevels: the amount of parent levels to go from the current scope
  • string $varstr: the variable string, using dwoo variable syntax (i.e. "var.subvar[subsubvar]->property")
readVar (line 1276)

[runtime function] reads a variable into the current scope

  • access: public
mixed readVar (string $varstr)
  • string $varstr: the variable string, using dwoo variable syntax (i.e. "var.subvar[subsubvar]->property")
readVarInto (line 1207)

[runtime function] reads a variable into the given data array

  • access: public
mixed readVarInto (string $varstr, mixed $data)
  • string $varstr: the variable string, using dwoo variable syntax (i.e. "var.subvar[subsubvar]->property")
  • mixed $data: the data array or object to read from
removeFilter (line 577)

removes a filter

  • access: public
void removeFilter (mixed $callback)
  • mixed $callback: callback or filter name if it was autoloaded
removePlugin (line 535)

removes a custom plugin

  • access: public
void removePlugin (string $name)
  • string $name: the plugin name
removeResource (line 624)

removes a custom resource

  • access: public
void removeResource (string $name)
  • string $name: the resource name
setCacheDir (line 687)

sets the cache directory and automatically appends a DIRECTORY_SEPARATOR

  • access: public
void setCacheDir (string $dir)
  • string $dir: the cache directory
setCacheTime (line 733)

sets the default cache time to use with templates that do not have a cache time set

  • access: public
void setCacheTime (int $seconds)
  • int $seconds: the duration in seconds
setCharset (line 757)

sets the character set used by the string manipulation plugins

the charset will be automatically lowercased

  • access: public
void setCharset (string $charset)
  • string $charset: the character set
setCompileDir (line 710)

sets the compile directory and automatically appends a DIRECTORY_SEPARATOR

  • access: public
void setCompileDir (string $dir)
  • string $dir: the compile directory
setDefaultCompilerFactory (line 780)

sets the default compiler factory function for the given resource name

a compiler factory must return a Dwoo_ICompiler object pre-configured to fit your needs

  • access: public
void setDefaultCompilerFactory (string $resourceName, callback $compilerFactory)
  • string $resourceName: the resource name (i.e. file, string)
  • callback $compilerFactory: the compiler factory callback
setLoader (line 641)

sets the loader object to use to load plugins

  • access: public
void setLoader (Dwoo_ILoader $loader)
setPluginProxy (line 824)

sets the object that must be used as a plugin proxy when plugin can't be found by dwoo's loader

  • access: public
void setPluginProxy (Dwoo_IPluginProxy $pluginProxy)
setScope (line 1473)

[runtime function] sets the scope to the given scope string or array

  • return: the current scope tree
  • access: public
array setScope (mixed $scope, [bool $absolute = false])
  • mixed $scope: a string i.e. "level1.level2" or an array i.e. array("level1", "level2")
  • bool $absolute: if true, the scope is set from the top level scope and not from the current scope
setSecurityPolicy (line 803)

sets the security policy object to enforce some php security settings

use this if untrusted persons can modify templates

  • access: public
void setSecurityPolicy ([Dwoo_Security_Policy $policy = null])
templateFactory (line 885)

[util function] fetches a template object of the given resource

  • access: public
Dwoo_ITemplate templateFactory (string $resourceName, string $resourceId, [int $cacheTime = null], [string $cacheId = null], [string $compileId = null])
  • string $resourceName: the resource name (i.e. file, string)
  • string $resourceId: the resource identifier (i.e. file path)
  • int $cacheTime: the cache time setting for this resource
  • string $cacheId: the unique cache identifier
  • string $compileId: the unique compiler identifier
triggerError (line 938)

[util function] triggers a dwoo error

  • access: public
void triggerError (string $message, [int $level = E_USER_NOTICE])
  • string $message: the error message
  • int $level: the error level, one of the PHP's E_* constants
__clone (line 308)

resets some runtime variables to allow a cloned object to be used to render sub-templates

  • access: public
void __clone ()
Class Constants
BLOCK_PLUGIN = 8 (line 95)

constants that represents all plugin types

these are bitwise-operation-safe values to allow multiple types on a single plugin

CLASS_PLUGIN = 1 (line 92)

constants that represents all plugin types

these are bitwise-operation-safe values to allow multiple types on a single plugin

COMPILABLE_PLUGIN = 16 (line 96)

constants that represents all plugin types

these are bitwise-operation-safe values to allow multiple types on a single plugin

CUSTOM_PLUGIN = 32 (line 97)

constants that represents all plugin types

these are bitwise-operation-safe values to allow multiple types on a single plugin

FUNC_PLUGIN = 2 (line 93)

constants that represents all plugin types

these are bitwise-operation-safe values to allow multiple types on a single plugin

NATIVE_PLUGIN = 4 (line 94)

constants that represents all plugin types

these are bitwise-operation-safe values to allow multiple types on a single plugin

PROXY_PLUGIN = 512 (line 101)

constants that represents all plugin types

these are bitwise-operation-safe values to allow multiple types on a single plugin

RELEASE_TAG = 12 (line 82)

unique number of this dwoo release

this can be used by templates classes to check whether the compiled template has been compiled before this release or not, so that old templates are recompiled automatically when Dwoo is updated

SMARTY_BLOCK = 128 (line 99)

constants that represents all plugin types

these are bitwise-operation-safe values to allow multiple types on a single plugin

SMARTY_FUNCTION = 256 (line 100)

constants that represents all plugin types

these are bitwise-operation-safe values to allow multiple types on a single plugin

SMARTY_MODIFIER = 64 (line 98)

constants that represents all plugin types

these are bitwise-operation-safe values to allow multiple types on a single plugin

VERSION = "0.9.3" (line 73)

current version number

Documentation generated on Sun, 03 Aug 2008 15:12:30 +0200 by phpDocumentor 1.4.0