views:

468

answers:

3

Zend_Tool is nice, it generates a project with a given name & a given path.

But after a while, i started to develop my own tools, like helpers, plugins, validators, etc...

I put them all in library, which is ok (and recommanded).

But, i would have to start my project with the same bootstrap file, including initialization of my plugins, helpers, translate object, db object, etc..

Some could be done in the application.ini.

Then, i'd have like to be able to write my own generic application.ini, some initialization code inside my bootstrap, maybe some directory, etc...

What/How do you do ?

A: 

You can extend zend tool classes if you need. But I think it'S better to have for example your own Bootstrap class in library and just change the generated class Boostrap extends Zend_Application_Boostrap_Bootstrap to extends My_Bootstrap

Tomáš Fejfar
A: 

Modules can be used for code-reuse at the project level:

http://framework.zend.com/manual/en/zend.controller.modular.html

If you have a new project that is similar in functionality to an existing one, you can add a new module to your existing project and turn specific modules on/off in the application.ini file. Module-specific initialization can be contained in their own Bootstraps.

But it isn't completely straightforward...

When I tried a few months ago, Zend_Tool had issues creating the module directory structure and I had to create it by hand. Also, some features you might require (module-specific configuration files, merged navigation definitions, and/or specific deployment configs) are not built into Zend Framework currently and would need to be written.

For my setup I have an application.ini for each deployment (application-foo.ini, application-bar.ini). Using an environment variable (SetEnv APP_DEPLOYMENT foo) set in the .htaccess file, the appropriate ini file is chosen via custom logic in the bootstrap (index.php). Generic configuration for the modules are put into module-specific configuration files, loaded via a custom subclass of Zend_Application_Resource_Modules.

A deployment process can be run to exclude any unneeded modules, public files and/or libraries depending on the site. Phing, Capistrano, or Ant is good for that.

Guruno
+3  A: 

I guess one solution would be to edit the files in library/zend/Tool/Project/Context/Zf which seem to provide the contents/structures used for the out-of-the-box project.

But that doesn't sound like the right solution. Further I have already found out in my ongoing research that the tool (zf.bat or sh) scans all directories on the php inculde_path for 'manifests' and 'providers' which in turn provide the functionality for the tool.

The article Zend_Tool for the Developer by one of the Zend Developers has just clarified some things.

Manifests

can be used to bundle and 'load' as many providers as you want.

Providers

Providers in turn are the actual containers for the CLI commands you want to use and the design is similar to the 'controller/action' design. You can call a method (action) of a specific class (controller) from the command prompt by calling:

zf <method-name> <class-name>

given that this class extends Zend_Tool_Project_Provider_Abstract

Subsequently I found out that the Manifest that gets the providers responsible for setting up the out-of-the-box layout is found in:

library\Zend\Tool\Project\Provider\Manifest.php

In this file the following Providers are returned to the tool:

public function getProviders()
{
    return array(
        new Zend_Tool_Project_Provider_Profile(),
        new Zend_Tool_Project_Provider_Project(),
        new Zend_Tool_Project_Provider_Controller(),
        new Zend_Tool_Project_Provider_Action(),
        new Zend_Tool_Project_Provider_View(),
        new Zend_Tool_Project_Provider_Module(),
        new Zend_Tool_Project_Provider_ProjectProvider()
    );
}

These are obviously the available default CLI commands.

Furthermore it is also obvious that you can have a lot of influence on what is created by providing your own xml project profile which is by default created in library/Zend/Tool/Project/Provider/Project in the method _getDefaultProfile().

What I'm trying at the moment:

  • overriding the default Providers and the default Manifest with my own stuff and in my own Project Provider override the _getDefaultProfile() and set some stuff to true instead of false.

I'm having some problems with the CLI not accepting my Providers. I'll report back on the progress!

tharkun