# 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
  $Revision: 557 $

## \Capsule
jump to top

Package: phing\lib

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
  $Revision: 557 $

### Properties

`$initialized= 'false'`

Has template been initialized.

Default value `false` Details

Type

`string $old_include_path= ''`

Stores the pre-parse() include_path.

Details

Type
  string

`string $outputDirectory= ''`

Where should output files be written? (This is named inconsistently to be compatible w/ Texen.)

Details

Type
  string

`string $templatePath= ''`

Look for templates here (if relative path provided).

Details

Type
  string

`array $vars= 'array()'`

The variables that can be used by the templates.

Hash of variables.
Default value `array()`Details

Type
  array

### Methods

`__construct( ) : void`

`clear( mixed $which = null ) : void`

Clears one or several or all variables.

Parameters

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.

Parameters

Name | Type | Description
--- | --- | ---
$__template | string |

Throws

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().

Parameters

Name | Type | Description
--- | --- | ---
$name | string | Variable name to retrieve.

Returns

Type | Description
--- | ---
mixed |

`getOutputDirectory( ) : string`

Get basepath to use for output file creation.

Returns

Type | Description
--- | ---
string |

`getTemplatePath( ) : string`

Get the basepath to use for template lookups.

Returns

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.

Parameters

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?

Returns

Type | Description
--- | ---
string | The "parsed" template output.

Throws

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.

Parameters

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.

Parameters

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.

Parameters

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.

Parameters

Name | Type | Description
--- | --- | ---
$name |  |
$value |  | &$value

`resolvePath( string $file, string $basepath ) : string`

This returns a "best guess" path for the given file.

Parameters

Name | Type | Description
--- | --- | ---
$file | string | File name or possibly absolute path.
$basepath | string | The basepath that should be prepended if $file is not absolute.

Returns

Type | Description
--- | ---
string | "Best guess" path for this file.

`setOutputDirectory( string $v ) : void`

Set a basepath to use for output file creation.

Parameters

Name | Type | Description
--- | --- | ---
$v | string |

`setTemplatePath( string $v ) : void`

Set the basepath to use for template lookups.

Parameters

Name | Type | Description
--- | --- | ---
$v | string |

Documentation was generated by DocBlox 0.15.1.