# classes/phing/filters/ReplaceTokensWithFile.php

## \ReplaceTokensWithFile
jump to top

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

`string DEFAULT_BEGIN_TOKEN = '#@#'`

Default "begin token" character.

  string

`string DEFAULT_END_TOKEN = '#@#'`

Default "end token" character.

  string

### Properties

`string $_beginToken= 'ReplaceTokensWithFile'`

Character marking the beginning of a token.

Default value `ReplaceTokensWithFile` Details

Type
  string

`string $_dir= './'`

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

Default value`./`Details

Type
  string

`string $_endToken= 'ReplaceTokensWithFile'`

Character marking the end of a token.

Default value `ReplaceTokensWithFile` Details

Type
  string

`string $_postfix= ''`

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

Details

Type
  string

`string $_prefix= ''`

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

Details

Type
  string

`array $_tokensources= 'array'`

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

Default value `array` Details

Type
  array

`boolean $_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 value `true` Details

Type
  boolean

### Methods

`_initialize( ) :`
Initializes parameters This method is only called when this filter is used through a <filterreader> tag in build file.
`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 |

`getBeginToken( ) : string`
Returns the "begin token" character.
Returns

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

`getDir( ) :`
Returns the drectory where to look for the files to use for token replacement
`getEndToken( ) : \the`
Returns the "end token" character.
Returns

Type | Description
--- | ---
\the |

`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"
`getPrefix( ) :`
`getTranslateHTML( ) :`
Returns the drectory where to look for the files to use for token replacement
`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 |

`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

`setBeginToken( string $beginToken ) :`
Sets the "begin token" character.
Parameters

Name | Type | Description
--- | --- | ---
$beginToken | string | the character used to denote the beginning of a token.

`setDir( string $dir ) :`
Sets the drectory where to look for the files to use for token replacement
Parameters

Name | Type | Description
--- | --- | ---
$dir | string |

`setEndToken( string $endToken ) :`
Sets the "end token" character.
Parameters

Name | Type | Description
--- | --- | ---
$endToken | string | the character used to denote the end of a token

`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 |

`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 |

`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.