6.9 Writing Selectors

Custom selectors are datatypes that implement phing.types.selectors.FileSelector.

There is only one method required, public function isSelected(PhingFile $basedir, string $filename, PhingFile $file): bool. It returns true or false depending on whether the given file should be selected or not.

An example of a custom selection that selects filenames ending in .php would be:

class PhpSelector implements FileSelector
{
    public function isSelected(PhingFile $b, string $filename, PhingFile $f)
    {
        return StringHelper::endsWith('.php', strtolower($filename));
    }
}

Adding the selector to the system is achieved as follows:

<typedef
            name="phpselector"
            classname="PhpSelector"/>

This selector can now be used wherever a Core Phing selector is used, for example:

<copy todir="to">
    <fileset dir="src">
        <phpselector/>
    </fileset>
</copy>