gacela-project/resolver

This package is abandoned and no longer maintained. The author suggests using the gacela-project/container package instead.

A minimalistic container dependency resolver

Maintainers

Package info

github.com/gacela-project/container

Homepage

pkg:composer/gacela-project/resolver

Transparency log

Fund package maintenance!

chemaclass.com/sponsor

Statistics

Installs: 15 666

Dependents: 0

Suggesters: 0

Stars: 11

Open Issues: 0

2.0.2 2026-08-06 08:42 UTC

README

GitHub Build Status Latest Version PHP Version Require Psalm Type-coverage Status MIT Software License

A minimalistic, PSR-11 compliant dependency injection container with automatic constructor injection and zero configuration.

Features

  • ๐Ÿš€ Zero Configuration: Automatic constructor injection without verbose setup
  • ๐Ÿ”„ Circular Dependency Detection: Clear error messages when dependencies form a loop
  • ๐Ÿ“ฆ PSR-11 Compliant: Standard container interface for interoperability
  • โšก Performance Optimized: Warm resolution builds straight to new, plus warmup, a compiled cache that skips reflection, and one plan cache shared across sibling containers
  • ๐Ÿงฉ Fluent Registration: Register bindings after construction with bind(), singleton() and lazy()
  • ๐ŸŒฑ Scopes: Child containers that inherit registration without copying it, for per-request lifetimes
  • ๐ŸŽ Typed Resolution: make() returns a typed instance; getOrFail() never returns null
  • ๐Ÿงต Tags: Group services under a tag and resolve them lazily, as a list or as a keyed map
  • ๐Ÿงญ Contextual Bindings: when() scopes a dependency โ€” or a scalar โ€” to the classes that ask for it
  • ๐Ÿ“„ Definitions as Data: Ship and override wiring as arrays, PHP, JSON or YAML files with load()/loadFile()
  • ๐Ÿช Resolution Hooks: afterResolving() callbacks run once an id is built
  • ๐Ÿ” Introspection: Debug and inspect container state easily
  • ๐ŸŽฏ Type Safe: Requires type hints for reliable dependency resolution
  • ๐Ÿท๏ธ PHP 8 Attributes: Declarative configuration with #[Inject], #[Singleton], #[Factory] and #[Lazy] โ€” on parameters, properties and setters, and subclassable under your own namespace
  • โœ… Build-time Validation: validate() proves a set of classes resolves without resolving them, so broken wiring fails a deploy instead of a request
  • ๐Ÿ› ๏ธ A CLI: gacela-container compile|report|validate โ€” no console framework, psr/container stays the only runtime dependency
  • ๐ŸŽ€ Built to be Wrapped: withSelfReference() hands a decorator's facade to service closures, so composing over the final container costs one call

Installation

composer require gacela-project/container

Requires PHP >= 8.3.

Hello World

use Gacela\Container\Container;

class Greeter {
    public function __construct(private Clock $clock) {}

    public function greet(): string {
        return 'Hello World at ' . $this->clock->now();
    }
}

class Clock {
    public function now(): string {
        return date('H:i:s');
    }
}

// Zero configuration โ€” dependencies are auto-wired from type hints
$container = new Container();
$greeter = $container->make(Greeter::class);

echo $greeter->greet();

Need interfaces, singletons, attributes, or a compiled cache? See the docs below.

How it compares

Gacela Pimple Laravel PHP-DI Symfony
PSR-11 โœ… wrapper โœ… โœ… โœ…
Autowiring with zero config โœ… โŒ โœ… โœ… needs config
Framework-independent โœ… โœ… pulls illuminate/contracts โœ… โœ…
Lifetimes as attributes #[Singleton] #[Factory] #[Lazy] โŒ โŒ #[Inject] only #[Autoconfigure]
Property injection โœ… #[Inject] โŒ โŒ โœ… via config
Lazy services โœ… native lazy objects (PHP 8.4+), attribute or lazy(), no proxy class โŒ โŒ โœ… via proxy library โœ…
Compiled resolution โœ… plans + generated factories โŒ โŒ โœ… โœ…
Reflection shared across sibling containers โœ… PlanCache, in-process โŒ โŒ via APCu cache n/a โ€” dumped once
Child/scope containers โœ… inherits without copying โŒ โŒ โŒ โŒ
Contextual bindings โœ… โŒ โœ… definitions โœ…
Tags โœ… list or keyed map โŒ โœ… โŒ โœ…
Resolution hooks โœ… afterResolving() โŒ โœ… โŒ โŒ
Invoke any callable โœ… resolve() โŒ โœ… call() โœ… call() โŒ
Circular dependencies โœ… named exception + path โŒ โœ… โœ… โœ… at compile time
Introspection โœ… stats(), dependency tree, compileReport(), typo hints โŒ โŒ limited โœ… via console
Array access โœ… โœ… โœ… โŒ โŒ
Definitions as data โœ… arrays, PHP + JSON + YAML files โŒ โŒ โœ… โœ…
YAML definition files โœ… optional, via symfony/yaml โ€” never a hard dependency โŒ โŒ โœ… โœ…
XML definition files โŒ by design โ€” parse it and load() the array โŒ โŒ โŒ โœ…
Build-time validation โœ… validate(), gacela-container validate โŒ โŒ โŒ โœ… via compiler passes
Compiler passes / extensions โŒ by design โ€” packages expose definitions instead โŒ โŒ โŒ โœ…

Use this if you want Pimple's footprint with real autowiring, or Laravel's container API without Laravel โ€” plus lazy services, per-request scopes, and a compiled cache that skips reflection entirely.

Look elsewhere if you need XML definitions or compiler-pass style extension points. Both are deliberate boundaries rather than a backlog โ€” XML has no canonical mapping to a definition array short of inventing a schema (#139), and passes operate on a definition set an autowiring container mostly does not have (#140) โ€” the two things passes are actually reached for are covered instead: validate() gives the build-time feedback, and a package registers services by exposing definitions for load(). Each issue records the reasoning and what would change it. YAML is supported, as a suggest โ€” install symfony/yaml and loadFile() reads it; the runtime requirement is still psr/container alone.

Documentation

Guide What's inside
Getting Started Installation, basic usage, how resolution works
Bindings & Registration Constructor bindings, bind()/singleton(), contextual bindings, aliasing
Definitions as Data load()/loadFile(): wiring from arrays, PHP, JSON and YAML files
Resolving Services get(), make(), getOrFail(), resolve(), transient vs. shared
PHP 8 Attributes #[Inject], #[Singleton], #[Factory], #[Lazy]
Managing Services Factories, extending, protecting closures, introspection
Scopes Child containers: inherited registration, per-request lifetimes
Performance & Compilation warmUp(), compiled cache, generated factories, validate(), the CLI
Cookbook Recipes: testing, config, plugins, decorating, debugging
Error Handling Every exception, what causes it, how to fix it
Best Practices Recommended patterns
API Reference Full method, static, and attribute reference
Backward Compatibility What semver covers here, and what it does not
Upgrade Guide Migrating to 2.0, and 0.10.0 to 1.0.0

Real-World Example

See how it's used in the Gacela Framework.

Testing

composer test          # Run tests
composer quality       # Run static analysis
composer test-coverage # Generate coverage report

License

MIT License. See LICENSE file for details.