Article

ZF2 ServiceManager Factories and Aliases

Read and refactor ZF2 ServiceManager configuration so Laminas migration does not leave broken factories behind.

The ServiceManager is the DI heart of ZF2. Invokables, factories, aliases, and shared flags decide whether controllers boot or explode after a package rename.

// LEGACY
'factories' => [
    'Zend\Db\Adapter\Adapter' => 'Zend\Db\Adapter\AdapterServiceFactory',
],
'aliases' => [
    'db' => 'Zend\Db\Adapter\Adapter',
],
// MODERN (Laminas names after migrate)
'factories' => [
    \Laminas\Db\Adapter\Adapter::class => \Laminas\Db\Adapter\AdapterServiceFactory::class,
],
'aliases' => [
    'db' => \Laminas\Db\Adapter\Adapter::class,
],

Pre-migration cleanup

  • Replace string service names with ::class constants where safe
  • Delete unused factories rather than migrating noise
  • Note custom plugin managers (forms, hydrators, validators)

Continue to Laminas ServiceManager and the flagship migration guide.

Related tools

Related reading