PHPackages                             chevere/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. chevere/container

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

chevere/container
=================

A chevere container package

1.0.1(2mo ago)0924↑200%[1 issues](https://github.com/chevere/container/issues)1Apache-2.0PHPCI passing

Since Feb 21Pushed 2mo agoCompare

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

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

Container
=========

[](#container)

[![Chevere](chevere.svg)](chevere.svg)

[![Build](https://camo.githubusercontent.com/e1279ebe1b85476243d30d347df90f0c6962536f6a57055647fe370ba5e01ba4/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f616374696f6e732f776f726b666c6f772f7374617475732f636865766572652f636f6e7461696e65722f746573742e796d6c3f6272616e63683d312e30267374796c653d666c61742d737175617265)](https://github.com/chevere/container/actions)[![Code size](https://camo.githubusercontent.com/8de18e7188929495d3093f194a4554c747a17f16ff16f6926ee68353cecf3313/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f6c616e6775616765732f636f64652d73697a652f636865766572652f636f6e7461696e65723f7374796c653d666c61742d737175617265)](https://camo.githubusercontent.com/8de18e7188929495d3093f194a4554c747a17f16ff16f6926ee68353cecf3313/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f6c616e6775616765732f636f64652d73697a652f636865766572652f636f6e7461696e65723f7374796c653d666c61742d737175617265)[![Apache-2.0](https://camo.githubusercontent.com/9fc30aafbc95aaca16a94193a2978848678b256a4bd253cd29ecea84c84b786f/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f6c6963656e73652f636865766572652f636f6e7461696e65723f7374796c653d666c61742d737175617265)](LICENSE)[![PHPStan](https://camo.githubusercontent.com/6016298b28550819030c76e9327f62501596a31fd76406695bae2f3d2a1f26a4/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f5048505374616e2d6c6576656c253230392d626c756576696f6c65743f7374796c653d666c61742d737175617265)](https://phpstan.org/)[![Mutation testing badge](https://camo.githubusercontent.com/01fd074a9cddec70ff55f43d1371a0812ffd2afc0f9353af8b2f5e9a6a9bb1f6/68747470733a2f2f696d672e736869656c64732e696f2f656e64706f696e743f7374796c653d666c61742d7371756172652675726c3d687474707325334125324625324662616467652d6170692e737472796b65722d6d757461746f722e696f2532466769746875622e636f6d25324663686576657265253246636f6e7461696e6572253246312e30)](https://dashboard.stryker-mutator.io/reports/github.com/chevere/container/1.0)

[![Quality Gate Status](https://camo.githubusercontent.com/514c2725f47cecc246212ad5bc99d4f65e252335824f315e46b8c327a5bdc417/68747470733a2f2f736f6e6172636c6f75642e696f2f6170692f70726f6a6563745f6261646765732f6d6561737572653f70726f6a6563743d636865766572655f636f6e7461696e6572266d65747269633d616c6572745f737461747573)](https://sonarcloud.io/dashboard?id=chevere_container)[![Maintainability Rating](https://camo.githubusercontent.com/c3c52becfed228b2e05ce1e7471b7bf55d23fb0c22ae69b7a88f9bd913155054/68747470733a2f2f736f6e6172636c6f75642e696f2f6170692f70726f6a6563745f6261646765732f6d6561737572653f70726f6a6563743d636865766572655f636f6e7461696e6572266d65747269633d7371616c655f726174696e67)](https://sonarcloud.io/dashboard?id=chevere_container)[![Reliability Rating](https://camo.githubusercontent.com/9b57b5db530e99ee1643bda1aaae17a0ed266598e7b7b77561bd7a00fbd70c4f/68747470733a2f2f736f6e6172636c6f75642e696f2f6170692f70726f6a6563745f6261646765732f6d6561737572653f70726f6a6563743d636865766572655f636f6e7461696e6572266d65747269633d72656c696162696c6974795f726174696e67)](https://sonarcloud.io/dashboard?id=chevere_container)[![Security Rating](https://camo.githubusercontent.com/a9645885a99d1b8c98eb41f5fa9b05f2fc349a458f28ac4e6ab1d9e5237903f6/68747470733a2f2f736f6e6172636c6f75642e696f2f6170692f70726f6a6563745f6261646765732f6d6561737572653f70726f6a6563743d636865766572655f636f6e7461696e6572266d65747269633d73656375726974795f726174696e67)](https://sonarcloud.io/dashboard?id=chevere_container)[![Coverage](https://camo.githubusercontent.com/75545af03fc34746672708af9403114ec8ff2e2fdbe9b42579372fd99c247dbb/68747470733a2f2f736f6e6172636c6f75642e696f2f6170692f70726f6a6563745f6261646765732f6d6561737572653f70726f6a6563743d636865766572655f636f6e7461696e6572266d65747269633d636f766572616765)](https://sonarcloud.io/dashboard?id=chevere_container)[![Technical Debt](https://camo.githubusercontent.com/dac8fd04846d186964730619bb5491ff0cc346e4c964461a2b247b90281d601b/68747470733a2f2f736f6e6172636c6f75642e696f2f6170692f70726f6a6563745f6261646765732f6d6561737572653f70726f6a6563743d636865766572655f636f6e7461696e6572266d65747269633d7371616c655f696e646578)](https://sonarcloud.io/dashboard?id=chevere_container)[![CodeFactor](https://camo.githubusercontent.com/f0f98f22d4ac2becc31bba89ac36716279c9dbeef3007b17a0a877b55a4072ae/68747470733a2f2f7777772e636f6465666163746f722e696f2f7265706f7369746f72792f6769746875622f636865766572652f636f6e7461696e65722f6261646765)](https://www.codefactor.io/repository/github/chevere/container)

Summary
-------

[](#summary)

**Chevere Container** is a minimalist PSR-11 dependency injection container. It provides `get` and `has` for service container-interop, along with immutable `with` and `without` methods for modifying container entries.

It features automatic dependency resolution and injection. The container can automatically instantiate and inject class dependencies based on their constructor type hints. It also provides a `Dependencies` utility to collect, validate, and manage dependencies from multiple classes, ensuring type compatibility across the dependency graph.

Installing
----------

[](#installing)

Container is available through [Packagist](https://packagist.org/packages/chevere/container) and the repository source is at [chevere/container](https://github.com/chevere/container).

```
composer require chevere/container
```

Container usage
---------------

[](#container-usage)

Create a Container by passing the known dependencies.

```
use Chevere\Container\Container;

$container = new Container(
    database: $database,
    cipher: $cipher,
    //...
);
```

### Checking entries

[](#checking-entries)

Use `has` to check if an entry exists in the container.

```
$container->has('database'); // true
$container->has('logger'); // false
```

### Retrieving entries

[](#retrieving-entries)

Use `get` to retrieve an entry from the container. It will throw `ContainerNotFoundException` if the entry is not found.

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

### Adding entries

[](#adding-entries)

Use `with` to add or replace entries in the container.

```
$newContainer = $container->with(logger: $logger);
```

### Removing entries

[](#removing-entries)

Use `without` to remove entries from the container.

```
$newContainer = $container->without('cipher');
```

Auto-injection
--------------

[](#auto-injection)

The container can automatically resolve and inject dependencies.

### Resolving dependencies

[](#resolving-dependencies)

Use `withAutoInject` to get a new container instance with resolved dependencies.

```
$containerWithServices = $container->withAutoInject($dependencies);
```

This will automatically create instances for services like `MyController` and `MyMiddleware` if they are not already in the container, resolving their own dependencies recursively.

### Extracting arguments

[](#extracting-arguments)

Use `extract` to get the constructor arguments for a class from the container.

```
$arguments = $containerWithServices->extract(MyController::class);
$controller = new MyController(...$arguments);
```

Dependencies
------------

[](#dependencies)

The `Dependencies` class is used to collect constructor dependencies from multiple classes. It helps to identify required services and validates against type compatibility.

```
use Chevere\Container\Dependencies;

$dependencies = new Dependencies(
    MyController::class,
    MyMiddleware::class,
);
```

### Reading classes

[](#reading-classes)

Use `classes` to get a list of component classes in the collection.

```
$classNames = $dependencies->classes();
```

### Adding more dependencies

[](#adding-more-dependencies)

Use `withClass` to add more class dependencies to the collection. Returns a new instance with the specified classes added.

```
$newDependencies = $dependencies->withClass(
    AnotherController::class,
    AnotherMiddleware::class,
);
```

### Accessing parameters

[](#accessing-parameters)

Use `parameters` to get a ParametersInterface instance reflecting all dependencies as [Parameters](https://chevere.org/packages/parameter).

```
$parameters = $dependencies->parameters();
```

### Checking class dependencies

[](#checking-class-dependencies)

Use `has` to check if a specific class name defines dependencies.

```
$dependencies->has(MyController::class); // true
$dependencies->has(UnknownClass::class); // false
```

### Retrieving class parameters

[](#retrieving-class-parameters)

Use `get` to retrieve the parameters (dependencies) for a known class name.

```
$controllerParams = $dependencies->get(MyController::class);
```

### Extracting constructor arguments

[](#extracting-constructor-arguments)

Use `extract` to get the typed constructor arguments for a class from a container.

```
$arguments = $dependencies->extract(MyController::class, $container);
$controller = new MyController(...$arguments);
```

### Identifying dependency requirer

[](#identifying-dependency-requirer)

Use `requirer` to identify which class declared a specific dependency.

```
$className = $dependencies->requirer('database');
```

### Validating container dependencies

[](#validating-container-dependencies)

Use `assert` to check if a container has all the required dependencies. It will throw a `LogicException` if any dependency is missing or if there's a type mismatch.

```
$dependencies->assert($container);
```

Documentation
-------------

[](#documentation)

Documentation is available at [chevere.org](https://chevere.org/packages/container).

License
-------

[](#license)

Copyright [Rodolfo Berrios A.](https://rodolfoberrios.com/)

Chevere is licensed under the Apache License, Version 2.0. See [LICENSE](LICENSE) for the full license text.

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

###  Health Score

40

—

FairBetter than 88% of packages

Maintenance86

Actively maintained with recent releases

Popularity20

Limited adoption so far

Community10

Small or concentrated contributor base

Maturity35

Early-stage or recently created project

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

Total

3

Last Release

69d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/a87fbbcb1518fe64878bc53dedd9f61b81243cbb21b73c26f5e299d501375984?d=identicon)[rodolfo](/maintainers/rodolfo)

---

Top Contributors

[![rodber](https://avatars.githubusercontent.com/u/20590102?v=4)](https://github.com/rodber "rodber (16 commits)")

###  Code Quality

TestsPHPUnit

Static AnalysisPHPStan

Code StyleECS

Type Coverage Yes

### Embed Badge

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

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

###  Alternatives

[illuminate/contracts

The Illuminate Contracts package.

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

The Illuminate Container package.

31178.1M2.0k](/packages/illuminate-container)[symfony/type-info

Extracts PHP types information.

19951.9M114](/packages/symfony-type-info)[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)
