Improve universality of getting configurations for ZF2

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

Improve universality of getting configurations for ZF2

This post has NOT been accepted by the mailing list yet.
Hi guys!

(For next text we will use 'template_path_stack config option for showing examples)

I often had to decide which method of naming choose in configuration file camelCased or underscore_separated or dash-separated. Finally I understood that I should use all of them but each of them in own context:

  • php class member or function variable, doctrine 2 annotation (came cased)
  • file-syste path name, xml tags and attribute names (dash separated, this strategy uses in injectViewTemplate, and doctrine package paths)
  • ini file options (only one, as I know. Dash separated).
  • Now i usually transform one to another like

    $templatePathStack = $this->getConfig()->get('template_path_stack');
    //do something with $templatePathStack;

    Recently I created console controller where flags and command usually dash-separated. So I should do this:

    $adId = (int) $this->params('ad-id');
    $accountId = (int) $this->params('account-id');

    So I should always remember about converting and its type.

    To resolve thoughts like "Why should I use this name convention in my module?" I propose final config should be in php array format as it accepts any key. Assume it will use came case convention (but may be any).

    For using dash separated naming you just need change file format to xml or even php array and say that it dash separated.


    To arrange any config file to camel cased php array we will use standard reader for those type and then resulting array will pass throw respective filter (dashToCameCase). If hire present any non-convenient key you can add special strategy(read closure) to filter this key for proper name. How read config we could simple add to \VendorName\Module:getConfig() (or use instead of that function getDashSeparatedConfig, or use a factory same as for services)

    Additional + is that we will be able to use in routes usual url format. And by helper get robust router name like:

    //url like
    //and route name the same:
    $this->url()->fromRoute('admin/mail-posting/account', array('action'=> 'edit', 'id' => $id));

    I want to see here votes if should it be? An your opinion or some notices.