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

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

webino/instance-container
=========================

Class Instance Container implementation.

1.0.0(6y ago)165BSD-3-ClausePHPPHP ~7.1

Since Jun 22Pushed 6y ago1 watchersCompare

[ Source](https://github.com/webino/instance-container)[ Packagist](https://packagist.org/packages/webino/instance-container)[ RSS](/packages/webino-instance-container/feed)WikiDiscussions develop Synced 3d ago

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

Webino Instance Container
=========================

[](#webino-instance-container)

Instance Container implementation.

[![Build Status](https://camo.githubusercontent.com/c018e46f454dde4cf9d3209e51f3cbe9b5fa57b1be7c90b9b0e389446e621182/68747470733a2f2f696d672e736869656c64732e696f2f7472617669732f776562696e6f2f696e7374616e63652d636f6e7461696e65722f6d61737465722e7376673f7374796c653d666f722d7468652d6261646765)](http://travis-ci.org/webino/instance-container "Master Build Status")[![Coverage Status](https://camo.githubusercontent.com/29e17107a1f79e33d6afc7aac4b4bc64d4420e8a8be1893be08b8a41ba8e63af/68747470733a2f2f696d672e736869656c64732e696f2f636f766572616c6c732f6769746875622f776562696e6f2f696e7374616e63652d636f6e7461696e65722f6d61737465722e7376673f7374796c653d666f722d7468652d6261646765)](https://coveralls.io/github/webino/instance-container?branch=master "Master Coverage Status")[![Code Quality](https://camo.githubusercontent.com/73ace71075b9c4fbeee658b86e6e3bec555d5261944f96bd3f41d1288febaa76/68747470733a2f2f696d672e736869656c64732e696f2f7363727574696e697a65722f672f776562696e6f2f696e7374616e63652d636f6e7461696e65722f6d61737465722e7376673f7374796c653d666f722d7468652d6261646765)](https://scrutinizer-ci.com/g/webino/instance-container/?branch=master "Master Code Quality")[![Latest Stable Version](https://camo.githubusercontent.com/bb8fc5064cd609ef644ba38499e8e74d51de6a96936eb62f6ebbf5d941271229/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f7461672f776562696e6f2f696e7374616e63652d636f6e7461696e65722e7376673f6c6162656c3d535441424c45267374796c653d666f722d7468652d6261646765)](https://packagist.org/packages/webino/instance-container)

Recommended usage
-----------------

[](#recommended-usage)

Instance container should be used in factories to resolve new class instance dependencies. It is not recommended to inject it into objects directly.

Setup
-----

[](#setup)

[![PHP from Packagist](https://camo.githubusercontent.com/785aa25acc80265be5c77ec9688b300ac58839b01e4991f515e1fadcbffd685e/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f7068702d762f776562696e6f2f696e7374616e63652d636f6e7461696e65722e7376673f7374796c653d666f722d7468652d6261646765)](https://php.net "Required PHP version")

```
composer require webino\instance-container
```

Quick Use
---------

[](#quick-use)

Getting same class instance:

```
use Webino\InstanceContainer;

class TestInstance
{
}

$instances = new InstanceContainer;

$testInstance = $instances->get(TestInstance::class);
```

Creating new class instance:

```
use Webino\InstanceContainer;

class TestInstance
{
    public function __construct(stdClass $dependency)
    {
    }
}

$instances = new InstanceContainer;

$testInstance = $instances->make(TestInstance::class, new stdClass);
```

Getting class instance with a factory method:

```
use Webino\InstanceContainer;
use Webino\CreateInstanceEventInterface;
use Webino\InstanceFactoryMethodInterface;

class TestInstance implements InstanceFactoryMethodInterface
{
    public static function create(CreateInstanceEventInterface $event)
    {
        $container = $event->getContainer();
        return new static($container->get(stdClass::class));
    }

    public function __construct(stdClass $dependency)
    {
    }
}

$instances = new InstanceContainer;

$testInstance = $instances->get(TestInstance::class);
```

Setting class instance:

```
use Webino\InstanceContainer;

class TestInstance
{
}

$instances = new InstanceContainer;

$instances->set(TestInstance::class, new TestInstance);
```

Unsetting class instance:

```
use Webino\InstanceContainer;

class TestInstance
{
}

$instances = new InstanceContainer;

$instances->set(TestInstance::class, null);
```

Binding factory class:

```
use Webino\InstanceContainer;
use Webino\CreateInstanceEventInterface;

class TestInstanceFactory implements InstanceFactoryInterface
{
    public function createInstance(CreateInstanceEventInterface $event)
    {
        $container = $event->getContainer();
        return new TestInstance($container->get(stdClass::class));
    }
}

class TestInstance
{
    public function __construct(stdClass $dependency)
    {
    }
}

$instances = new InstanceContainer;

$instances->bind(TestInstance::class, TestInstanceFactory::class);

$testInstance = $instances->get(TestInstance::class);
```

Binding callback factory:

```
use Webino\InstanceContainer;
use Webino\CreateInstanceEventInterface;

class TestInstance
{
    public function __construct(stdClass $dependency)
    {
    }
}

$instances = new InstanceContainer;

$instances->bind(TestInstance::class, function (CreateInstanceEventInterface $event) {
    $container = $event->getContainer();
    return new TestInstance($container->get(stdClass::class));
});

$testInstance = $instances->get(TestInstance::class);
```

Getting interface default class instance:

```
use Webino\InstanceContainer;

interface TestInstanceInterface
{
}

class TestInstance implements TestInstanceInterface
{
    public function __construct(stdClass $dependency)
    {
    }
}

$instances = new InstanceContainer;

$testInstance = $instances->get(TestInstanceInterface::class);
```

Setting alias interface to a class:

```
use Webino\InstanceContainer;

interface TestAliasInterface
{
}

class TestInstance implements TestAliasInterface
{
    public function __construct(stdClass $dependency)
    {
    }
}

$instances = new InstanceContainer;

$instances->alias(TestInstance::class, TestAliasInterface::class);

$testInstance = $instances->get(TestAliasInterface::class);
```

Instance creation event handling:

```
use Webino\InstanceContainer;
use Webino\CreateInstanceEvent;

class TestInstance
{
    public $foo = false;
}

$instances = new InstanceContainer;

$instances->on(CreateInstanceEvent::class, function (CreateInstanceEvent $event) {
    $instance = $event->getInstance();
    $instance->foo = true;
});

$testInstance = $instances->get(TestAliasInterface::class);
```

API
---

[](#api)

**InstanceContainer**

- *bool* has(*string* $id)
    Returns true if the container can return an instance for the given identifier, false otherwise.
- *mixed* get(*string* $id)
    Returns entry instance of the container by its identifier.
- *void* set(*string* $id, *mixed* $instance)
    Set entry instance.
- *mixed* make(*string* $id, *array&lt;int, mixed&gt;* ...$parameter)
    Creates new instance.
- *void* bind(*string* $id, *mixed* $binding)
    Bind provider to an entry instance.
- *void* alias(*string* $id, *string* $alias)
    Set alias to an entry instance.

**CreateInstanceEvent**

- *InstanceContainerInterface* getContainer()
    Returns instance container.
- *string* getClass()
    Returns instance class.
- *array* getParameters()
    Returns instance creation parameters.

**InstanceFactory**

- *mixed* createInstance(*CreateInstanceEventInterface* $event)
    Creates new instance.

**InstanceFactoryMethod**

- *mixed* *static* create(*CreateInstanceEventInterface* $event)
    Creates new instance.

Development
-----------

[](#development)

[![Build Status](https://camo.githubusercontent.com/81e22675aca5f86b5d1be9838b90e26616dd6dd01443fc592e819cce0f293592/68747470733a2f2f696d672e736869656c64732e696f2f7472617669732f776562696e6f2f696e7374616e63652d636f6e7461696e65722f646576656c6f702e7376673f7374796c653d666f722d7468652d6261646765)](http://travis-ci.org/webino/instance-container "Develop Build Status")[![Coverage Status](https://camo.githubusercontent.com/dcb64a45d38dfb82beeddba7951550e24b841b502ed853cb33174b890f3de718/68747470733a2f2f696d672e736869656c64732e696f2f636f766572616c6c732f6769746875622f776562696e6f2f696e7374616e63652d636f6e7461696e65722f646576656c6f702e7376673f7374796c653d666f722d7468652d6261646765)](https://coveralls.io/github/webino/instance-container?branch=develop "Develop Coverage Status")[![Code Quality](https://camo.githubusercontent.com/d4fbd8dca15e363f2bf15e436b4e5b416a98f7fb1b1cd45edc3d1bcb090d3938/68747470733a2f2f696d672e736869656c64732e696f2f7363727574696e697a65722f672f776562696e6f2f696e7374616e63652d636f6e7461696e65722f646576656c6f702e7376673f7374796c653d666f722d7468652d6261646765)](https://scrutinizer-ci.com/g/webino/instance-container/?branch=develop "Develop Code Quality")[![Latest Unstable Version](https://camo.githubusercontent.com/8e278e8ad91487de937404e905aca56d15821a74c071ac94207c6bf3238f1b75/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f7461672d7072652f776562696e6f2f696e7374616e63652d636f6e7461696e65722e7376673f6c6162656c3d50524556494557267374796c653d666f722d7468652d6261646765)](https://packagist.org/packages/webino/instance-container "Packagist")

Static analysis:

```
composer analyse
```

Coding style check:

```
composer check
```

Coding style fix:

```
composer fix
```

Testing:

```
composer test
```

Git pre-commit setup:

```
ln -s ../../pre-commit .git/hooks/pre-commit
```

Addendum
--------

[](#addendum)

[![License](https://camo.githubusercontent.com/f1b147eded80d4e661e752faf5acc722939b09791eb323b9b9cdda32f0c5b795/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f6c2f776562696e6f2f696e7374616e63652d636f6e7461696e65722e7376673f7374796c653d666f722d7468652d6261646765)](https://github.com/webino/instance-container/blob/master/LICENSE.md "BSD-3-Clause License")[![Total Downloads](https://camo.githubusercontent.com/fc924c28e89b83364e44260b4455f5c9078f82e168f9c0cb21b295c6c6d88876/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f776562696e6f2f696e7374616e63652d636f6e7461696e65722e7376673f7374796c653d666f722d7468652d6261646765)](https://packagist.org/packages/webino/instance-container "Packagist")[![GitHub code size in bytes](https://camo.githubusercontent.com/d8de9587df189a922996a4e582ca2d3c4aa18af92d1f52bc640f927c71b4b0b6/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f6c616e6775616765732f636f64652d73697a652f776562696e6f2f696e7374616e63652d636f6e7461696e65722e7376673f7374796c653d666f722d7468652d6261646765)](https://camo.githubusercontent.com/d8de9587df189a922996a4e582ca2d3c4aa18af92d1f52bc640f927c71b4b0b6/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f6c616e6775616765732f636f64652d73697a652f776562696e6f2f696e7374616e63652d636f6e7461696e65722e7376673f7374796c653d666f722d7468652d6261646765)

Please, if you are interested in this library report any issues and don't hesitate to contribute. We will appreciate any contributions on development of this library.

[![GitHub issues](https://camo.githubusercontent.com/38b8168487090a0ec39236b0a5b87744a2bbef28449418282b59d1a570125fe0/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f6973737565732f776562696e6f2f696e7374616e63652d636f6e7461696e65722e7376673f7374796c653d666f722d7468652d6261646765)](https://github.com/webino/instance-container/issues)[![GitHub forks](https://camo.githubusercontent.com/5d91c60a2ba7408350ff027179a3459a5c4a2b92b27ce859966320efad6bc1b1/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f666f726b732f776562696e6f2f696e7374616e63652d636f6e7461696e65722e7376673f6c6162656c3d466f726b267374796c653d666f722d7468652d6261646765)](https://github.com/webino/instance-container)

###  Health Score

26

—

LowBetter than 43% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity10

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity55

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

2518d ago

### Community

Maintainers

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

---

Top Contributors

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

---

Tags

containerinstancelibraryv3webinowip

###  Code Quality

Static AnalysisPHPStan

Code StylePHP\_CodeSniffer

Type Coverage Yes

### Embed Badge

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

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

###  Alternatives

[symfony/dependency-injection

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

4.2k431.1M7.5k](/packages/symfony-dependency-injection)[illuminate/contracts

The Illuminate Contracts package.

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

The Illuminate Container package.

31278.1M2.0k](/packages/illuminate-container)[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)
