With FilterChains
and filters provide a powerful tool for
changing contents of files, Mappers provide a powerful tool for changing the names
of files.
To use a Mapper, you must specify a pattern to match on and a replacement pattern
that describes how the matched pattern should be transformed. The simplest form is
basically no different from the DOS copy
command:
copy *.bat *.txt
In Phing this is the glob
Mapper:
<mapper type="glob" from="*.bat" to="*.txt"/>
Phing also provides support for more complex mapping using regular expressions:
<mapper type="regexp" from="^(.*)\.conf\.xml$$" to="\1.php"/>
Consider the example below to see how Mappers can be used in a build file. This
example includes some of the other concepts introduced in this chapter, such as
FilterChains
and FileSets
. If you don't
understand everything, don't worry. The important point is that Mappers are types
too, which can be used in tasks that support them.
<copy> <fileset dir="."> <include name="*.ent.xml"/> </fileset> <mapper type="regexp" from="^(.*)\.ent\.xml$" to="\1.php"/> <filterchain> <filterreader classname="phing.filters.XsltFilter"> <param name="style" value="ent2php.xsl"/> </filterreader> </filterchain> </copy>
For a complete reference, see Core Types