Since some weeks ago, the agavi build system features a set of new nifty features. The build system has always been a great help to me as a developer saving me the tedious, boring work of writing the action, view and model stubs. And now, the build system gets even better:
The agavi build system now supports
- Generation of executeRequestMethod() methods for action. That saves another hundred keystrokes when generating an action.
- Generation of simple actions. Shaves off even more.
- Generation of executeOutputType() methods for views.
- Generation of properties and the respective getters and setters for models.
Let’s have a lookt at a short example: Before the change, creation of a view went like this:
> agavi view-create
> Module name: Default
> Action name: Index
> View name: Success
Done. But the view would only support the default executeHtml() method to handle the html output type. It would always contain this method, even if I only wanted to handle text output. Now this changes
> agavi view-create
> Module name: Default
> Action name: Index
> View name: Success
> Space-separated list of output types that should be handled. [html]: text
Done. So now I have one single prompt more, but the view is created with exactly the output type(s) that I want it to have. In this case it only handles text but I could list any number of output types here.
The generated code to handle the various output types can be controlled by supplying a suitable template. The default template generates the standard code, using a setup method that is named like the output type:
public function executeText(AgaviRequestDataHolder $rd)
{
$this->setupText($rd);
$this->setAttribute('_title', 'Index');
}
If I want that changed for all text output types, I just create a suitable template that changes the code the way I want. All other output types will still use the default template.
This feature not only saves the developer from writing all that boilerplate code but has other benefits as well. We can now go and integrate the testing system and the build system even further. Now that we generate the methods for you, we have all the information to generate the relevant testcases as well, reminding you that the best way to keep your code bug-free is to automate the testing.
If you’d like to check this out, have a look at changeset 4155 or see the relevant ticket for further information.