First-class Dependency Injection container with zero-config autowiring for the Quill PHP Framework.
This container implements PSR-11 and provides a fast, reflection-based autowiring mechanism that eliminates the need for manual service configuration in most cases.
composer require quillphp/container- PSR-11 Compliant: Seamless integration with any PSR-11 compatible library.
- Recursive Autowiring: Automatically resolves and injects constructor dependencies.
- Singletons: High-performance instance caching for shared services.
- Interface Decoupling: Bind abstract interfaces to concrete implementations.
- Circular Detection: Fail fast with clear error messages when circular dependencies occur.
Simply request a class, and the container will instantiate it and all its dependencies:
use Quill\Container\Container;
class Mailer {}
class UserController {
public function __construct(private Mailer $mailer) {}
}
$container = new Container();
$controller = $container->get(UserController::class); // Works out-of-the-box!Register a service that should only be instantiated once:
$container->singleton(Database::class, function($c) {
return new Database(getenv('DB_URL'));
});Tell the container which concrete class to use for an interface:
$container->bind(UserRepositoryInterface::class, SqliteUserRepository::class);Quill automatically uses this container for resolving handlers:
$app = new \Quill\App();
$app->singleton(MyService::class);
$app->get('/users', function(MyService $service) {
// service is already resolved and injected!
});This package is open-sourced software licensed under the MIT license.