Writing filename mappers is simplified by interface support in PHP5. Essentially,
your custom filename mapper must implement
phing.mappers.FileNameMapper
. Here's an example of a filename
mapper that creates DOS-style file names. For this example, the "to" and "from"
attributes are not needed because all files will be transformed. To see the "to" and
"from" attributes in action, look at phing.mappers.GlobMapper
or
phing.mappers.RegexpMapper
.
require_once "phing/mappers/FileNameMapper.php"; /** * A mapper that makes those ugly DOS filenames. */ class DOSMapper implements FileNameMapper { /** * The main() method actually performs the mapping. * * In this case we transform the $sourceFilename into * a DOS-compatible name. E.g. * ExtendingPhing.html -> EXTENDI~.DOC * * @param string $sourceFilename The name to be coverted. * @return array The matched filenames. */ public function main($sourceFilename) { $info = pathinfo($sourceFilename); $ext = $info['extension']; // get basename w/o extension $bname = preg_replace('/\.\w+\$/', '', $info['basename']); if (strlen($bname) > 8) { $bname = substr($bname,0,7) . '~'; } if (strlen($ext) > 3) { $ext = substr($bname,0,3); } if (!empty($ext)) { $res = $bname . '.' . $ext; } else { $res = $bname; } return (array) strtoupper($res); } /** * The "from" attribute is not needed here, but method must exist. */ public function setFrom($from) {} /** * The "from" attribute is not needed here, but method must exist. */ public function setTo($to) {} }