lib/Capsule.php
Capsule is a simple "template" engine that essentially provides an isolated context for PHP scripts.
There is no special templating language, and therefore no limitations to what can be accomplished within templates. The main purpose of Capsule is to separate the business logic from display / output logic.
- Author
- Hans Lellelid
- Package
- phing.lib
- Version
- $Id$
\Capsule
Capsule is a simple "template" engine that essentially provides an isolated context for PHP scripts.
There is no special templating language, and therefore no limitations to what can be accomplished within templates. The main purpose of Capsule is to separate the business logic from display / output logic.
- Author
- Hans Lellelid
- Version
- $Id$
Properties


string
$outputDirectory= ''
Where should output files be written? (This is named inconsistently to be compatible w/ Texen.)
- Type
- string
Methods


clear(
mixed $which
=
null
)
:
void
Clears one or several or all variables.
Name | Type | Description |
---|---|---|
$which | mixed | String name of var, or array of names. |


display(
string $__template
)
:
void
Low overhead (no output buffering) method to simply dump template to buffer.
Name | Type | Description |
---|---|---|
$__template | string |
Exception | Description |
---|---|
\Exception | - if template cannot be found |


get(
string $name
)
:
mixed
Gets value of specified var or NULL if var has not been put().
Name | Type | Description |
---|---|---|
$name | string | Variable name to retrieve. |
Type | Description |
---|---|
mixed |


getOutputDirectory(
)
:
string
Get basepath to use for output file creation.
Type | Description |
---|---|
string |


getTemplatePath(
)
:
string
Get the basepath to use for template lookups.
Type | Description |
---|---|
string |


parse(
string $template, string $outputFile
=
null, boolean $append
=
false
)
:
string
Fetches the results of a tempalte parse and either returns the string or writes results to a specified output file.
Name | Type | Description |
---|---|---|
$template | string | The template filename (relative to templatePath or absolute). |
$outputFile | string | If specified, contents of template will also be written to this file. |
$append | boolean | Should output be appended to source file? |
Type | Description |
---|---|
string | The "parsed" template output. |
Exception | Description |
---|---|
\Exception | - if template not found. |


put(
string $name, mixed $value
)
:
void
Adds a variable to the context.
Resulting template will have access to ${$name$} variable.
Name | Type | Description |
---|---|---|
$name | string | |
$value | mixed |


putAll(
array $vars, boolean $recursiveMerge
=
false
)
:
void
Merges in passed hash to vars array.
Given an array like:
array( 'myvar' => 'Hello',
'myvar2' => 'Hello')
Resulting template will have access to $myvar and $myvar2.
Name | Type | Description |
---|---|---|
$vars | array | |
$recursiveMerge | boolean | Should matching keys be recursively merged? |


putCopy(
string $name, mixed $value
)
:
void
Makes a copy of the value and puts it into the context.
This is primarily to force copying (cloning) of objects, rather than the default behavior which is to assign them by reference.
Name | Type | Description |
---|---|---|
$name | string | |
$value | mixed |


putRef(
$name, $value
)
:
void
Put a variable into the context, assigning it by reference.
This means that if the template modifies the variable, then it will also be modified in the context.
Name | Type | Description |
---|---|---|
$name | ||
$value | &$value |


resolvePath(
string $file, string $basepath
)
:
string
This returns a "best guess" path for the given file.
Name | Type | Description |
---|---|---|
$file | string | File name or possibly absolute path. |
$basepath | string | The basepath that should be prepended if $file is not absolute. |
Type | Description |
---|---|
string | "Best guess" path for this file. |


setOutputDirectory(
string $v
)
:
void
Set a basepath to use for output file creation.
Name | Type | Description |
---|---|---|
$v | string |