PHPackages                             usmanhalalit/viocon - 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. [Testing &amp; Quality](/categories/testing)
4. /
5. usmanhalalit/viocon

ActiveLibrary[Testing &amp; Quality](/categories/testing)

usmanhalalit/viocon
===================

A simple and flexible Dependency Injection container for PHP.

1.0.1(12y ago)42.3M↑30.5%4[1 issues](https://github.com/usmanhalalit/viocon/issues)10MITPHPPHP &gt;=5.3.0

Since Jul 9Pushed 12y ago3 watchersCompare

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

READMEChangelogDependencies (1)Versions (4)Used By (10)

Viocon [![Build Status](https://camo.githubusercontent.com/5ac5956d07c0b3c2df39d600740d046c4f91d19492bd1b6d022ba5b750c48ee4/68747470733a2f2f7472617669732d63692e6f72672f75736d616e68616c616c69742f76696f636f6e2e706e673f6272616e63683d6d6173746572)](https://travis-ci.org/usmanhalalit/viocon)
===============================================================================================================================================================================================================================================================================================

[](#viocon-)

A simple and flexible Dependency Injection or Service container for PHP.

It can be extremely helpful to decouple your dependencies. You can also mock dependencies at runtime.

Installation
------------

[](#installation)

Viocon uses [Composer](http://getcomposer.org/) to make things easy.

Learn to use composer and add this to require (in your composer.json):

```
"usmanhalalit/viocon": "1.0.*@dev"

```

Library on [Packagist](https://packagist.org/packages/usmanhalalit/viocon).

Usage
-----

[](#usage)

```
$container = new \Viocon\Container();
```

**You can optionally create a class alias too**

```
new \Viocon\Container('Container');
```

Viocon will create a class alias for you with the given name 'Container'. Now you can use this class' methods statically, like

```
\Container::set(...);
\Container::build(...);
```

And so ...

---

### Bind a closure

[](#bind-a-closure)

```
$container->set('myClosure', function ($test1, $test2)
{
    $stdClass = new \stdClass();
    $stdClass->testVar1 = $test1;
    $stdClass->testVar2 = $test2;
    $stdClass->testMethod = function ($test3) {
        return $test3;
    };

    return $stdClass;
});

$object = $container->build('myClosure', array('Test Var 1', 'Test Var 2'))

echo $object->testVar1;
```

### Build Any Class and Optionally Pass Parameters

[](#build-any-class-and-optionally-pass-parameters)

```
$container->build('\PDO', array('myConnectionInfo'));
```

### Singleton

[](#singleton)

```
$container->set('mySingleton', '\\stdClass');
$stdClass = $container->build('mySingleton');
```

### Replacing Objects at Runtime

[](#replacing-objects-at-runtime)

It can be useful while testing with mocked object

```
$mockedClass = new \stdClass();
$mockedClass->testVar = 'mocked';

static::$container->setInstance('\\stdClass', $mockedClass);

$stdClass = static::$container->build('\\stdClass');
$this->assertEquals('mocked', $stdClass->testVar);
```

###  Health Score

38

—

LowBetter than 85% of packages

Maintenance15

Infrequent updates — may be unmaintained

Popularity45

Moderate usage in the ecosystem

Community16

Small or concentrated contributor base

Maturity60

Established project with proven stability

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

Total

3

Last Release

4692d ago

### Community

Maintainers

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

---

Tags

containertestdiioc

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/usmanhalalit-viocon/health.svg)

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

###  Alternatives

[php-di/php-di

The dependency injection container for humans

2.8k48.9M994](/packages/php-di-php-di)[ramunasd/symfony-container-mocks

Provides extended Symfony dependency injection container enabling service mocking.

2295.8k2](/packages/ramunasd-symfony-container-mocks)[slince/di

A flexible dependency injection container

20260.4k6](/packages/slince-di)[joomla/di

Joomla DI Package

15391.2k11](/packages/joomla-di)[capsule/di

A PSR-11 compliant autowiring dependency injection container.

2857.5k2](/packages/capsule-di)[miladrahimi/phpcontainer

Dependency injection (IoC) container for PHP projects

1322.7k2](/packages/miladrahimi-phpcontainer)

PHPackages © 2026

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