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

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

istok/container
===============

DI / IoC container with `call(\\Closure $fn): mixed` method

0.0.5(4y ago)09MITPHPPHP ^8.1

Since Apr 30Pushed 4y ago1 watchersCompare

[ Source](https://github.com/the-toster/istok-container)[ Packagist](https://packagist.org/packages/istok/container)[ RSS](/packages/istok-container/feed)WikiDiscussions master Synced 3w ago

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

DI container
============

[](#di-container)

```
composer require istok/container
```

- allow to call any `\Closure` with `Container::call(\Closure $fn): mixed` method
- allow custom resolving by attributes (useful to fill DTO)
- allow param-name binding: `Container::argument(string $name, string $for, \Closure $resolver)`
- provided with wrapper implementing PSR-11 (see `Istok\Container\Psr\StrictContainer` and `Istok\Container\Psr\GreedyContainer`)

Registration methods
--------------------

[](#registration-methods)

```
// Registration of cachable entry
Container::singletone(string $id, string|\Closure $defitition);

// This entry will not be cached
Container::register(string $id, string|\Closure $defitition);

// parameter $name of $for::__construct() will be resolved by given closure
Container::argument(string $name, string $for, \Closure $resolver);
```

`$definition` parameters will be resolved by `Container`

Retrieving
----------

[](#retrieving)

```
// take instance
Container::make(string $id);

/**
 * Call $fn with given arguments, using Container::make() for rest
 * @param array $args
 */
Container::call(\Closure $fn, $args);

/**
 * Psalm-friendly version, contains actual type check, T should be class or interface, result should be typeof T
 * @template T
 * @param class-string $id
 * @return T
 */
Container::construct(string $id): object;
```

Identifier resolution order
---------------------------

[](#identifier-resolution-order)

- use direct registration
- use attributes, use if any suited
- try to construct

Closure arguments resolution
----------------------------

[](#closure-arguments-resolution)

- apply explicitly provided arguments
- use `Container::get()` to resolve rest

Resolving by attributes
-----------------------

[](#resolving-by-attributes)

If target class has attribute that implements `Istok\Container\Resolver` interface, instance of attribute will be constructed (by `Container::get`, not `ReflectionAttribute::newInstance()`), and then result of `Resolver::resolve($targetName, ...$attributeArgs)` will be returned as result.

Service and Model resolving
---------------------------

[](#service-and-model-resolving)

According to [Object Design Style Guide](https://matthiasnoback.nl/book/style-guide-for-object-design/) by Matthias Noback, there are [two types of objects](https://medium.com/swlh/objects-services-and-dependencies-58106df2ac2b):

> #### Two types of objects
>
> [](#two-types-of-objects)
>
> In an application there are typically two types of objects:
>
> 1. Service objects which either perform a task, or return a piece of information.
> 2. Objects that hold some data, and optionally expose some behavior for manipulating or retrieving that data.

First type have a well-known name, `Service`, and other one I called `Model` (I have to called it someway).
While `Services` depends on both other `Services` and `Models`, `Models` depends only on other `Models` and `input`.

One of reasons why I want to create this container was the desire to be able to get well-typed DTOs filled from user input, or config, as arguments of my controllers.

To achieve this, I added `Resolver` interface, which implementation can be used as attribute of `Model`.
This allows to add contextual configuration for resolving this type of objects.

So, `Container` itself is mostly for resolving `Services`, and `ModelResolver` used for resolving `Models`, like request `DTOs`.

###  Health Score

23

—

LowBetter than 26% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity4

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity51

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

Total

5

Last Release

1490d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/62257854467f165e1ec97a01abf9999a603eca22a0345e9af7d33c1cf7413975?d=identicon)[the-toster](/maintainers/the-toster)

---

Top Contributors

[![the-toster](https://avatars.githubusercontent.com/u/22966096?v=4)](https://github.com/the-toster "the-toster (29 commits)")

###  Code Quality

TestsPHPUnit

Static AnalysisPsalm

Type Coverage Yes

### Embed Badge

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

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

###  Alternatives

[symfony/dependency-injection

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

4.2k455.6M9.6k](/packages/symfony-dependency-injection)[illuminate/contracts

The Illuminate Contracts package.

706130.3M13.3k](/packages/illuminate-contracts)[illuminate/container

The Illuminate Container package.

31182.0M2.4k](/packages/illuminate-container)[ecotone/ecotone

Enterprise architecture layer for Laravel and Symfony — CQRS, Event Sourcing, Durable Workflows (Sagas, Orchestrators), Projections, and Outbox messaging via PHP attributes.

564576.7k53](/packages/ecotone-ecotone)[symfony/type-info

Extracts PHP types information.

20069.8M270](/packages/symfony-type-info)[civicrm/civicrm-core

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

751291.4k43](/packages/civicrm-civicrm-core)

PHPackages © 2026

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