Skip to content

quillphp/quill-container

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Quill DI Container

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.

Installation

composer require quillphp/container

Features

  • 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.

Usage

Basic Autowiring

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!

Manual Bindings

Singletons

Register a service that should only be instantiated once:

$container->singleton(Database::class, function($c) {
    return new Database(getenv('DB_URL'));
});

Interface Implementation

Tell the container which concrete class to use for an interface:

$container->bind(UserRepositoryInterface::class, SqliteUserRepository::class);

Integration with Quill App

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!
});

License

This package is open-sourced software licensed under the MIT license.

About

First-class Dependency Injection container with zero-config autowiring for the Quill PHP Framework.

Topics

Resources

License

Stars

Watchers

Forks

Packages

 
 
 

Contributors

Languages