My little fork of ZFTool

Previous Topic Next Topic
classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view

My little fork of ZFTool

Ralf Eggert

in the last months I gave a lot of ZF2 beginner training courses in
Germany. Then I also attended the PHP Summit in Berlin a couple of weeks
ago and had an insight in other frameworks like Symfony 2 and TYPO3 Flow.

My big impression on both of these events was that ZF2 is in need of a
proper and solid tool to setup projects. Just the basic configuration
stuff is very time consuming for beginners and we need a tool to help
them to get a basic project skeleton up and running.

ZFTool is great for the start but really lacks a lot of features. So a
couple of weeks ago I started to create some pull requests and got a
little lost in the Git stuff. As well I saw that the PRs of ZFTool don't
seem to be accepted in a while. Since I wanted to spend my time on
programming and not on waiting or fixing my Git mee, I forked ZFTool and
started working on it. And here is the current result:

This is what I did so far:

- The parameters and its processing are standardized now by
  implementing the options class ZFTool\Options\RequestOptions

- The parameter normalization follows the ZF2 coding standards but
  can be turned of optionally

- A Generator class ZFTool\Generator\ModuleGenerator creates all needed
  files and class with Zend\Code\Generator

- A Configurator class ZFTool\Generator\ModuleConfigurator does the
  configuration work

- All controller classes have been refactored to use RequestOptions,
  ModuleGenerator and ModuleConfigurator to do the work; I also added
  a lot of parameter checks to give the user a proper feedback

- The console usage page was reorganized because it was getting very
  confusing by the time

- I added a -h flag to all commands to show a proper help page

- When a file is created a doc block is added by default
  (can be turned off)

- New feature to list all controllers for a module and all actions
  for a controller

    zf.php controllers <module_name> [<path>]
    zf.php actions <module_name> <controller_name> [<path>]

- When a controller is created the configuration (controller loader,
  view manager) is added as well (can be turned off)

- A factory for a controller class can be created during controller
  creation or afterwards

- A basic routing can be created (in two different flavors)

- New feature to create a view helper with an optional factory. The
  configuration for the view helper manager is added as well.

- When the classmap is created the Module.php getAutoloaderConfig()
  method is updated to use the classmap

- A couple of minor improvements and bug fixes

This is not the end of the road, so here is a little todo list of things
I would like to implement:

Please give it a try. Feedback (positive or negative) is very appreciated.

Thanks and best regards,

Reply | Threaded
Open this post in threaded view

Re: My little fork of ZFTool

This post has NOT been accepted by the mailing list yet.
One thing I think may be relevant is how detailed or "bare" one may want their code generation done.

Currently I use Zend Studio for my code generation, and it is hit or miss. i.e. sometimes it generates namespaces that are just wrong.  Official ZFTool is quite terse in a sense that it generates a controller or a module and the code inside of it is very basic.  I may want the tool to generate things for me in one go.

In particular, as an example, adding a basic single form to your application, should be a trivial task.  Currently it is not.   For one form, I may as well add things like:
*  src/ModuleName/Factory/PostControllerFactory.php
*  src/ModuleName/Form/PostForm.php
*  src/ModuleName/Form/PostFormFilter.php
*  view/ModuleName/post/index.phtml
* config/module.config.php changes such as routes, and factory pointers

That is five individual actions that can and should be done in one line.

It will be good to generate some basic form code inside as well, like an example, i.e. a form with a single string field, and submit button, for example. User can always delete code they don't need, but they can easily extend and edit code that is already there, without having to type their own all the time.  99%(*) of forms are the same in structure.

Not everyone may be interested in full-on verbosity of code structure and actual code inside of the php files, but I think having a "--verbose" option to generate the much needed monstrosity behind common ZF2, structures, such as forms, will help me greatly.  

I did not look at how ZFTool is implemented, but I think this can be done without much pain, especially it is done via using templates of code that you use, name, and generate for a particular naming structure.