Class Crafty

Description

Crafty main class implementation

This is the main class of the Crafty template engine. You should always instantiate this and make use of it's member functions. See also the Crafty Usage and Syntax manual for further information.

Located in /crafty/Crafty.class.php (line 80)


	
			
Variable Summary
Method Summary
Crafty __construct ([string $path_crafty = ''])
void append (string $name, mixed $data, [string $index = ''], [string $index_sub = ''])
void appendRef (string $name, mixed &$data, [string $index = ''], [string $index_sub = ''])
void assign (string $name, mixed $data, [boolean $extract = FALSE])
void assignRef (string $name, reference &$data)
boolean display (string $template_name, [integer $compile_mode = CRAFTY_COMPILE_AUTO])
void error_handler (mixed $errno, mixed $errstr, mixed $errfile, mixed $errline, mixed $errcontext)
void securityCheck (string $param)
Variables
Crafty_Compiler $compiler (line 123)

Object handle of a Compiler object

If compiling is neccessary (display modes CRAFTY_COMPILE_AUTO and CRAFTY_COMPILE_ALWAYS), this will contain an object handle of a Crafty_Compiler object. It is only for internal use.

  • access: public
string $path_crafty (line 102)

Path to Crafty directory

Stores the absolute path to the Crafty directory. It is set by the constructor, so you will have to pass it at least once.

  • access: public
string $path_templates_c (line 112)

Root path to the compiled templates

Stores the absolute path to the compiled template files. This is automatically set by the constructor, you will not have to take care of it.

  • access: public
array $_output_data = array() (line 92)

Stores assigned values

This array is used to store the values assigned to this template by assign(), assignRef(), append() or appendRef().

  • access: private
Methods
Constructor __construct (line 138)

Initializes a Crafty instance

The constructor intializes a Crafty instance and sets up the neccessary internal path variables. It also includes the Exception classes. You have to pass the absolute or relative path to the constructor so Crafty can find it's files.

From version 1.0.1 the parameter is optional and will be acquired using the __FILE__ magic constant by default.

  • access: public
Crafty __construct ([string $path_crafty = ''])
  • string $path_crafty: [optional] Path to the crafty directory
append (line 214)

Append a content to an data array

Appends content $data to the assigned data array $name. $data will allways be appended at the end.
If the array is not yet assigned, a new one will be created, if only a value is set this value will be used as first element of the array and $data as the second one.
If $index is set it will not just append to the main array but append with a $index as key for the main array. However this will not influence the order of the displayed blocks.
If $index_sub is set it will create and append the following array:
array($index_sub => $data) then the value of $index can be used as variablename inside a blocklist, instead of $value. This is useful for cascaded blocklists.

  • access: public
void append (string $name, mixed $data, [string $index = ''], [string $index_sub = ''])
  • string $name: Variable path and name
  • mixed $data: Variable content
  • string $index: [optional, default=''] Index for main array
  • string $index_sub: [optional, default=''] Index for subarray
appendRef (line 253)

Append a reference to an data array

Same as append(), but uses an reference instead of "real" values.

  • access: public
void appendRef (string $name, mixed &$data, [string $index = ''], [string $index_sub = ''])
  • string $name: Variable path and name
  • mixed $data: Variable content
  • string $index: [optional, default=''] Index for main array
  • string $index_sub: [optional, default=''] Index for subarray
assign (line 166)

Assign a variable content

This assigns a variable content to a template before its beeing displayed by display(). If $extract is true and data is an associative array, every key will be taken as sub-variable and the corresponding value as sub-variable content. The array itself will still be assigned. $extract also works recursive

  • access: public
void assign (string $name, mixed $data, [boolean $extract = FALSE])
  • string $name: Variable path and name
  • mixed $data: Variable content
  • boolean $extract: [optional, default=false] Whether or not to extract an array as multiple variables.
assignRef (line 186)

Assign variable content as reference

This assigns a variable content as reference. So you can first assign the variable and then manipulate it's content. There's no extraction for references like in assign().

  • access: public
void assignRef (string $name, reference &$data)
  • string $name: Variable path and name
  • reference $data: Variable reference
display (line 295)

Display template

Displays template $template_name in compilation mode $compile_mode. Call this from your file after all values are assigned.

  • return: State of success
  • access: public
boolean display (string $template_name, [integer $compile_mode = CRAFTY_COMPILE_AUTO])
error_handler (line 333)

Error handler method for compiled templates

See http://www.php.net/set_error_handler for the parameters.

  • access: public
void error_handler (mixed $errno, mixed $errstr, mixed $errfile, mixed $errline, mixed $errcontext)
securityCheck (line 361)

Checks security integrity of a string

This checks whether or not it is secure to print the string $param in a template. If not, an exception will be thrown, and Crafty will refuse further work.

  • access: public
void securityCheck (string $param)
  • string $param: String to check

Documentation generated on Sat, 19 Feb 2005 01:43:38 +0100 by phpDocumentor 1.3.0RC3