Issues
So I try to decouple my application to multiple module project ( each has its own composer.json ), then the real application will load all this project through composer
Each of this module project will have a user-interface accessible through browser and can start individually, so it's not just a simple library. This file will exist on each module project:
- config/application.config.php
- public/index.php
Example Module ( Dependency is what I write in module array in application.config.php ):
- UIModule
- Dependency : AssetManager, UIModule
- CMSModule
- Dependency : UIModule, CMSModule
- AccountingModule:
- Dependency : UIModule, AccountingModule
Now in my final application lets say MyApplication it need both CMSModule and AccountingModule, but I cannot write only just this two module in application.config.php. Instead I have to write:
- AssetManager -> this should be load by UIModule
- UIModule -> this should be load by CMS/Accounting Module
- CMSModule
- AccountingModule
I should only require to write this two in MyApplication
- CMSModule
- AccountingModule
Is this can be done ? which I think what this guy want to achieve in Loading Modules Dynamically in Zend Framework 2

Based on our exchange in the comments and the question, you're going to need at least 3 applications. I'll give you a quick examples, you'll have to update your requirements for each application yourself. After the composer.json configs I'll give you a skeleton module to use as a theme module.
These config's are to be used as the
rootcomposer.json config files. Each of the required packages should have their own composer file listing requirements for the specific package.For example, a "core" module would require various Zend Framework packages. A "theme" package could be requiring other ZF packages, such as
zendframework/zend-viewin order to be able to have a GUI layout.Setting up 3 separate Zend Framework applications with overlapping requirements
composer.jsonfor application 1composer.jsonfor application 2composer.jsonfor application 3 (has no theme)As you can see, the Applications 1 & 2 use the same
MODULE_THEMEpackage, as you outlined in the diagram in your question.Now, the creation of a package for Zend Framework is pretty much the same for every package you create, so modify what follows to the requirements you have for each module (in a package).
Creating a theme module
This module basically replaces the
Applicationmodule that you get by default when you install the Zend Framework (2 or 3) Skeleton Application.I've recently upgraded everything I have with Zend Framework to Zend Framework 3, so I'll be giving you a setup tailored for ZF3. However, downgrading for ZF2 should not be too much of an issue.
Create config for what you need
A typical theme needs a few things, such as:
Config for this could be (not limited to! Do with it what you wish!) as such in the
module.config.phpof the Theme moduleFile/module structure based on config
The location of the package would be
/vendor/COMPANY_NAME/THEME_MODULE_NAME(as you would've defined in thenameproperty in thecomposer.jsonfile for this package.The folder/file structure would be:
ThemeController & *Factory
These are very simple as the Controller is pretty much a clone of the original
IndexControllerprovided by the Skeleton Application. The Factory in this instance does nothing but return the Controller. As such you could replace the config for it with the FQCN to theInvokableFactoryof Zend Framework 3 and not make the Factory class. However, if yourThemeControllerneeds some requirements (such as aRegisterForm), you're going to need the Factory to provide these.ThemeController
ThemeControllerFactory
Theme composer requirements
Obviously your modules will not have the same requirements. Make sure you figure out what they are, per module.
For my own Theme module, I have the following Zend Framework requirements in my
composer.jsonfile:In the
requiresection I also have:"rwoverdijk/assetmanager": "^1.6",. This module is used to mash together all CSS, JS (any type really) of file to a determined location. I would advise you to have a look at it (here).Notes on the answer
COMPANY_NAMEwith the username of your Github account (or the identifying account name if your using Bitbucket or Gitlab)THEME_MODULE_NAMEwith the name of the repository"rwoverdijk/assetmanager": "^1.6"). Version locking can save you a lot of hassle in the future...Additionally: using a package as a "Theme module" allows you to completely remove the
module/folder originally shipped with the Skeleton Application of Zend Framework. However, you're hereby advised to use themodule/folder for application specific modules. If you create a package for everything, you'll soon find yourself maintenance hell.