Sitellite Application Framework
Class Tree         Index         All Elements

Class: TemplateTransformation

Source Location: Program_Root/Template/Transformation.php

Class Overview


TemplateTransformation is the class that Template uses internally


Author(s)

Version

  • 1.2, 2002-03-24, $Id: Transformation.php,v 1.2 2005/07/06 15:30:56 lux Exp $

Copyright

  • Copyright (C) 2001-2003, Simian Systems Inc.

Variables

Methods


Inherited Variables

Inherited Methods


Class Details

[line 91]
TemplateTransformation is the class that Template uses internally

to handle the manipulation of values before they are substituted into a template. It is often valuable to be able to call a function or a regular expression on a value before it is shown. For instance, when you are retrieving a date value straight from your database to the template (using the [SQL: ...] directive), it is nice to be able to format it how you like, instead of how the database decides it should look.

The format of a transformation is as follows:

Tag name:Transformation type:Transformation rule

The tag name corresponds to the latter part of the name if the name is of the form ##object:property##.

There are currently three types of transformations:

  • func : a function call
  • regex: a regular expression search and replace
  • alternate : alternates the value of the variable between the two provided (good for alternating background colours of table rows)
New 1.2:
  • Added an optional list of variables to import from the global namespace.

1 <?php
2
3 A few basic transformations:
4
5 [Transformations:
6 bgcolor:alternate:#ffffff:#eeeeee
7 icon:regex:(.+):<img src="sitellite/\1" />
8 file_extension:func:strtoupper ("##file_extension##")
9 date:func:Date::format ("##date##", "F j, Y")
10 ]
11
12 Class usage:
13
14 $transformation = new TemplateTransformation ('func', 'date', 'Date::format ("##date##", "F j, Y")');
15
16 echo $transformation->transform ('2001-12-24');
17
18 // can also be used like this:
19
20 // note: data is the contents of a [Transformations: ...] directive
21 $transformations =& TemplateTransformation::parse ($data);
22
23 foreach ($transformations as $key => $object) {
24 // do things with $key and $object here
25 }
26
27 ?>




Tags:

access:  public
version:  1.2, 2002-03-24, $Id: Transformation.php,v 1.2 2005/07/06 15:30:56 lux Exp $
license:  http://www.sitellite.org/index/license
copyright:  Copyright (C) 2001-2003, Simian Systems Inc.
author:  John Luxford <mailto:lux@simian.ca>


[ Top ]


Class Variables

$key =

[line 106]

The name of the element to which the transformation belongs.



Tags:

access:  public

Type:   mixed


[ Top ]

$rule =

[line 114]

The actual transformation rule. See the examples above for format information.



Tags:

access:  public

Type:   mixed


[ Top ]

$type =

[line 98]

The type of transformation. Can be 'regex', 'func', or 'alternate'.



Tags:

access:  public

Type:   mixed


[ Top ]



Class Methods


constructor TemplateTransformation [line 125]

TemplateTransformation TemplateTransformation( string $type, string $key, string $rule)

Constructor method.



Tags:

access:  public


Parameters:

string   $type  
string   $key  
string   $rule  

[ Top ]

method parse [line 187]

associative &parse( [string $data = ''])

Parses a block of transformations into an associative array of TemplateTransformation objects (usually taken from a [Transformations: ...] directive).



Tags:

return:  array
access:  public


Parameters:

string   $data  

[ Top ]

method transform [line 139]

string transform( string $value, [mixed $import = ''])

Performs the transformation on a given value.



Tags:

access:  public


Parameters:

string   $value  

[ Top ]


Copyright © 2007, SIMIAN systems Inc.
All rights reserved. Privacy policy
Documentation generated on Tue, 13 Feb 2007 17:20:02 -0600 by Sitellite AppDoc and phpDocumentor 1.2.2