Zend Framework 2: Services

Services.

There are various ways through which the services can be configured into the Service Manager.

Service Manager Configuration –

Configuration requires a “service_manager” key at the top level of your configuration, with any of the following sub-keys:

  • abstract_factories, which should be an array of abstract factory class names.
  • aliases, which should be an associative array of alias name/target name pairs (where the target name may also be an alias).
  • factories, an array of service name/factory class name pairs. The factories should be either classes implementing “Zend\ServiceManager\FactoryInterface” or invokable classes. If you are using PHP configuration files, you may provide any PHP callable as the factory.
  • invokables, an array of service name/class name pairs. The class name should be class that may be directly instantiated without any constructor arguments.
  • services, an array of service name/object pairs. Clearly, this will only work with PHP configuration.
  • shared, an array of service name/boolean pairs, indicating whether or not a service should be shared. By default, theServiceManager assumes all services are shared, but you may specify a boolean false value here to indicate a new instance should be returned.
  • initializers, .
  • allow_override, .

a. abstract_factories: an array of service name/class name pairs. The class name should be a class that may be directly instantiated without any constructor arguments. Mostly Controllers are defined here.

/* __ModuleName__/config/module.config.php */

return array(

‘controllers’ => array (

‘invokables’ => array (

‘__ModuleName__\Controller\User’ => ‘__ModuleName__\Controller\UserController’,

)

)

);

Reference:

http://framework.zend.com/manual/2.2/en/modules/zend.service-manager.quick-start.html

http://samsonasik.wordpress.com/2013/01/02/zend-framework-2-cheat-sheet-service-manager/

Leave a comment