Article

Laminas ServiceManager after Zend Framework

Operate Laminas ServiceManager factories, aliases, and plugin managers after migrating from Zend\ServiceManager.

Post-migration, most “class not found” and “Unable to resolve service” failures trace to ServiceManager configuration that still references old names, deleted invokables, or factories that were never updated for constructor changes.

// LEGACY ZF-era factory signature style (string keys)
'factories' => [
    'My\Service\Report' => 'My\Factory\ReportFactory',
],
// MODERN Laminas / PSR-11 style
use Laminas\ServiceManager\Factory\FactoryInterface;
use Psr\Container\ContainerInterface;

final class ReportFactory implements FactoryInterface
{
    public function __invoke(ContainerInterface $container, $requestedName, ?array $options = null): ReportService
    {
        return new ReportService(
            $container->get(\Laminas\Db\Adapter\Adapter::class)
        );
    }
}

Verification steps

  • Boot the container in a CLI script and get() critical services
  • Clear merged config caches after deploy
  • Search for remaining Zend\\ServiceManager strings
  • Align controller manager / form manager plugin configs

Related: ZF2 ServiceManager, Laminas MVC, autoload class not found.

Related tools

Related reading