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

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

jakulov/container
=================

Simple universal Container &amp; DIContainer

020PHP

Since Jan 2Pushed 10y ago1 watchersCompare

[ Source](https://github.com/jakulov/container)[ Packagist](https://packagist.org/packages/jakulov/container)[ RSS](/packages/jakulov-container/feed)WikiDiscussions master Synced yesterday

READMEChangelogDependenciesVersions (1)Used By (0)

Container
=========

[](#container)

Simple universal PHP Container &amp; DIContainer (Dependency Injection)

Can be installed with composer

```
composer require jakulov/container

```

Implements [Container Interoperability](https://github.com/container-interop/container-interop)

1. Container
------------

[](#1-container)

Container could be used to store any array data (e.g. configuration or repository) and easy accessing it with dot notation.

```
$config = ['test' => [
        'key1' => 'value1',
    ]];
$container = \jakulov\Container\Container::getInstance($config);
echo $container->get('test.key1'); // value1

```

Container and DIContainer uses singleton pattern, so after first initialization of container you can access to it without passing config as argument, like:

```
// second and other usages of container should not use config
$container = \jakuov\Container\Container::getInstance();

```

2. DIContainer
--------------

[](#2-dicontainer)

Dependency injection container should be used for manager dependencies between services in php application. This quite simple but agile implementation of DI Container.

```
$config = [
    'foo' => 'bar',
    // you can use aware-interfaces to manage dependencies in app
    'container' => [
      'di' => [
          'aware' => [
              // in any service class implements this interface and resolved
              // with DIContainer will be called setInterfaceTest method with argument
              // containing instance of service "service.interface_test"
              'Service\\InterfaceTestServiceAwareInterface' => [
                  'setInterfaceTest' => '@service.interface_test',
              ],
          ],
      ],
    ],
    // configuration of services
    'service' => [
      // service name will be "service.test"
      'test' => [
          'class' => 'Service\\TestService', // class of service
          // arguments of service __construct
          'args' => [
              'argument1',
              'argument2'
          ],
          // setters to call while service initialization
          'aware' => [
              // as dependency you can use:
              'setAnotherTestService' => '@service.another_test', // another service
              'setContainerValue' => ':foo', // container value
              'setScalarValue' => 'value', // or scalar value
          ],
      ],
      'another_test' => [
          'class' => 'Service\\AnotherTestService',
      ],
      'alias_test' => '@another_test',
      'interface_test' => [
          'class' => 'Service\\InterfaceTestService'
      ],
    ],
];

$dic = \jakulov\Container\DIContainer::getInstance($config);
$testService = $dic->get('service.test');
echo $testService->argument1; // 'argument1'
echo $testService->containerValue; // 'bar'
echo $testService->scalarValue; // 'value'
echo get_class( $testService->anotherTestService ); // Service\\AnotherTestService
echo get_class( $testService->anotherTestService->interfaceTestService ); // Service\\InterfaceTestService

```

Service can also resolve dependencies without declaration in config, if it's dependencies declared in class with help of aware interfaces.

```
$service = $dic->resolve(\Service\UnresolvedTestService::class);

```

If you want to make you services reusable with multiple requests, you should renew some dependencies on each request. For example it could be HTTP Request instance. If request service declared with id "request", you can provide new object like this:

```
$request = \Symfony\Component\HttpFoundation\Request::createFromGlobals();
$dic->provide('request', $request); // updated dependency in all services

```

Tests
-----

[](#tests)

Run: ./run\_tests.sh

Tests are also examples for usage library

###  Health Score

20

—

LowBetter than 13% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity6

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity41

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.

### Community

Maintainers

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

---

Top Contributors

[![jakulov](https://avatars.githubusercontent.com/u/3069267?v=4)](https://github.com/jakulov "jakulov (8 commits)")

### Embed Badge

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

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

###  Alternatives

[spatie/shiki-php

Highlight code using Shiki in PHP

31018.6M16](/packages/spatie-shiki-php)[xj/yii2-sitemap

yii2-sitemap

142.7k](/packages/xj-yii2-sitemap)

PHPackages © 2026

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