PHPackages                             borschphp/container - 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. [PSR &amp; Standards](/categories/psr-standards)
4. /
5. borschphp/container

ActiveLibrary[PSR &amp; Standards](/categories/psr-standards)

borschphp/container
===================

A simple PSR-11 Container implementation.

2.0.0(9mo ago)01.1k↓100%2MITPHPPHP ^8.2CI passing

Since May 20Pushed 7mo agoCompare

[ Source](https://github.com/borschphp/borsch-container)[ Packagist](https://packagist.org/packages/borschphp/container)[ RSS](/packages/borschphp-container/feed)WikiDiscussions master Synced 1mo ago

READMEChangelog (10)Dependencies (4)Versions (17)Used By (2)

Borsch Container
================

[](#borsch-container)

[![Build](https://github.com/borschphp/borsch-container/actions/workflows/php.yml/badge.svg)](https://github.com/borschphp/borsch-container/actions/workflows/php.yml)[![Latest Stable Version](https://camo.githubusercontent.com/971908efb8b0a328fd30509d84841b3dc176b5b0007777df7a649ba3cd3cb0d3/68747470733a2f2f706f7365722e707567782e6f72672f626f727363687068702f636f6e7461696e65722f76)](//packagist.org/packages/borschphp/container)[![License](https://camo.githubusercontent.com/6bc22cc5ddcd9d6c1e16e2f216661cf27a7ef211a6faff9f07e2f109b835c739/68747470733a2f2f706f7365722e707567782e6f72672f626f727363687068702f636f6e7461696e65722f6c6963656e7365)](//packagist.org/packages/borschphp/container)

A lightweight and easy-to-use PSR-11 container for your web projects.

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

[](#installation)

Via [composer](https://getcomposer.org/) :

```
composer require borschphp/container
```

Usage
-----

[](#usage)

```
use Borsch\Container\Container;

$container = new Container();

// Add your dependencies
$container->set('db', fn() => new PDO('mysql:host=localhost;dbname=mydb', 'user', 'password'));

// Retrieve your dependencies
$db = $container->get('db');
```

### Parameterized Dependencies

[](#parameterized-dependencies)

In this example, we're defining a PDO service within an entry `db`.

Then we set the values of the parameters in the same order as the constructor :
`PDO::__construct(string $dsn, ?string $username = null, ?string $password = null, ?array $options = null)`) :

Finally we retrieve the PDO service.

```
use Borsch\Container\Container;

$container = new Container();

$container
    ->set('db', PDO::class)
    ->addParameter('mysql:host=localhost;dbname=mydb')
    ->addParameter('user')
    ->addParameter('password');

$db = $container->get('db');
```

### Shared and Unshared Dependencies

[](#shared-and-unshared-dependencies)

In this example, we're defining a logger service which is shared by default.
We're retrieving the logger service twice, so we can see that the two instances are identical.

```
use Borsch\Container\Container;

$container = new Container();

$container
    ->set('logger', fn() => new Logger())
    ->cache(true);

$logger1 = $container->get('logger');
$logger2 = $container->get('logger');

// $logger1 and $logger2 are the same instances
```

### Auto-wiring by default

[](#auto-wiring-by-default)

In this example we create a custom class that requires a `Logger` instance to be instantiated :

```
class MyApp
{
    public function __construct(
        protected Logger $logger
    ) {}
}
```

We create an entry in the Container with `Logger::class` and use a closure to instantiate it.
We create an entry in the Container with `MyApp::class`; as we did not provide a second parameter, the container will do its best to fetch required parameters (here, a `Logger`) from the environment.

```
use Borsch\Container\Container;

$container = new Container();

$container->set(Logger::class, function () {
    $logger = new Logger('app');
    $logger->pushHandler(new StreamHandler('path/to/log/file.log'));

    return $logger;
})-> cache(true);

$container->set(MyApp::class);

$app = $container->get(MyApp::class);

// $app is instantiated with the logger from entry Logger::class
```

### Use the container to get dependencies in a definition

[](#use-the-container-to-get-dependencies-in-a-definition)

Let say we have a `PDO::class` defined in our container and would like to use it in a Symfony `CacheInterface`using PdoAdapter.
We can simply get the `PDO::class` instance we defined by requesting it in the function parameters.

```
use Borsch\Container\Container;

$container = new Container();
$container->set(PDO::class, function () {
    $pdo = new PDO('sqlite:/path/to/my/database.sqlite');
    $pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
    $pdo->setAttribute(PDO::ATTR_DEFAULT_FETCH_MODE, PDO::FETCH_ASSOC);
    $pdo->setAttribute(PDO::ATTR_EMULATE_PREPARES, false);

    return $pdo;
})->cache(true);

$container->set(
    CacheInterface::class,
    // PDO instance defined upper will be injected here as parameter
    fn(PDO $pdo) => new PdoAdapter($pdo)
)->cache(true);
```

License
-------

[](#license)

The package is licensed under the MIT license. See [License File](https://github.com/borschphp/borsch-container/blob/master/LICENSE.md) for more information.

###  Health Score

45

—

FairBetter than 92% of packages

Maintenance64

Regular maintenance activity

Popularity17

Limited adoption so far

Community10

Small or concentrated contributor base

Maturity76

Established project with proven stability

 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 ~158 days

Recently: every ~233 days

Total

13

Last Release

282d ago

Major Versions

0.4.3 → 1.0.02022-07-01

1.1.2 → v2.x-dev2025-07-31

PHP version history (5 changes)0.1PHP ^7.3

0.2PHP ^7.2

0.4.3PHP ^7.2|^8.0

1.0.0PHP ^8.0

v2.x-devPHP ^8.2

### Community

Maintainers

![](https://www.gravatar.com/avatar/0e1a70117520fe10a630d61c750bbe6888d174e9903825e741470f818ee2c5d1?d=identicon)[debuss-a](/maintainers/debuss-a)

---

Top Contributors

[![debuss](https://avatars.githubusercontent.com/u/2537607?v=4)](https://github.com/debuss "debuss (29 commits)")

---

Tags

psrcontainerPSR-11

###  Code Quality

TestsPest

Static AnalysisPHPStan

Type Coverage Yes

### Embed Badge

![Health badge](/badges/borschphp-container/health.svg)

```
[![Health](https://phpackages.com/badges/borschphp-container/health.svg)](https://phpackages.com/packages/borschphp-container)
```

###  Alternatives

[psr/container

Common Container Interface (PHP FIG PSR-11)

10.0k1.0B3.7k](/packages/psr-container)[php-di/php-di

The dependency injection container for humans

2.8k48.9M987](/packages/php-di-php-di)

PHPackages © 2026

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