tasks/ext/SmartyTask.php

Show: inherited
Table of Contents

A phing task for generating output by using Smarty.

This is based on the TexenTask from Apache's Velocity engine. This class was originally proted in order to provide a template compiling system for Torque.

TODO: - Add Path / useClasspath support?

Author
Hans Lellelid (SmartyTask)  
Author
Jason van Zyl (TexenTask)  
Author
Robert Burrell Donkin  
Package
phing.tasks.ext  
Version
$Id: 1fe8b2aa2668db628554e59b3099520c0e1c03e4 $  

\SmartyTask

Package: phing\tasks\ext

A phing task for generating output by using Smarty.

This is based on the TexenTask from Apache's Velocity engine. This class was originally proted in order to provide a template compiling system for Torque.

TODO: - Add Path / useClasspath support?

Parent(s)
\Task < \ProjectComponent
Author
Hans Lellelid (SmartyTask)  
Author
Jason van Zyl (TexenTask)  
Author
Robert Burrell Donkin  
Copyright
2001,2002 THYRELL. All rights reserved  
Version
$Id: 1fe8b2aa2668db628554e59b3099520c0e1c03e4 $  

Properties

Propertyprotectedstring  $compilePath= ''

Smarty compiles templates before parsing / replacing tokens in them.

By default it will try ./templates_c, but you may wish to override this.

Details
Type
string
Propertyprotectedstring  $configPath= ''

Smarty can use config files.

This tells Smarty where to look for the config files.

Details
Type
string
Propertyprotected\Smarty  $context= ''

Smarty template engine.

Details
Type
\Smarty
Propertyprotectedarray  $contextProperties= ''

<p> These are properties that are fed into the initial context from a properties file. This is simply a convenient way to set some values that you wish to make available in the context.

These values are not critical, like the template path or output path, but allow a convenient way to set a value that may be specific to a particular generation task.

<

p> For example, if you are generating scripts to allow user to automatically create a database, then you might want the

$databaseName

to be placed in the initial context so that it is available in a script that might look something like the following:

#!bin/sh

echo y | mysqladmin create $databaseName

The value of

$databaseName

isn't critical to output, and you obviously don't want to change the ant task to simply take a database name. So initial context values can be set with properties file.

Details
Type
array
Propertyprotectedstring  $controlTemplate= ''

This is the control template that governs the output.

It may or may not invoke the services of worker templates.

Details
Type
string
Propertyprotectedstring  $description= ''
inherited

Description of the task

Inherited from: \Task::$$description
Details
Type
string
Inherited_from
\Task::$$description  
Propertyprotectedboolean  $forceCompile= 'false'

Whether to force Smarty to recompile templates.

Smarty does check file modification time, but you can set this to be sure that the template will be compiled (of course it will be slower if you do).

Default valuefalseDetails
Type
boolean
Propertyprotectedstring  $leftDelimiter= ''

Customize the left delimiter for Smarty tags.

Details
Type
string
Propertyprotected\Location  $location= ''
inherited

Stored buildfile location

Inherited from: \Task::$$location
Details
Type
\Location
Inherited_from
\Task::$$location  
Propertyprotectedstring  $outputDirectory= ''

This is where texen will place all the output that is a product of the generation process.

Details
Type
string
Propertyprotectedstring  $outputFile= ''

This is the file where the generated text will be placed.

Details
Type
string
Propertyprotected\Project  $project= 'null'
inherited

Holds a reference to the project that a project component (a task, a target, etc.) belongs to

A reference to the current project instanceInherited from: \ProjectComponent::$$project\Task::$$project
Default valuenullDetails
Type
\Project
Inherited_from
\ProjectComponent::$$project  
Inherited_from
\Task::$$project  
Propertyprotectedarray  $properties= 'array()'

Variables that are assigned to the context on parse/compile.

Default valuearray()Details
Type
array
Propertyprotectedstring  $rightDelimiter= ''

Customize the right delimiter for Smarty tags.

Details
Type
string
Propertyprotected\Target  $target= ''
inherited

Owning Target object

Inherited from: \Task::$$target
Details
Type
\Target
Inherited_from
\Task::$$target  
Propertyprotectedstring  $taskName= ''
inherited

Taskname for logger

Inherited from: \Task::$$taskName
Details
Type
string
Inherited_from
\Task::$$taskName  
Propertyprotectedstring  $taskType= ''
inherited

Internal taskname (req)

Inherited from: \Task::$$taskType
Details
Type
string
Inherited_from
\Task::$$taskType  
Propertyprotectedstring  $templatePath= ''

This is where Velocity will look for templates using the file template loader.

Details
Type
string
Propertyprotected\RuntimeConfigurable  $wrapper= ''
inherited

Wrapper of the task

Inherited from: \Task::$$wrapper
Details
Type
\RuntimeConfigurable
Inherited_from
\Task::$$wrapper  

Methods

methodprotectedcleanup( ) : void

A hook method called at the end of {@link #execute()} which can be overridden to perform any necessary cleanup activities (such as the release of database connections, etc.). By default, does nothing.

Throws
Exception Description
\Exception Problem cleaning up.
methodpublicgetCompilePath( ) : string

Get the path Smarty uses for compiling templates.

Returns
Type Description
string
methodpublicgetConfigPath( ) : string

Get the path that Smarty uses for looking for config files.

Returns
Type Description
string
methodpublicgetContextProperties( ) : \Properties

Get the context properties that will be fed into the initial context be the generating process starts.

Returns
Type Description
\Properties
methodpublicgetControlTemplate( ) : string

Get the control template for the generating process.

Returns
Type Description
string
methodpublicgetDescription( ) : string
inherited

Returns the textual description of the task

Inherited from: \Task::getDescription()
Returns
Type Description
string The text description of the task
methodpublicgetForceCompile( ) : boolean

Get whether Smarty should always recompile template.

Returns
Type Description
boolean
methodpublicgetLeftDelimiter( ) : string

Get Smarty template right delimiter

Returns
Type Description
string
methodpublicgetLocation( ) : \Location
inherited

Returns the location within the buildfile this task occurs. Used by {@link BuildException} to give detailed error messages.

Inherited from: \Task::getLocation()
Returns
Type Description
\Location The location object describing the position of this task within the buildfile.
methodpublicgetOutputDirectory( ) : string

Get the output directory.

Returns
Type Description
string
methodpublicgetOutputFile( ) : string

Get the output file for the generation process.

Returns
Type Description
string
methodpublicgetOwningTarget( ) : \Target
inherited

Returns the owning target of this task.

Inherited from: \Task::getOwningTarget()
Returns
Type Description
\Target The target object that owns this task
methodpublicgetProject( ) : \Project
inherited

Returns a reference to current project

Inherited from: \ProjectComponent::getProject()\Task::getProject()
Returns
Type Description
\Project Reference to current porject object
methodprotectedgetRegisterSlot( string $slotName ) : void
inherited

Returns a name

Inherited from: \Task::getRegisterSlot()
Parameters
Name Type Description
$slotName string
methodpublicgetRightDelimiter( ) : string

Get Smarty template right delimiter

Returns
Type Description
string
methodpublicgetRuntimeConfigurableWrapper( ) : \RuntimeConfigurable
inherited

Returns the wrapper object for runtime configuration

Inherited from: \Task::getRuntimeConfigurableWrapper()
Returns
Type Description
\RuntimeConfigurable The wrapper object used by this task
methodpublicgetTaskName( ) : string
inherited

Returns the name of task, used only for log messages

Inherited from: \Task::getTaskName()
Returns
Type Description
string Name of this task
methodpublicgetTaskType( ) : string
inherited

Returns the name of the task under which it was invoked, usually the XML tagname

Inherited from: \Task::getTaskType()
Returns
Type Description
string The type of this task (XML Tag)
methodpublicgetTemplatePath( ) : string

Get the path where Velocity will look for templates using the file template loader.

Returns
Type Description
string
methodpublicinit( ) : void

Called by the parser to let the task initialize properly.

Should throw a BuildException if something goes wrong with the build

This is abstract here, but may not be overloaded by subclasses.

Throws
Exception Description
\BuildException
methodpublicinitControlContext( ) : \Smarty

Creates a Smarty object.

Returns
Type Description
\Smarty initialized (cleared) Smarty context.
Throws
Exception Description
\Exception the execute method will catch and rethrow as a BuildException
methodpubliclog( string $msg, integer $level = Project::MSG_INFO ) : void
inherited

Provides a project level log event to the task.

Inherited from: \Task::log()
Parameters
Name Type Description
$msg string

The message to log

$level integer

The priority of the message

Details
See
\BuildEvent  
See
\BuildListener  
methodpublicmain( ) : void

Execute the input script with Velocity

Should throw a BuildException if someting goes wrong with the build

This is abstract here. Must be overloaded by real tasks.

Throws
Exception Description
\BuildException BuildExceptions are thrown when required attributes are missing. Exceptions thrown by Velocity are rethrown as BuildExceptions.
methodpublicmaybeConfigure( ) : void
inherited

Configure this task if it hasn't been done already.

Inherited from: \Task::maybeConfigure()
methodpublicperform( ) : void
inherited

Perfrom this task

Inherited from: \Task::perform()
methodprotectedpopulateInitialContext( \context $context ) : void

Place useful objects into the initial context.

TexenTask places

Date().toString()
into the context as
$now
. Subclasses who want to vary the objects in the context should override this method.

$generator
is not put into the context in this method.

Parameters
Name Type Description
$context \context

The context to populate, as retrieved from {@link #initControlContext()}.

Throws
Exception Description
\Exception Error while populating context. The {@link #execute()} method will catch and rethrow as a BuildException.
methodpublicsetCompilePath( string $compilePath ) : void

Set the path Smarty uses as a "cache" for compiled templates.

Parameters
Name Type Description
$compilePath string
methodpublicsetConfigPath( string $configPath ) : void

Set where Smarty looks for config files.

Parameters
Name Type Description
$configPath string
methodpublicsetContextProperties( string $file ) : void

Set the context properties that will be fed into the initial context be the generating process starts.

Parameters
Name Type Description
$file string
methodpublicsetControlTemplate( string $controlTemplate ) : void

[REQUIRED] Set the control template for the generating process.

Parameters
Name Type Description
$controlTemplate string
methodpublicsetDescription( string $desc ) : void
inherited

Sets a textual description of the task

Inherited from: \Task::setDescription()
Parameters
Name Type Description
$desc string

The text describing the task

methodpublicsetForceCompile( boolean $force ) : void

Set whether Smarty should always recompile tempaltes.

Parameters
Name Type Description
$force boolean
methodpublicsetLeftDelimiter( string $delim ) : void

Set Smarty template left delimiter.

Parameters
Name Type Description
$delim string
methodpublicsetLocation( \Location $location ) : void
inherited

Sets the location within the buildfile this task occurs. Called by the parser to set location information.

Inherited from: \Task::setLocation()
Parameters
Name Type Description
$location \Location

The location object describing the position of this task within the buildfile.

methodpublicsetOutputDirectory( \PhingFile $outputDirectory ) : void

[REQUIRED] Set the output directory. It will be created if it doesn't exist.

Parameters
Name Type Description
$outputDirectory \PhingFile
Throws
Exception Description
\Exception
methodpublicsetOutputFile(  $outputFile ) : void

[REQUIRED] Set the output file for the generation process.

Parameters
Name Type Description
$outputFile
methodpublicsetOwningTarget( \Target $target ) : void
inherited

Sets the owning target this task belongs to.

Inherited from: \Task::setOwningTarget()
Parameters
Name Type Description
$target \Target

Reference to owning target

methodpublicsetProject( \Project $project ) : void
inherited

References the project to the current component.

Inherited from: \ProjectComponent::setProject()\Task::setProject()
Parameters
Name Type Description
$project \Project

The reference to the current project

methodpublicsetRightDelimiter( string $delim ) : void

Set Smarty template right delimiter.

Parameters
Name Type Description
$delim string
methodpublicsetRuntimeConfigurableWrapper( \RuntimeConfigurable $wrapper ) : void
inherited

Sets the wrapper object this task should use for runtime configurable elements.

Inherited from: \Task::setRuntimeConfigurableWrapper()
Parameters
Name Type Description
$wrapper \RuntimeConfigurable

The wrapper object this task should use

methodpublicsetTaskName( string $name ) : string
inherited

Sets the name of this task for log messages

Inherited from: \Task::setTaskName()
Parameters
Name Type Description
$name string
Returns
Type Description
string A string representing the name of this task for log
methodpublicsetTaskType( string $name ) : void
inherited

Sets the type of the task. Usually this is the name of the XML tag

Inherited from: \Task::setTaskType()
Parameters
Name Type Description
$name string

The type of this task (XML Tag)

methodpublicsetTemplatePath(  $templatePath ) : void

[REQUIRED] Set the path where Velocity will look for templates using the file template loader.

Parameters
Name Type Description
$templatePath
Throws
Exception Description
\Exception
Documentation was generated by DocBlox 0.18.1.