PHPackages                             krubio/perfect-container-psr-11 - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. krubio/perfect-container-psr-11

ActiveLibrary

krubio/perfect-container-psr-11
===============================

A PSR-11 dependency injection container with autowiring support

2.0.0(7mo ago)12501MITPHPPHP ^8.3CI passing

Since Sep 17Pushed 7mo ago1 watchersCompare

[ Source](https://github.com/benanamen/perfect-container-psr-11)[ Packagist](https://packagist.org/packages/krubio/perfect-container-psr-11)[ RSS](/packages/krubio-perfect-container-psr-11/feed)WikiDiscussions master Synced 1mo ago

READMEChangelog (2)Dependencies (4)Versions (3)Used By (1)

[![PHPStan](https://camo.githubusercontent.com/722de1d5a42bd7b0690e2dd7cf57984e352512dacc0e674932366f1ae2289b09/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f5048505374616e2d4c6576656c25323031302d627269676874677265656e2e737667)](https://camo.githubusercontent.com/722de1d5a42bd7b0690e2dd7cf57984e352512dacc0e674932366f1ae2289b09/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f5048505374616e2d4c6576656c25323031302d627269676874677265656e2e737667)[![PHPUnit](https://camo.githubusercontent.com/fb2ed4fdae2a0531899d3591acc4bfa15e87161a8cdc7e22cbd6a9e387d5b24c/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f504850556e69742d3130302532352d627269676874677265656e2e737667)](https://camo.githubusercontent.com/fb2ed4fdae2a0531899d3591acc4bfa15e87161a8cdc7e22cbd6a9e387d5b24c/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f504850556e69742d3130302532352d627269676874677265656e2e737667)[![PHP](https://camo.githubusercontent.com/89899a77bdce65fc4c3d3423dfacff9c6461066a0b5354dc18d7721c23ba596e/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f5048502d382e332532422d626c75652e737667)](https://camo.githubusercontent.com/89899a77bdce65fc4c3d3423dfacff9c6461066a0b5354dc18d7721c23ba596e/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f5048502d382e332532422d626c75652e737667)[![Dependencies](https://camo.githubusercontent.com/20f4b99a958aadb02ff273ac6428c17cf55c6b817657ed64b1c39c7f71955a0e/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f646570656e64656e636965732d302d627269676874677265656e2e737667)](https://camo.githubusercontent.com/20f4b99a958aadb02ff273ac6428c17cf55c6b817657ed64b1c39c7f71955a0e/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f646570656e64656e636965732d302d627269676874677265656e2e737667)

Quality Assurance
-----------------

[](#quality-assurance)

- ✅ **100% Test Coverage** with PHPUnit 12
- 📊 **PHPStan Level 10** - Maximum static analysis quality
- 🚀 **Zero Dependencies** - Pure PHP implementation
- 🎯 **PHP 8.3+** with strict types and modern features
- 🛡️ **Exception-Based Error Handling** for robust security

Features
--------

[](#features)

- **PSR-11 Compliant**: Full implementation of `Psr\Container\ContainerInterface`
- **Smart Autowiring**: Automatic reflection-based dependency resolution
- **Dual Mode Operation**: Toggle autowiring on/off via constructor parameter
- **Intelligent Resolution**: Class names automatically instantiated, other values returned as-is
- **Factory Support**: Closure factories for on-demand service creation
- **Interface Binding**: Simple interface-to-implementation mapping

---

Installation
------------

[](#installation)

```
  composer require perfectapp//perfect-container-psr-11
```

---

Usage
-----

[](#usage)

### Instantiation

[](#instantiation)

```
use PerfectApp\Container\Container;

// Autowiring enabled (default)
$container = new Container(true);

// Autowiring disabled (explicit registration only)
$container = new Container(false);
```

### Registering Dependencies

[](#registering-dependencies)

```
// Class name (automatically instantiated when retrieved)
$container->set(LoggerInterface::class, FileLogger::class);

// Ready-made instance
$container->set('database', new PDO('mysql:host=localhost;dbname=test', 'user', 'pass'));

// Closure factory
$container->set('config', function () {
    return [
        'database_host' => 'localhost',
        'database_name' => 'my_database'
    ];
});

// Simple value
$container->set('app.version', '1.0.0');
```

### Resolving Dependencies

[](#resolving-dependencies)

```
// Autowired resolution
$service = $container->get(UserService::class);

// Manual resolution
$version = $container->get('app.version');

// Check existence
if ($container->has(SomeClass::class)) {
    // Entry exists
}
```

#### Example

[](#example)

```
use PerfectApp\Container\Container;

interface Logger {
    public function log(string $message): void;
}

class FileLogger implements Logger {
    public function log(string $message): void {
        file_put_contents('log.txt', $message, FILE_APPEND);
    }
}

class UserService {
    public function __construct(private Logger $logger) {}

    public function createUser(string $username): void {
        $this->logger->log("User $username created");
    }
}

$container = new Container(true);
$container->set(Logger::class, FileLogger::class);

$userService = $container->get(UserService::class);
$userService->createUser('john@example.com');
```

Exception Handling
------------------

[](#exception-handling)

- NotFoundExceptionInterface: When a dependency cannot be found
- ContainerExceptionInterface: For errors during dependency resolution

---

Versioning
----------

[](#versioning)

This project follows Semantic Versioning. Current version: 2.0.0

---

License
-------

[](#license)

This library is open-sourced software licensed under the [MIT license](LICENSE).

###  Health Score

38

—

LowBetter than 85% of packages

Maintenance62

Regular maintenance activity

Popularity18

Limited adoption so far

Community9

Small or concentrated contributor base

Maturity51

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~2 days

Total

2

Last Release

235d ago

Major Versions

0.1.0-alpha → 2.0.02025-09-19

### Community

Maintainers

![](https://www.gravatar.com/avatar/92efcd3e8d87753dc819d970a254160b7ea8a60de6a127e7f93acada576b49c5?d=identicon)[benanamen](/maintainers/benanamen)

---

Top Contributors

[![benanamen](https://avatars.githubusercontent.com/u/1039435?v=4)](https://github.com/benanamen "benanamen (19 commits)")

###  Code Quality

TestsPHPUnit

Static AnalysisPHPStan

Code StylePHP CS Fixer

Type Coverage Yes

### Embed Badge

![Health badge](/badges/krubio-perfect-container-psr-11/health.svg)

```
[![Health](https://phpackages.com/badges/krubio-perfect-container-psr-11/health.svg)](https://phpackages.com/packages/krubio-perfect-container-psr-11)
```

###  Alternatives

[pimple/pimple

Pimple, a simple Dependency Injection Container

2.7k130.5M1.4k](/packages/pimple-pimple)[neos/flow

Flow Application Framework

862.0M451](/packages/neos-flow)[api-platform/state

API Platform state interfaces

223.4M57](/packages/api-platform-state)[internal/dload

Downloads binaries.

98142.7k10](/packages/internal-dload)[symfony/json-streamer

Provides powerful methods to read/write data structures from/into JSON streams.

14440.0k8](/packages/symfony-json-streamer)[rubix/server

Deploy your Rubix ML models to production with scalable stand-alone inference servers.

632.3k](/packages/rubix-server)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
