PHPackages                             gdianov/opium - 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. gdianov/opium

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

gdianov/opium
=============

Simple dependency injection container

v1.0.0(5y ago)02MITPHP

Since Jul 5Pushed 5y ago1 watchersCompare

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

READMEChangelogDependencies (3)Versions (2)Used By (0)

Opium - Simple Yaml DI Container
================================

[](#opium---simple-yaml-di-container)

How to usage?
-------------

[](#how-to-usage)

### Install:

[](#install)

> composer require gdianov/opium

1. Create your yaml config like config.yaml:

    ```
     t:
       class: gdianov\opium\tests\classes\T
       constructor:
         - 1
       props:
         - bar: barValue

     c:
       class: gdianov\opium\tests\classes\C
       constructor:
         - '@t'

     p:
       class: gdianov\opium\tests\classes\P
       constructor:
         - opium
       props:
         - c: '@c'

    ```
2. Create Opium instance like this:

    ```
    $configFile = __DIR__ . '/config.yaml';
    $loader = new YamlLoader($configFile);
    $config = $loader->configure();
    $opium = Opium::getInstance(new Container(), $config);

    ```
3. Use it.

**Create objects by yaml configuration:**

```
//$t is instance of: gdianov\opium\tests\classes\T
$t = $opium->make('t');

//$c is instance of: gdianov\opium\tests\classes\C with
//injected object $t by constructor
$c = $opium->make('c');

//$p is instance of: gdianov\opium\tests\classes\P with
//injected object $c by property and string by constructor
$p = $opium->make('p');

//You can injected dependency by property and constructor.
```

**Also we can create new object dynamically:**

```
$t = $opium->makeDynamic([
     'class' => T::class,
     'props' => [
          [
            'bar' => $barValue
          ]
]);

```

**Create dynamically and related with yaml config dependency:**

```
$c = $opium->makeDynamic([
    'class' => C::class,
    'constructor' => ['@t']
]);

//New C instance with T dependency
```

**You can get new instance with another params:**

```
$t = $opium->getWithParams('t', [
        'props' => [
            ['bar' => 'Another Value'],
        ]
]);

//Instance T with new property bar value

```

> #### You can combine objects as you like without restricting yourself to anything. Try it.
>
> [](#you-can-combine-objects-as-you-like-without-restricting-yourself-to-anything-try-it)

###  Health Score

23

—

LowBetter than 27% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity2

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity54

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

Unknown

Total

1

Last Release

2134d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/527a7bcd787a6877d6de2b13df7aff607ddaaba71dc44c311bcac3da36dbfef3?d=identicon)[s0maly](/maintainers/s0maly)

---

Top Contributors

[![gdianov](https://avatars.githubusercontent.com/u/13520354?v=4)](https://github.com/gdianov "gdianov (5 commits)")

---

Tags

containercontainer-interopPSR-11dependency-injectiondiiocpsr11

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/gdianov-opium/health.svg)

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

###  Alternatives

[php-di/php-di

The dependency injection container for humans

2.8k48.9M989](/packages/php-di-php-di)[slince/di

A flexible dependency injection container

20260.4k6](/packages/slince-di)

PHPackages © 2026

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