Weave Code
Code Weaver
Helps Laravel developers discover, compare, and choose open-source packages. See popularity, security, maintainers, and scores at a glance to make better decisions.
Feedback
Share your thoughts, report bugs, or suggest improvements.
Subject
Message

Zend Servicemanager Laravel Package

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.

View on GitHub
Deep Wiki
Context7

Getting Started

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:

  • Replace the package with laminas/laminas-servicemanager via Composer (composer require laminas/laminas-servicemanager).
  • Create a basic configuration array mapping interface-to-concrete class or factory class names.
  • Instantiate the 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);

Implementation Patterns

  • Factory Pattern: Use factories (implementing FactoryInterface or implementing __invoke(ContainerInterface $container, $requestedName, ?array $options = null)) for complex instantiation logic or when dependencies need injection via the container.
  • Delegator Factories: Chain service creation with cross-cutting concerns (e.g., caching, logging, middleware wrapping) via delegators — especially useful in middleware pipelines or service proxies.
  • Service Aliasing: Register aliases for backward compatibility or interface-to-implementation mapping ('aliases' => [ServiceInterface::class => ConcreteServiceImpl::class]).
  • Service Manager in Frameworks: In Laminas MVC or Mezzio (formerly Expressive), the ServiceManager is the core DI container — extend config with modules, plugins, and middleware pipelines via config.php, config/autoload/*.php, and module.config.php.
  • Lazy Loading: Use ServiceManager::build() to instantiate services without caching, or create() for one-off, non-cached objects.

Gotchas and Tips

  • Archived Status: Avoid new adoption of zendframework/zend-servicemanager; migrate to laminas/laminas-servicemanager to receive security and bug fixes. Update use statements and Composer constraints.
  • Circular Dependencies: The container throws CircularDependencyException by default. Use delegators, lazy loading (LazyServiceFactory), or refactor dependencies to resolve these silently or explicitly.
  • Plugin Manager Integration: Many Laminas components (e.g., View Helpers, Input Filters, Validators) rely on plugin managers extending ServiceManager. Understand AbstractPluginManager inheritance when extending plugin collections.
  • Configuration Merging: When using modules, config is merged recursively — ensure keys like services, factories, and aliases don’t unintentionally override or fragment definitions.
  • Debugging: Enable ServiceManager::setAllowOverride(true) cautiously for runtime overrides during testing; use ServiceManager::getCreatedServices() and ServiceManager::getServiceNames() for introspection.
  • Auto-wiring Support: While auto-wiring (resolving via reflection) is not default, it can be enabled with setAutoAddMissingInvokableClasses() or via InvokableClassFactory, but use sparingly — explicit configuration improves testability and performance.
Weaver

How can I help you explore Laravel packages today?

Conversation history is not saved when not logged in.
Prompt
Add packages to context
No packages found.
davejamesmiller/laravel-breadcrumbs
artisanry/parsedown
christhompsontldr/phpsdk
enqueue/dsn
bunny/bunny
enqueue/test
enqueue/null
enqueue/amqp-tools
milesj/emojibase
bower-asset/punycode
bower-asset/inputmask
bower-asset/jquery
bower-asset/yii2-pjax
laravel/nova
spatie/laravel-mailcoach
spatie/laravel-superseeder
laravel/liferaft
nst/json-test-suite
danielmiessler/sec-lists
jackalope/jackalope-transport