# ReplaceTokensWithFile

Extends \BaseParamFilterReader Implements \ChainableReader

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:

author | johan persson, johanp@aditus.nu
version | $Id: 2ce2fe6389844147fcaa7f85308157891a38e7af $
see |
package | phing.filters

### Methods

## __construct

    __construct(\Reader $in = null)

inherited

### Arguments

#### $in

`\Reader`

## Initializes parameters This method is only called when this filter is used through a <filterreader> tag in build file.

    _initialize()

## Close stream.

    close()

inherited abstract

throws | if there is an error closing stream

## Returns whether the end of file has been reached with input stream.

    eof() : boolean

inherited

### Response

`boolean`

## Returns the "begin token" character.

    getBeginToken() : string

### Response

`string`

The character used to denote the beginning of a token.

## Returns the drectory where to look for the files to use for token replacement

    getDir()

## Returns the "end token" character.

    getEndToken() : \the

### Response

`\the`

character used to denote the beginning of a token

## Returns the initialized status.

    getInitialized() : boolean

inherited

### Response

`boolean`

whether or not the filter is initialized

## Returns the parameters to be used by this filter.

    getParameters() : array

inherited

### Response

`array`

the parameters to be used by this filter

## 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"

    getPostfix()

## getPrefix

    getPrefix() : string

### Response

`string`

## Returns the project this filter is part of.

    getProject() : object

inherited

### Response

`object`

The project this filter is part of

## Returns the filename, url, etc. that is being read from.

    getResource() : string

inherited abstract

This is critical for, e.g., ExpatParser's ability to know the filename that is throwing an ExpatParserException, etc.

### Response

`string`

## Returns the drectory where to look for the files to use for token replacement

    getTranslateHTML()

## Convenience method to support logging in filters.

    log(string $msg, integer $level = \Project::MSG_INFO) : void

inherited

### Arguments

#### $msg

`string`

Message to log.

#### $level

`integer`

Priority level.

## If supported, places a "marker" (like a bookmark) at current stream position.

    mark()

inherited

A subsequent call to reset() will move stream position back to last marker (if supported).

## Whether marking is supported.

    markSupported() : boolean

inherited

### Response

`boolean`

## Read data from source.

    read(integer $len = null)

inherited abstract

If length is specified, then only that number of chars is read, otherwise stream is read until EOF.

### Arguments

#### $len

`integer`

## Reads a line of text ending with '\n' (or until the end of the stream).

    readLine() : string

inherited

The returned String retains the '\n'.

throws | if the underlying reader throws one during reading

### Response

`string`

the line read, or `null` if the end of the stream has already been reached

## Is stream ready for reading.

    ready() : boolean

inherited

### Response

`boolean`

## Replace the token found with the appropriate file contents

    replaceTokenCallback(array $matches) : string

### Arguments

#### $matches

`array`

Array of 1 el containing key to search for.

### Response

`string`

Text with which to replace key or value of key if none is found.

## Reset the current position in stream to beginning or last mark (if supported).

    reset()

inherited

## Sets the "begin token" character.

    setBeginToken(string $beginToken)

### Arguments

#### $beginToken

`string`

the character used to denote the beginning of a token.

## Sets the drectory where to look for the files to use for token replacement

    setDir(string $dir)

### Arguments

#### $dir

`string`

## Sets the "end token" character.

    setEndToken(string $endToken)

### Arguments

#### $endToken

`string`

the character used to denote the end of a token

## Sets the initialized status.

    setInitialized(boolean $initialized)

inherited

### Arguments

#### $initialized

`boolean`

Whether or not the filter is initialized.

## Sets the parameters used by this filter, and sets the filter to an uninitialized status.

    setParameters(array $parameters) : void

inherited

throws |

### Arguments

#### $parameters

`array`

Array of parameters to be used by this filter. Should not be `null`.

## 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"

    setPostfix(string $postfix)

### Arguments

#### $postfix

`string`

## 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"

    setPrefix(string $prefix)

### Arguments

#### $prefix

`string`

## Sets the project to work with.

    setProject(object|\Project $project)

inherited

### Arguments

#### $project

`object|\Project`

The project this filter is part of. Should not be `null`.

## setReader

    setReader(\Reader $in)

inherited

### Arguments

#### $in

`\Reader`

## Move stream position relative to current pos.

    skip(integer $n)

inherited

### Arguments

#### $n

`integer`

### Constants

## Default "begin token" character.

    DEFAULT_BEGIN_TOKEN

var |

## Default "end token" character.

    DEFAULT_END_TOKEN

var |

### Properties

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

    _tokensources : array

var |

### Type(s)

`array`

## Character marking the beginning of a token.

    _beginToken : string

var |

### Type(s)

`string`

## Character marking the end of a token.

    _endToken : string

var |

### Type(s)

`string`

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

    _prefix : string

var |

### Type(s)

`string`

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

    _postfix : string

var |

### Type(s)

`string`

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

    _dir : string

var |

### Type(s)

`string`

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

    _translatehtml : boolean

var |

### Type(s)

`boolean`

## The passed in parameter array.

    _parameters : array

inherited

var |

### Type(s)

`array`

## Have the parameters passed been interpreted?

    initialized :

inherited

### Type(s)

``

## The Phing project this filter is part of.

    project :

inherited

### Type(s)

``

## in

    in : \Reader

inherited

var |

### Type(s)

`\Reader`