zendframework/zend-servicemanager
Abandoned Zend Framework ServiceManager (moved to laminas/laminas-servicemanager). Implements the Service Locator pattern to create and retrieve services/objects via factories and configuration. Includes docs, tests, and PHPBench benchmarks.
The zend-servicemanager package is a dependency injection container implementation from Zend Framework (now Laminas). Since the package is archived and last released in 2018, modern projects should use the actively maintained fork laminas/laminas-servicemanager. To get started quickly:
laminas/laminas-servicemanager via Composer (composer require laminas/laminas-servicemanager).ServiceManager with the config and use get() to resolve services.use Laminas\ServiceManager\ServiceManager;
use Laminas\ServiceManager\Factory\InvokableFactory;
$config = [
'services' => [
SomeInterface::class => new SomeConcreteClass(),
],
'factories' => [
AnotherService::class => InvokableFactory::class,
],
];
$sm = new ServiceManager($config);
$service = $sm->get(AnotherService::class);
FactoryInterface or implementing __invoke(ContainerInterface $container, $requestedName, ?array $options = null)) for complex instantiation logic or when dependencies need injection via the container.'aliases' => [ServiceInterface::class => ConcreteServiceImpl::class]).ServiceManager is the core DI container — extend config with modules, plugins, and middleware pipelines via config.php, config/autoload/*.php, and module.config.php.ServiceManager::build() to instantiate services without caching, or create() for one-off, non-cached objects.zendframework/zend-servicemanager; migrate to laminas/laminas-servicemanager to receive security and bug fixes. Update use statements and Composer constraints.CircularDependencyException by default. Use delegators, lazy loading (LazyServiceFactory), or refactor dependencies to resolve these silently or explicitly.ServiceManager. Understand AbstractPluginManager inheritance when extending plugin collections.services, factories, and aliases don’t unintentionally override or fragment definitions.ServiceManager::setAllowOverride(true) cautiously for runtime overrides during testing; use ServiceManager::getCreatedServices() and ServiceManager::getServiceNames() for introspection.setAutoAddMissingInvokableClasses() or via InvokableClassFactory, but use sparingly — explicit configuration improves testability and performance.How can I help you explore Laravel packages today?