zendframework/zend-modulemanager

composer dependencies should fit code dependencies

Closed this issue · 1 comments

This issue refers to zendframework/zend-modulemanager v2.7.2 but was already existent in v2.5.0.

The ModuleManagerFactory adds service managers for each (obviously optional) repository such as zendframework/zend-serializer (SerializerAdapterManager), zendframework/zend-log (LogProcessorManager) and many more.

These repositories are suggested repositories in zendframework/modulemanager and since then, they shouldn't be added by the ModuleManagerFactory.
Actually I get the following exception if I do not require the "semi-optional" packages:

PHP Fatal error:  Class 'Zend\Serializer\AdapterPluginManager' not found in /Users/max/git/some-module/vendor/zendframework/zend-mvc/src/Service/AbstractPluginManagerFactory.php on line 36

And that is because the ModuleManagerFactory adds these not available service managers which getting loaded during ModuleEvent::EVENT_LOAD_MODULES_POST in \Zend\ModuleManager\Listener\ServiceListener::onLoadModulesPost.

So the question is, why are these packages optional and lead to exceptions if not required?

With v2, we didnt' fully separate the various components properly, and assumed that if you were building an MVC application, you were using the full framework. Over time, we've loosened requirements, but the fact still remains that if you are using a zend-mvc v2 release, you basically need to install all suggested components as well. (The reason they are not marked as required is that you can, potentially, use your own factories instead of those provided in the Zend\Mvc\Service namespace, which would allow you to restrict to only those components you need.)

Technically, this is not a zend-modulemanager issue, but one of zend-mvc, as it is the ModuleManager factory in zend-mvc that is injecting the additional plugin managers. We could not address it properly in a v2 release without breaking backwards compatibility, so we addressed it with the zend-mvc v3 release:

  • Zend\Mvc\Service\ModuleManagerFactory now only adds service listener definitions for plugin managers of components directly required by zend-mvc.
  • Each component now registers its plugin managers with the service listener directly. Each component with potential MVC integrations now defines a Module class to tie into initialization and bootstrap events.

This approach resolves the exact issue you're reporting above.