views:

218

answers:

3

I'd like to use Zend_Tool (ZF 1.9) with my project, but I would like to be able to customize the default output of new files. For example, all Controllers should have a specific header pre-pended to the output with phpdoc markup and licensing information to avoid me having to add this as an extra step.

Also, for this particular project (but not all other projects), I need the controllers to extend something other than the default Zend controller as I have extended that for some specific functionality.

The documentation alludes to the ability to do these things, but it does not make it very clear.

From what I can tell I can set up a ~/.zf directory (on ***nix based systems) and include custom providers there. However, this will be machine-wide as opposed to limited to single project scope. Also, while this will add new providers it does not (seemingly) allow me to customize the functionality of existing providers.

Any help here would be greatly appreciated!

A: 

You can naturally continue to override when you define the specific classes. You can declare them to be based on your class, rather than the ZF class.

For specific projects, you can modify your classpath to be a custom version of ZF or possibly have a custom override folder. With a custom folder then your changes are not machine wide, but neither is your zend framework. on ***nix based systems, you can leverage symbolic links to keep yourself to one copy of ZF.

Are you trying to modify your source code to include the license headers and PHPdoc? If so, what I have done in the past is have a simple build step that adds the information you need. Each file type can have the appropriate header information. You can have nice tags to tell the system to ignore files, or only run on controllers.

Good Luck, Jacob

TheJacobTaylor
+1  A: 

Essentially what Jacob was getting at: what you're talking seems like simple class extending. There's a really simple slideshow introduction to extending Zend Framework here:

http://www.slideshare.net/PHPBelgium/extending-zend-framework-presentation

There are also lots of other resources available online for extending Zend Framework. You can create separate source trees for your different projects, and functionality common to various projects can be added to abstract classes that are in common folders. Something like this isn't common, but I've found it works in those kinds of situations:

class My_Component_HelloProvider extends My_Common_Component_HelloProvider
{
    public function say()
    {
        echo 'Hello from my provider!';
    }

    // public function do() is inherited

}

class My_Common_Component_HelloProvider
    implements Zend_Tool_Framework_Provider_Interface
{
    public function do()
    {
        // do something
    }
}

Let me know if this is different from what you're trying to do, but there's no reason you can't build multiple applcation extensions from a single instance of ZF.

angrychimp
A: 

What if you use Zend_Tool to setup the basic structure and then use Zend_CodeGenerator to add the project specific things like docblocks and such.

tharkun