PHPackages                             sergix44/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. [Utility &amp; Helpers](/categories/utility)
4. /
5. sergix44/container

ActiveLibrary[Utility &amp; Helpers](/categories/utility)

sergix44/container
==================

A simple and fast service container

3.1.0(1y ago)5191.3k—4%[1 issues](https://github.com/SergiX44/container/issues)1MITPHPPHP ^8.1

Since Jun 27Pushed 1y ago2 watchersCompare

[ Source](https://github.com/SergiX44/container)[ Packagist](https://packagist.org/packages/sergix44/container)[ GitHub Sponsors](https://github.com/SergiX44)[ RSS](/packages/sergix44-container/feed)WikiDiscussions main Synced 1mo ago

READMEChangelog (5)Dependencies (4)Versions (6)Used By (1)

XContainer
==========

[](#xcontainer)

A simple, fast and PSR-11 compliant service container.

Perfect for libraries that benefit from dependency injection, which integrate with other frameworks, thanks to the delegation feature.

🚀 Installation
--------------

[](#-installation)

```
composer require sergix44/container
```

🔧 Usage
-------

[](#-usage)

Register a definition:

```
$container = new \SergiX44\Container\Container();

$container->bind(ServiceInterface::class, MyService::class);

$instance = $container->get(ClassThatUseMyService::class);
```

Register a shared definition (first resolution will be cached, and the same instance will be returned)

```
$container = new \SergiX44\Container\Container();

$container->singleton(ServiceInterface::class, MyService::class);

$instance = $container->get(ClassThatUseMyService::class);
```

You can define factories as closures:

```
$container = new \SergiX44\Container\Container();

$value = 'dynamic';

// factory
$container->bind(ServiceInterface::class, function (\Psr\Container\ContainerInterface $container) use ($value) {
    return new MyService($container->get(AnotherService::class), $value);
});

// shared/singleton
$container->singleton(FooServiceInterface::class, function (\Psr\Container\ContainerInterface $container) {
    return new FooService($container->get(ServiceInterface::class));
});

$instance = $container->get(ClassThatUseMyService::class);
```

You can set an already resolved instance:

```
$container = new \SergiX44\Container\Container();

$service = new MyService();

$container->set(ServiceInterface::class, $service);

// or even as string:
// $container->set('service', $service);
// $service = $container->get('service');

$instance = $container->get(ClassThatUseMyService::class);
```

It can be also used to inject parameters inside any callable:

```
// InvokableClass.php
class InvokableClass {
    public function __invoke(ServiceInterface $service)
    {
        //
    }
}
// ClassAndMethod.php
class ClassAndMethod {
    public function method(ServiceInterface $service)
    {
        //
    }
}

// --

$container = new \SergiX44\Container\Container();

$container->bind(ServiceInterface::class, MyService::class);

$result = $container->call(InvokableClass::class); // calls __invoke
$result = $container->call(new InvokableClass()); // calls __invoke
$result = $container->call([ClassAndMethod::class, 'method']); // calls method
$result = $container->call([new ClassAndMethod(), 'method']); // calls method
$result = $container->call(function (ServiceInterface $service) {
    //
});
```

It's also possible to pass arbitrary parameters with an associative array:

```
// InvokableClass.php
class InvokableClass {
    public function __invoke(ServiceInterface $service, string $a, int $b)
    {
        //
    }
}

$container = new \SergiX44\Container\Container();

// map parameter name => value
$result = $container->call(InvokableClass::class, ['a' => 'foo', 'b' => 123]);

// positional
$result = $container->call(InvokableClass::class, ['foo', 123]);
```

It's also possible to mix positional and associative notation:

```
// InvokableClass.php
class InvokableClass {
    public function __invoke(ServiceInterface $service, string $a, int $b)
    {
        // same result: b=456 and a=foo
    }
}

$container = new \SergiX44\Container\Container();

$result = $container->call(InvokableClass::class, ['b' => 456, 'foo']);
```

⚗️ Testing
----------

[](#️-testing)

To run the test suite:

```
vendor/bin/pest
```

🏅 Credits
---------

[](#-credits)

- [Sergio Brighenti](https://github.com/SergiX44)
- [All Contributors](../../contributors)

📖 License
---------

[](#-license)

The MIT License (MIT). Please see [License File](LICENSE.md) for more information.

###  Health Score

38

—

LowBetter than 85% of packages

Maintenance32

Infrequent updates — may be unmaintained

Popularity39

Limited adoption so far

Community10

Small or concentrated contributor base

Maturity56

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

Total

5

Last Release

699d ago

Major Versions

1.0.0 → 2.0.02023-07-02

2.1.0 → 3.0.02024-06-01

### Community

Maintainers

![](https://www.gravatar.com/avatar/08bc14acf1f7db717de09e715047f5b5684841d6b9712129334931fa8833beda?d=identicon)[SergiX44](/maintainers/SergiX44)

---

Top Contributors

[![sergix44](https://avatars.githubusercontent.com/u/4172890?v=4)](https://github.com/sergix44 "sergix44 (48 commits)")

---

Tags

containerdependency-injectionioc-containerphppsr-11service-container

###  Code Quality

TestsPest

Static AnalysisPsalm

Type Coverage Yes

### Embed Badge

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

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

###  Alternatives

[symfony/dependency-injection

Allows you to standardize and centralize the way objects are constructed in your application

4.2k431.1M7.5k](/packages/symfony-dependency-injection)[illuminate/contracts

The Illuminate Contracts package.

705122.9M10.1k](/packages/illuminate-contracts)[illuminate/container

The Illuminate Container package.

31178.1M2.0k](/packages/illuminate-container)[ecotone/ecotone

Supporting you in building DDD, CQRS, Event Sourcing applications with ease.

558549.8k17](/packages/ecotone-ecotone)[civicrm/civicrm-core

Open source constituent relationship management for non-profits, NGOs and advocacy organizations.

728272.9k20](/packages/civicrm-civicrm-core)[internal/dload

Downloads binaries.

98142.7k10](/packages/internal-dload)

PHPackages © 2026

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