lib/Capsule.php

Show: inherited
Table of Contents

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

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
$Id$  

Properties

Propertyprotected  $initialized= 'false'

Has template been initialized.

Default valuefalseDetails
Type
n/a
Propertyprivatestring  $old_include_path= ''

Stores the pre-parse() include_path.

Details
Type
string
Propertyprotectedstring  $outputDirectory= ''

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

Details
Type
string
Propertyprotectedstring  $templatePath= ''

Look for templates here (if relative path provided).

Details
Type
string
Propertypublicarray  $vars= 'array()'

The variables that can be used by the templates.

Hash of variables.
Default valuearray()Details
Type
array

Methods

methodpublic__construct( ) : void

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

methodpublicdisplay( 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
methodpublicget( 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
methodpublicgetOutputDirectory( ) : string

Get basepath to use for output file creation.

Returns
Type Description
string
methodpublicgetTemplatePath( ) : string

Get the basepath to use for template lookups.

Returns
Type Description
string
methodpublicparse( 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.
methodpublicput( 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
methodpublicputAll( 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?

methodpublicputCopy( 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
methodpublicputRef(  $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

methodprotectedresolvePath( 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.
methodpublicsetOutputDirectory( string $v ) : void

Set a basepath to use for output file creation.

Parameters
Name Type Description
$v string
methodpublicsetTemplatePath( string $v ) : void

Set the basepath to use for template lookups.

Parameters
Name Type Description
$v string
Documentation was generated by DocBlox 0.18.1.