🔥码云GVP开源项目 12k star Uniapp+ElementUI 功能强大 支持多语言、二开方便! 广告
# Chapter 6 Extending Phing Phing was designed to be flexible and easily extensible. Phing's existing core and optional tasks do provide a great deal of flexibility in processing files, performing database actions, and even getting user feedback during a build process. In some cases, however, the existing tasks just won't suffice and because of Phing's open, modular architecture adding exactly the functionality you need is often quite trivial. In this chapter we'll look primarily at how to create your own tasks, since that is probably the most useful way to extend Phing. We'll also give some more information about Phing's design and inner workings. 6.1 Extension Possibilities There are three main areas where Phing can be extended: [Tasks](ch06.html#sect.ext.tasks "6.1.1 Tasks"), [Types](ch06.html#sect.ext.types "Types"), [Mappers](ch06.html#sect.ext.mappers "Mappers"). The following sections discuss these options. 6.1.1 Tasks Tasks are pieces of codes that perform an atomic action like installing a file. Therefore a special worker class hast to be created and stored in a specific location, that actually implements the job. The worker is just the interface to Phing that must fulfill some requirements discussed later in this chapter, however it can - but not necessarily must - use other classes, workers and libraries that aid performing the operations needed. 6.1.2 Types Extending types is a rare need; nevertheless, you can do it. A possible type you might implement is `urlset`, for example. You may end up needing a new type for a task you write; for example, if you were writing the XSLTTask you might discover that you needed a special type for XSLTParams (even though in that case you could probably use the generic name/value Parameter type). In cases where the type is really only for a single task, you may want to just define the type class in the same file as the Task class, rather than creating an official stand-alone `Type`. 6.1.3 Mappers Creating new mappers is also a rare need, since most everything can be handled by the [Appendix聽F](apf.html "Appendix F. Core mappers"). The Mapper framework does provide a simple way for defining your own mappers to use instead, however, and mappers implement a very simple interface.