A free and open-source book on ZF3 for beginners


3.11. Plugin Managers

Now that you understand what service manager is, it shouldn't be very difficult for you to learn the concept of plugin managers. A plugin manager is almost the same as the service manager, but it can instantiate services of the single type only. Which plugin type a plugin manager may be hard-coded instantiated inside the plugin manager class.

Why would you need such thing? Actually, in ZF3, plugin managers are widely used, because they allow to instantiate a plugin only when it is needed (this reduces CPU and memory usage). There is a separate plugin manager for:

The fact that each plugin manager inherits from the Zend\ServiceManager\ServiceManager base class allows all plugin managers to have similar configuration. For example, controllers are registered under the controllers key in module.config.php file, and this key may have the same subkeys: services, invokables, factories, abstract_factories, and aliases. The same structure has the view_helpers key that is used for registering view helpers, the controller_plugins key that is used for registering controller plugins, and so on.


Top