Class Dwoo

Description

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

 requirements :
  php 5.2.0 or above (might work below, it's a rough estimate)
  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.

Located in /Dwoo.php (line 31)


	
			
Direct descendents
Class Description
Dwoo_Smarty__Adapter a Smarty compatibility layer for Dwoo
Class Constant Summary
Variable Summary
Method Summary
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)
Dwoo __construct ([string $compileDir = null], [string $cacheDir = null])
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 ()
void initGlobals ()
bool isArray (mixed $value, [bool $checkIsEmpty = 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, [bool $safeRead = false])
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], [Dwoo_ITemplate $parentTemplate = null])
void triggerError (string $message, [int $level = E_USER_NOTICE])
mixed __call (string $method, array $args)
void __clone ()
Variables
string $buffer (line 240)

stores the output buffer during template runtime

  • access: protected
string $cacheDir (line 116)

directory where the cached templates are stored

defaults to DWOO_CACHEDIR (= dwoo_dir/cache by default)

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

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 79)

character set of the template, used by string manipulation plugins

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

string $compileDir (line 107)

directory where the compiled templates are stored

defaults to DWOO_COMPILEDIR (= dwoo_dir/compiled by default)

  • access: protected
Dwoo_Block_Plugin $curBlock (line 233)

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

  • access: protected
array $data (line 202)

stores the data during template runtime

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

stores the filter callbacks

array $globals (line 98)

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.

  • private:
  • access: public
Dwoo_ILoader $loader = null (line 181)

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

  • access: protected
Dwoo_IPluginProxy $pluginProxy (line 247)

stores plugin proxy

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

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 162)

stores the resource types and associated classes / compiler classes

  • access: protected
array $runtimePlugins (line 195)

stores the instances of the class plugins during template runtime

  • access: protected
mixed $scope (line 212)

stores the current scope during template runtime

this should ideally not be accessed directly from outside template code

  • private:
  • access: public
array $scopeTree (line 219)

stores the scope tree during template runtime

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

security policy object

  • access: protected
array $stack (line 226)

stores the block plugins stack during template runtime

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

currently rendered template, set to null when not-rendering

  • access: protected
Methods
addFilter (line 505)

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 465)

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 565)

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 929)

[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 1098)

[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 1396)

[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 1069)

[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 830)

[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 972)

[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 1028)

[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
Constructor __construct (line 255)

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:
get (line 306)

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

Redefined in descendants as:
getCacheDir (line 641)

returns the cache directory with a trailing DIRECTORY_SEPARATOR

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

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 717)

returns the character set used by the string manipulation plugins

the charset is automatically lowercased

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

returns the compile directory with a trailing DIRECTORY_SEPARATOR

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

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 1492)

[runtime function] returns the entire data array

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

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 615)

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

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

[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 1013)

[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 805)

returns the current plugin proxy object or null by default

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

[runtime function] returns a reference to the current scope

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

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 739)

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

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

re-initializes the globals array before each template run

this method is only callede once when the Dwoo object is created

  • access: protected
void initGlobals ()

Redefined in descendants as:
initRuntimeVars (line 442)

re-initializes the runtime variables before each template run

override this method to inject data in the globals array if needed, this method is called before each template execution

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

[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])
  • mixed $value: the variable to check
  • bool $checkIsEmpty: if true, the function will also check if the array is empty, and return true only if it's not empty
isCached (line 819)

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

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

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 1222)

[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 1252)

[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 1183)

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

  • access: public
mixed readVarInto (string $varstr, mixed $data, [bool $safeRead = false])
  • 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
  • bool $safeRead: if true, the function will check whether the index exists to prevent any notices from being output
removeFilter (line 541)

removes a filter

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

removes a custom plugin

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

removes a custom resource

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

sets the cache directory and automatically appends a DIRECTORY_SEPARATOR

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

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 729)

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 682)

sets the compile directory and automatically appends a DIRECTORY_SEPARATOR

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

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 605)

sets the loader object to use to load plugins

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

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 1452)

[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 775)

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 857)

[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], [Dwoo_ITemplate $parentTemplate = 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
  • Dwoo_ITemplate $parentTemplate
triggerError (line 910)

[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

Redefined in descendants as:
__call (line 1514)

Redirects all calls to unexisting to plugin proxy.

  • access: public
mixed __call (string $method, array $args)
  • string $method: Method name
  • array $args: List of arguments

Redefined in descendants as:
__clone (line 269)

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 60)

constants that represents all plugin types

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

CLASS_PLUGIN = 1 (line 57)

constants that represents all plugin types

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

COMPILABLE_PLUGIN = 16 (line 61)

constants that represents all plugin types

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

CUSTOM_PLUGIN = 32 (line 62)

constants that represents all plugin types

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

FUNC_PLUGIN = 2 (line 58)

constants that represents all plugin types

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

NATIVE_PLUGIN = 4 (line 59)

constants that represents all plugin types

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

PROXY_PLUGIN = 512 (line 66)

constants that represents all plugin types

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

RELEASE_TAG = 16 (line 47)

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 64)

constants that represents all plugin types

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

SMARTY_FUNCTION = 256 (line 65)

constants that represents all plugin types

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

SMARTY_MODIFIER = 64 (line 63)

constants that represents all plugin types

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

TEMPLATE_PLUGIN = 1024 (line 67)

constants that represents all plugin types

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

VERSION = '1.1.0' (line 38)

current version number

Documentation generated on Sat, 18 Jul 2009 21:04:54 +0200 by phpDocumentor 1.4.0