topthink/think-container
Think Container is a lightweight PSR-11 compatible dependency injection container from ThinkPHP. It supports binding, singleton instances, aliases, and constructor injection, giving PHP applications a simple, flexible IoC foundation for managing class dependencies.
Cache::get(), Db::table()) while making the underlying service swappable and mockable in tests. That is a roadmap-enabling move: it lets you schedule test coverage and dependency upgrades before a full rewrite, instead of blocking on one.Consider it when:
Look elsewhere when:
php-di/php-di, league/container, or Symfony's DI component. They have the interfaces, the docs, and the hiring pool.ContainerInterface of your own that this package satisfies today and a PSR-11 implementation can satisfy tomorrow.For executives: This is a small, permissively licensed (Apache-2.0), actively maintained component — the most recent release is within the current cycle — that provides dependency injection and a service-facade layer. It is not a strategic bet; it is a tactical dependency with a low integration cost, and that cost drops to near zero wherever we already run ThinkPHP. The business case is avoided engineering spend: we do not build or maintain a container, and we unlock test coverage and modular packaging earlier in the roadmap than a rewrite would allow. The honest risk is concentration: a single vendor, thin public community, limited independent security review. We mitigate by wrapping it behind our own interface so the underlying implementation is replaceable, and by keeping it off any path where a container vulnerability would be directly exploitable.
For engineering: It is a container plus a facade manager. Facades are the useful part — they let us keep existing static call sites while making the resolved service injectable and mockable, which is how we get tests onto legacy code without a big-bang refactor. The container handles lazy binding and construction ordering, so bootstrap code stays declarative. There are no meaningful runtime prerequisites beyond PHP, and the code surface is small enough to read in an afternoon, which matters more than the star count. Two constraints to design around: it is not a full PSR-11 implementation, so do not build a public extension API on the assumption that it is; and the feature set stops short of compiled containers, tagged services, and contextual binding — if a roadmap item needs those, the answer is Symfony or Laravel's container, not a fork. Standard practice: depend on an internal interface, not on the package's classes directly.
How can I help you explore Laravel packages today?