laminas-servicemanager

A fast, factory-driven, PSR-11 compatible dependency injection container for PHP applications.

Library
Composer
v4.5.1
159stars
BSD 3-Clause License

Repository Health

Pre-computed score based on development activity, maintenance, community, maturity, and trend momentum.How we score it →
61/100Good
Development Activity36
Maintenance44
Community84
Maturity60
Momentum20

Technical Analysis

AI-assessed by reading the actual repository — architecture, code quality, innovation, and documentation.How we score it →
72/100Good
Architecture78
Code Quality82
Innovation60
Learning Curve68

laminas-servicemanager implements the Service Locator pattern as a PSR-11 compliant dependency injection container. Services are registered as factories, invokables, aliases, or delegators, and the container lazily instantiates and caches them on first request, giving applications a single, explicit source of truth for how objects are wired together.

With over 1.2 million monthly downloads and nearly 8,000 commits from 213 contributors, it is one of the most mature DI containers in the PHP ecosystem and forms the backbone of Mezzio and other Laminas-based applications, while remaining fully usable standalone in any PSR-11-compatible codebase.

What You Get

  • A PSR-11 compliant ServiceManager container supporting get()/has() lookups
  • Factory-based service registration for explicit, testable object construction
  • Invokable and alias registration for simple class-to-service mappings
  • Delegator factories for wrapping or decorating existing service instances
  • Lazy service support and abstract factories for dynamic, pattern-based service resolution

Common Use Cases

  • Wiring the object graph of a Mezzio or Laminas MVC application from configuration arrays
  • Decoupling class construction from usage to make components easier to unit test
  • Registering third-party service factories (loggers, DB connections, HTTP clients) once and reusing them app-wide
  • Applying cross-cutting decorators (caching, logging) to services via delegator factories without touching consumer code

Under The Hood

Architecture - The core ServiceManager class holds internal maps of factories, aliases, invokables, and delegators, resolving a requested service name through alias resolution, then factory invocation (with results cached for subsequent get() calls), optionally passing the result through a chain of delegator factories. This factory-first design keeps object construction explicit and traceable rather than relying on reflection-based autowiring, which is a deliberate trade-off favoring predictability and performance over magic.

Tech Stack - Pure PHP implementing psr/container (PSR-11), distributed via Composer with PSR-4 autoloading under Laminas\ServiceManager. It includes a benchmarks/ suite built on PHPBench for tracking container performance across releases, and CI runs via GitHub Actions with Psalm static analysis tracked on Shepherd.

Code Quality - With nearly 8,000 commits and 213 contributors across 47 tagged releases, this is a heavily exercised, long-lived component. It maintains a comprehensive PHPUnit suite plus dedicated performance benchmarks, reflecting an unusual (for a DI container) emphasis on measuring and preventing performance regressions release over release.

API Design - The public API centers on get(string $name) and has(string $name) per PSR-11, with configuration-time registration via a config array of factories, aliases, invokables, and delegators keys. This configuration-array pattern is consistent with the rest of the Laminas ecosystem, so once a developer learns the pattern from one Laminas component, it transfers directly to service registration.

Join founders buildingwith open source

Opinionated takes, migration guides, cost-saving tips, and insights from the open source ecosystem.

Subscribe on Substack
Join 750+ subscribers

Search