classes/phing/filters/ReplaceTokensWithFile.php

\ReplaceTokensWithFile

Replaces tokens in the original input with the contents of a file.

The file to be used is controlled by the name of the token which corresponds to the basename of the file to be used together with the optional pre and postfix strings that is possible to set.

By default all HTML entities in the file is replaced by the corresponding HTML entities. This behaviour can be controlled by the "translatehtml" parameter.

Supported parameters are:

 prefix         string Text to be prefixed to token before using as filename
 postfix        string Text to be prefixed to token before using as filename
 dir            string The directory where the files should be read from
 translatehtml  bool   If we should translate all HTML entities in the file.

Example:


  
  
Extends from
\BaseParamFilterReader
Implements
\ChainableReader
see
\ReplaceTokensWithFile
access
public
author
johan persson, johanp@aditus.nu
copyright
© 2003 seasonfive. All rights reserved
package
phing.filters
version
$Id: ReplaceTokensWithFile.php 1084 2011-05-06 09:55:25Z mrook $

Constants

Constantstring  DEFAULT_BEGIN_TOKEN = '#@#'

Default "begin token" character.

string
Constantstring  DEFAULT_END_TOKEN = '#@#'

Default "end token" character.

string

Properties

Propertyprivatestring  $_beginToken= 'ReplaceTokensWithFile'

Character marking the beginning of a token.

Default valueReplaceTokensWithFileDetails
Type
string
Propertyprivatestring  $_dir= './'

Directory where to look for the files. The default is to look in the current file.

Default value./Details
Type
string
Propertyprivatestring  $_endToken= 'ReplaceTokensWithFile'

Character marking the end of a token.

Default valueReplaceTokensWithFileDetails
Type
string
Propertyprivatestring  $_postfix= ''

File postfix to be inserted in front of the token to create the file name to be used.

Details
Type
string
Propertyprivatestring  $_prefix= ''

File prefix to be inserted in front of the token to create the file name to be used.

Details
Type
string
Propertyprivatearray  $_tokensources= 'array'

Array to hold the token sources that make tokens from different sources available

Default valuearrayDetails
Type
array
Propertyprivateboolean  $_translatehtml= 'true'

Translate all HTML entities in the file to the corresponding HTML entities before it is used as replacements. For example all '<' will be translated to &lt; before the content is inserted.

Default valuetrueDetails
Type
boolean

Methods

methodprivate  _initialize( ) :
Initializes parameters This method is only called when this filter is used through a tag in build file.
methodpublic  chain( object $reader ) : object
Creates a new ReplaceTokensWithFile using the passed in Reader for instantiation.
Parameters
Name Type Description
$reader object

A Reader object providing the underlying stream. Must not be null.

Returns
Type Description
object
methodpublic  getBeginToken( ) : string
Returns the "begin token" character.
Returns
Type Description
string
methodpublic  getDir( ) :
Returns the drectory where to look for the files to use for token replacement
methodpublic  getEndToken( ) : \the
Returns the "end token" character.
Returns
Type Description
\the
methodpublic  getPostfix( ) :
Returns the postfix that is added to the token in order to create the file name. For example if the token is 01 and the postfix is ".php" then the filename to look for will be "01.php"
methodpublic  getPrefix( ) :
methodpublic  getTranslateHTML( ) :
Returns the drectory where to look for the files to use for token replacement
methodpublic  read(  $len = null ) : mixed
Returns stream with tokens having been replaced with appropriate values.

If a replacement value is not found for a token, the token is left in the stream.

Parameters
Name Type Description
$len
Returns
Type Description
mixed
methodprivate  replaceTokenCallback( array $matches ) : string
Replace the token found with the appropriate file contents
Parameters
Name Type Description
$matches array Array of 1 el containing key to search for.
Returns
Type Description
string
Details
access
private
methodpublic  setBeginToken( string $beginToken ) :
Sets the "begin token" character.
Parameters
Name Type Description
$beginToken string the character used to denote the beginning of a token.
methodpublic  setDir( string $dir ) :
Sets the drectory where to look for the files to use for token replacement
Parameters
Name Type Description
$dir string
methodpublic  setEndToken( string $endToken ) :
Sets the "end token" character.
Parameters
Name Type Description
$endToken string the character used to denote the end of a token
methodpublic  setPostfix( string $postfix ) :
Sets the postfix that is added to the token in order to create the file name. For example if the token is 01 and the postfix is ".php" then the filename to look for will be "01.php"
Parameters
Name Type Description
$postfix string
methodpublic  setPrefix( string $prefix ) :
Sets the prefix that is prepended to the token in order to create the file name. For example if the token is 01 and the prefix is "example" then the filename to look for will be "example01"
Parameters
Name Type Description
$prefix string
methodpublic  setTranslateHTML(  $translate ) :
Sets the drectory where to look for the files to use for token replacement
Parameters
Name Type Description
$translate
Documentation was generated by DocBlox 0.13.1.