PHP Objects, Patterns and Practice (3rd edition)

(Barry) #1
CHAPTER 19 ■ AUTOMATED BUILD WITH PHING




Any changes I make to the inc_code patternset will automatically update any types that use it. As
with FileSet, you can place exclude rules either in an excludes attribute or a set of exclude subelements.
The same is true of include rules.
Some patternset element attributes are summarized in Table 19–4.


Table 19–4. Some Attributes of the patternset Element


Attribute Required Description

Id No A unique handle for referring to the element

Excludes No A list of patterns for exclusion

Includes No A list of patterns for inclusion

Refid No Current patternset is a reference to patternset of given ID

FilterChain


The types that I have encountered so far have provided mechanisms for selecting sets of files.
FilterChain, by contrast, provides a flexible mechanism for transforming the contents of text files.
In common with all types, defining a filterchain element does not in itself cause any changes to
take place. The element and its children must first be associated with a task—that is, an element that
tells Phing to take a course of action. I will return to tasks a little later.
A filterchain element groups any number of filters together. Filters operate on files like a
pipeline—the first alters its file and passes its results on to the second, which makes its own alterations,
and so on. By combining multiple filters in a filterchain element, you can effect flexible
transformations.
Here I dive straight in and create a filterchain that removes PHP comments from any text passed
to it:





The StripPhpComments task does just what the name suggests. If you have provided detailed API
documentation in your source code, you may have made life easy for developers, but you have also
added a lot of dead weight to your project. Since all the work that matters takes place within your source
directories, there is no reason why you should not strip out comments on installation.


■Note If you use a build tool for your projects, ensure that no one makes changes in the installed code. The


installer will copy over any altered files, and the changes will be lost. I have seen it happen.

Free download pdf