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

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

zalevsk1y/container-builder
===========================

Container Builder, provides a simple implementation of a Dependency Injection Container. It allows for easy management of object instances and their dependencies, allowing for more flexible and maintainable code. The module includes methods for adding definition files, retrieving instances, and calling methods on instances with specified arguments. This can help improve code organization and reduce coupling between classes, leading to a more robust and scalable application.

v1.0.5(1y ago)2161MITPHPPHP &gt;=7.4

Since Feb 14Pushed 1y ago2 watchersCompare

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

READMEChangelog (5)Dependencies (1)Versions (7)Used By (0)

ContainerBuilder
================

[](#containerbuilder)

Introduction
------------

[](#introduction)

The ContainerBuilder is a Dependency Injection (DI) tool that allows you to handle dependencies and create instances of classes with their dependencies. The tool provides an implementation of the Container Interface, providing a simple and effective way to manage dependencies and resolve them.

Every class that is created using the definition file or the set method is saved in the container and will be returned by the get method as a singleton instance. This means that subsequent calls to get the same class will return the previously created instance.

New Feature: Manual Object Addition
-----------------------------------

[](#new-feature-manual-object-addition)

Now, you can manually add objects to the DI container using the set method. This allows you to set a specific instance of a class, providing more control over the objects stored in the container.

```
use ContainerBuilder\DI;

$container = new DI();
$container->addDefinitions(__DIR__ . '/config.php');

$instance = $container->set(new ClassName($some_deps));
$instance = $container->get(ClassName::class);

```

API
---

[](#api)

The API of the ContainerBuilder is simple and straightforward, allowing you to:

- Add definitions using the addDefinitions method
- Get an instance of a class using the get method
- Call a method of an instance using the call method
- Set a specific instance of a class using the set method

Configuration File Format
-------------------------

[](#configuration-file-format)

The configuration file is an array of definitions where each key represents a class and its value is an array of dependencies. The format of the configuration file is as follows:

```
return array(
    ClassName1::class=>[Dependency1, Dependency2, ...],
    ClassName2::class=>[Dependency3, Dependency4, ...],
    ...
)

```

Here, ClassName1 and ClassName2 are classes that have dependencies Dependency1, Dependency2, Dependency3, and Dependency4, respectively.

Example
-------

[](#example)

Here is an example of how you can use the ContainerBuilder:

```
use ContainerBuilder\DI;

$container = new DI();
$container->addDefinitions(__DIR__ . '/config.php');

$instance = $container->get(ClassName::class);
$result = $container->call([$instance, 'methodName'], [$arg1, $arg2, ...]);

```

In this example, config.php is the configuration file that contains the definitions of the classes and their dependencies. The addDefinitions method is used to load the definitions, and the get method is used to get an instance of the ClassName class. The call method is used to call the methodName method of the ClassName instance and pass the arguments $arg1, $arg2, etc.

Thank you 🙏 for support - [Atlant Web Agency](https://www.atlant-web.com/).

###  Health Score

28

—

LowBetter than 54% of packages

Maintenance33

Infrequent updates — may be unmaintained

Popularity13

Limited adoption so far

Community8

Small or concentrated contributor base

Maturity49

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

Recently: every ~62 days

Total

6

Last Release

703d ago

PHP version history (3 changes)v1.0.0PHP &gt;=7.2

v1.0.2PHP &gt;=5.6

v1.0.3PHP &gt;=7.4

### Community

Maintainers

![](https://www.gravatar.com/avatar/681627d87d4333dede3a4ddc81bca9033d73913d6ab87749dc2eef5637e73077?d=identicon)[zalievsk1y](/maintainers/zalievsk1y)

---

Top Contributors

[![zalevsk1y](https://avatars.githubusercontent.com/u/24773764?v=4)](https://github.com/zalevsk1y "zalevsk1y (7 commits)")

###  Code Quality

TestsPHPUnit

### Embed Badge

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

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

###  Alternatives

[winzou/state-machine-bundle

Bundle for the very lightweight yet powerful PHP state machine

34010.4M15](/packages/winzou-state-machine-bundle)[xethron/laravel-4-generators

Rapidly generate resources, migrations, models, and much more.

972.8M10](/packages/xethron-laravel-4-generators)[timacdonald/has-parameters

A trait that allows you to pass arguments to Laravel middleware in a more PHP'ish way.

228271.7k2](/packages/timacdonald-has-parameters)[cornernote/gii-modeldoc-generator

Gii ModelDoc Generator for Yii framework

13109.1k](/packages/cornernote-gii-modeldoc-generator)[vanthao03596/laravel-hanhchinhvn

hành chính việt nam laravel

406.3k](/packages/vanthao03596-laravel-hanhchinhvn)

PHPackages © 2026

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