Zend_Tool and ZF 1.8
By now, you are sure to have heard the news, Zend Framework 1.8 has landed. With ZF 1.8 comes several new features such as Zend_Application, Zend_Navigation, Zend_Tag_Cloud, and, my favorite Zend_Tool. Zend_Tool is not a component in the typical sense. Most components have a class at its top level namespace, Zend_Tool does not. Most components are generally consumed inside your application code to simplify runtime tasks, Zend_Tool does not. Zend_Tool is more akin to a framework than a component – a framework within a framework.
So what is Zend_Tool?
The initiative began by exploring what it would take to create a next generation framework for RAD, or Rapid Application Development. RAD as you can imagine, is a term with a pretty wide definition. In its most general sense, its a term that describes the speed at which you can build the resources that form your application's backlog of requirements. In the most ideal of situations, the initial development, or loading phase of a project, should be kept to an absolute minimum such that the developers can get on with the more interesting development. After all, the more "interesting development" is more than likely the reason the application was born.
So if there is interesting development, what is the uninteresting development? For Zend Framework, and most MVC based frameworks for that matter, it's the process of creating the initial project resources common to all projects: the primary project structure, initial configuration files, initial bootstrapping and autoloading code, etc. It also includes the tasks of error handling, controller creation, and view creation to name a few more. For someone just getting involved with ZF, some of these tasks would require hours of reading though tutorials, manuals, and quickstarts. Not exactly "rapid".
Zend_Tool As A Framework
Instead of whipping together a system that was targeted specifically for creating ZF based applications, specifically on the command line, and strictly generating code and not modifying existing code, we set out to build a system extensible in every regard that should concern a developer. Zend_Tool was designed to facilitate abstraction at all the necessary points where we felt that developers would want to extend the system. For example, while we have a primary CLI client, the tooling framework was developed as a generic RPC (remote procedure call) system to enable developing other non-CLI clients. While we have the stock providers (the capabilities of the system), the interfaces to build future providers has remained simple and easy to extend and understand.
Zend_CodeGenerator & Zend_Reflection
During development, we discovered a couple of problem areas that had no solid solution. Code generation is one of those areas. Generally speaking, when you talk about generating code, it's typically a template-based approach; the generated code comes from template files which are usually written without regard as to whether or not they are well-formed (by the target language's standard). Having an templated approach also introduces the risk of developers going outside the suggested coding standard and generating generally bad code (bad code in this sense is both code that will not run as well as poorly formatted code). So, we immediately realized that there was an opportunity to create a component that would provide an object-oriented interface, similar to that of PHP's Reflection API, with the sole purpose of generating well-formed and well-formatted object oriented code. It should be said that the Zend_CodeGenerator component can be used without the rest of the Zend_Tool stack. This means that if you ever find yourself in a position where you need to repeatedly generate code, the first place you should look is Zend_CodeGenerator.
Zend_CodeGenerator doesn't simply write code from scratch; it has the capability of reading existing code, modifying it, and producing new code. This is primarily due to the other component born out of Zend_Tool, Zend_Reflection. Zend_Reflection is not, and I repeat, not a reinvention of the wheel. In fact, it extends PHP's Reflection API to add support for user-based extensions (i.e., extending the Reflection API), docblock reflection (and annotation tags within docblocks), and file-based reflection. The semantics of the component are true to its origins, and can be used as a drop in replacement when the additional feature-set is needed.
Zend_CodeGenerator and Zend_Reflection have similar API's, with Zend_Reflection targetting reading code structure, and Zend_CodeGenerator targetting writing code structure. Together these two components make it easy to reflect and write code during the development process of an application.
Zend_Tool Command Line Client et. al.
It goes without saying that CLI based RAD is a very highly desired for ZF developers. As mentioned previously, the task of setting up the initial resources of a project can be tedious. Many developers prefer to interact with their development environment through the terminal, or command line, so naturally, this is the place we decided would make the most sense to build a client into Zend_Tool. This does not mean it will be the only client; as mentioned previously, the client functionality of Zend_Tool has been abstracted in such a way that additional clients can be built to interact with Zend_Tool. IDEs and text editors have an opportunity to hook into the client framework and dispatch commands from their native interface. Two potential extension points include to of my favorite tools, Zend Studio and Textmate -- but the possibilities are almost limitless. Any client that can execute PHP can effectively build on top of Zend_Tool for tooling needs.
Zend_Tool_Project
Since project development is an iterative process, the tooling side of the equation also needs to keep track of history, so to speak. What we mean by history is keeping track of the actions you have performed: what have you created, where is it located in the project structure, and what is its context in the project? As an example, after creating a project, you might want to create a controller. For all intents and purposes, a controller is simply a file with a class in it; how can the tooling environment know the difference between a regular file and a controller file?
Zend_Tool_Project sets out to solve this problem. Zend_Tool_Project is the bundle of functionality built to work with Zend_Tool_Framework to deliver a solution to the project management problem. Zend_Tool_Project keeps track of the resources inside your application, where they are in relation to each other, and the name by which you refer to them; this is the key to allowing "iterative development". As an example, if you had created that project, with a controller named "foo"; you might want to add actions to that controller later on down the line. To make development as seamless as possible, it should be as simple to modify as it was to create resources. To do this, Zend_Tool_Project keeps track of everything you've done inside your project.
In addition to being an application resource tracker, Zend_Tool_Project is the key part of Zend_Tool that delivers the "build a Zend Framework based project" solution. Zend_Tool_Project knows specifically what a project, controller, view, bootstrap class, index.php file, and so on, should look like, and aids you in creating them. If you were to take Zend_Tool_Project out of the Zend_Tool runtime, you'd be left with just the framework or platform to build a tooling system with. That said, any project can use Zend_Tool_Framework to build tools fulfilling their needs.
What It Can Currently Do
So, with all that in mind. What can it do right now? Instead of talking about it, lets walk through a few screenshots.
Help
Error
Create Project
create controller
create action
What's Next
In addition to what it can already do in the 1.8 release, several additional features are already in the pipeline. Some of these features are considered beta (which is why they are not in the distribution), or are still in the design phase. For example, with Zend_Application, we are finally deciding what a "model" should look like, even if we are only talking about what the name should be. Also, with 1.8 we are finally publishing the default project structure. For a project that has a very firm footing in the "component library" space, these are tremendous steps for Zend Framework.
In addition to model support, we also have plans to add "module" support (for building componentized applications), database connectivity, and Zend_Db_Table file generation. Look for these feature in the upcoming releases. Additionally, since Zend_Tool is so extensible, new (more beta) features can be distributed by outside projects that plug directly into Zend_Tool.


Comments (Login to leave comments)
Thanks a million to you and everyone who's contributed to this piece of ZF.
As you know, the masses are in the streets smashing windows and setting cars on fire demanding Zend_Tool support modules.
A couple questions:
Is there anything you can do today (at 1.8.0) to make a modular app with Zend_Tool -- even if it entails manually creating subtrees and hacking on .zfproject.xml?
And, once we do have our modular Zend_Tool-created modular app moving along, suppose you are sitting there in your Zend Studio when you decide FooController needs another action. It will break .zfproject.xml if you just write it, will it not? So, will the recommended way be to go over to your terminal window to add the action? Or... is Zend Studio planning to support this kinda thing and automatically keep our .zfproject.xml up to date?
Thanks,
David
http://davidmintz.org/
I am near complete on this new feature. I am getting the incubator and trunk sycned, then I will commit what i have to the incubator and give instructions on how to get it and test it out. Should have it in there by the end of the day (fully working or not), but definitely full working order by tomorrow.
Thanks!
Ralph
2) Once I put the library into include path, I got empty output.
question, did I miss something else?
***************************** ZF ERROR ********************************
In order to run the zf command, you need to ensure that Zend Framework
is inside your include_path. If you are running this tool without
ZendFramework in your include_path, you can alternatively set one of
two environment variables to for this tool to work:
a) ZEND_TOOL_INCLUDE_PATH_PREPEND="/path/to/ZendFramework/library"
OR alternatively
b) ZEND_TOOL_INCLUDE_PATH="/path/to/ZendFramework/library"
The former (a) will make the specified Zend Framework first in the
include_path whereas the latter (b) will replace the include_path
with the specified path.
Information:
original include_path: .;C:\xampp\php\pear\;
attempted include_path: .;C:\xampp\php\pear\;
script location: C:\xampp\php\\zf.php
First of all kudos for this awesome and 'riot causing' addition.
Now on to a question that pop up when playing around with Zend_Tool. Are there any plans to extend the create method of the Project provider, so that it also will setup an intial unit testing environment, or is this already possible via the available Test provider shown in 55.3 of the reference guide?
I guess a feature like this would skyrocket the testing spirit for Zend Framework based applications and lower the hurdle to get started with it.
Cheers,
Raphael Stolt
This is exactly what was missing in ZF. I can't wait to try the module generation. Is there a tutorial on how to create task in this subframework ?
Thanks
<p>I am a fan of the CakePHP framework because it works very intuitive for me and has a very easy learning curve for me, but the advantages of ZF made me decide to choose for ZF within our company. Now Zend Tool make it even more rapid. Keep on the good work.</p>
<p>Kind regards, Christine Furst</p>
After create a new project with Zend_Toll, it would be very usefull to have a project file that Zend Studio for Eclipse can read for importing.
Building project with Zend_Tool or Zend Studio and obtain the same result would be helpfull.
I translate it to Russian if you don't mind - http://lobach.info/develop/zf/zend-tool-and-zf-18/
prior to ZF-1.8+
my project (w/modules) directory tree looked like:
|-application/
| |- configs/
| |- library/
| |- modules
| | |- default/
| | | |- controllers/
| | | |- models/
| | | |- views/
| | |
| | |- admin/
| | |- controllers/
| | |- models/
| | |- views/
| |
| |- bootstrap.php
|
|-public/
|-index.html
Now, creating a project using Zend_Tool I get a directory tree like:
|-application/
| |- configs
| |- controllers/
| |- models/
| |- views/
| |- Bootstrap.php
|
|- library/
|- public/
| |-index.html
|- tests/
When I add a module (admin) to this project using Zend_Tool, the directory structure looks like:
|-application/
| |- configs
| |- controllers/
| |- models/
| |- modules
| | |- admin/
| | |- controllers/
| | |- models/
| | |- views/
| |
| |- views/
| |- Bootstrap.php
|
|- library/
|- public/
| |-index.html
|- tests/
Is this a new preferred directory structure for Zend Framework, having the default controllers, models, and views, outside the modules directory?
Thanks in Advance, for helping me get this straight in my mind.
jim
thank you very much for Zend_Tool.
I think there is a problem with "zf create module". I wrote in the forum http://forums.zend.com/viewtopic.php?f=69&t=815 that I made the mistake and I'm experiencing. Do you have any suggestions?
Regards,
Kevin