Search code examples
phpmodulezend-framework2composer-phpautoloader

Getting development copy of ZF2 module


I have one main Application module and several dependent modules. All modules have their own repositories on github and installed via composer (using satis local repository). During development process I need to make changes either in main module or dependent ones. But dependent modules are located in /vendor directory, and it's bad idea to make changes and git init there. So, I need a local copy of each module in /devmodules folder and add this folder to application.config:

'module_listener_options' => array(
 // ...
  'module_paths' => array(
      './module',
      './vendor',
      './devmodules'
  ),

How to tell ZF don't use /vendor for such modules? Change autoloader / use make tool or hook script in composer to make new copy and clean /vendor? What is the best practice to solve the problem?

P.S. Dependent modules are my own modules I develop in parallel with Application. So I want to see changes immediately, not after commit/push/update.


Solution

  • For me I get the next solution:

    1) Add somethink like that to "script"-section in composer.json:

    "devmodules": [
        "mkdir devmodules",
        "git clone git://github.com/4orever/ppc-auth/           devmodules/ppc-auth",
        "git clone git://github.com/4orever/ppc-backend/        devmodules/ppc-backend",
        "git clone git://github.com/4orever/ppc-backend-client/ devmodules/ppc-backend-client",
        "git clone git://github.com/4orever/ppc-dev-mode/       devmodules/ppc-dev-mode",
        "git clone git://github.com/4orever/ppc-main-assets/    devmodules/ppc-main-assets",
        "rm -rf vendor/4orever"
    ]
    

    2) And add "autoload-dev":

     "autoload-dev": {
         "psr-4": {
            "PpcMainAssets\\":  "devmodules/ppc-main-assets/",
            "PpcBackend\\":     "devmodules/ppc-backend/src",
            "PpcAuth\\":     "devmodules/ppc-auth/src"
        },
        "classmap":[
            "devmodules/ppc-backend/Module.php",
            "devmodules/ppc-backend-client/Module.php",
            "devmodules/ppc-auth/Module.php"
        ]
     }
    

    3) For production just use: composer install --no-dev. I haven't test it, but I suppose that 'autoload-dev' must be ignored. If not run composer dumpautoload --no-dev

    4) For development: composer install and composer devmodules

    I don't like to use standard ./vendor folder made by composer because it's not connected to git by default. I prefer git clone in the folder I need.

    I hope it would be usefull.