PHPackages                             webiik/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. [PSR &amp; Standards](/categories/psr-standards)
4. /
5. webiik/container

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

webiik/container
================

The Container adds handy methods to most common Pimple functions and then adds automatic injection of dependencies from container to class constructor.

1.1(4y ago)0701MITPHPPHP &gt;=7.2

Since Mar 28Pushed 4y ago1 watchersCompare

[ Source](https://github.com/webiik/container)[ Packagist](https://packagist.org/packages/webiik/container)[ Docs](https://www.webiik.com)[ RSS](/packages/webiik-container/feed)WikiDiscussions master Synced 6d ago

READMEChangelogDependencies (1)Versions (3)Used By (1)

[![](https://camo.githubusercontent.com/a397347ee4fb199934fee6354504f4702b89f5c22f0ce0ba94c5ff691cde545c/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f6c2f77656269696b2f77656269696b2e737667)](https://camo.githubusercontent.com/a397347ee4fb199934fee6354504f4702b89f5c22f0ce0ba94c5ff691cde545c/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f6c2f77656269696b2f77656269696b2e737667)[![](https://camo.githubusercontent.com/bdb417a12aecf0f18d2522ead57fa9c3d6f72238f05a20e8169bcd816f5ee809/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f646570656e64656e636965732d312d627269676874677265656e2e737667)](https://camo.githubusercontent.com/bdb417a12aecf0f18d2522ead57fa9c3d6f72238f05a20e8169bcd816f5ee809/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f646570656e64656e636965732d312d627269676874677265656e2e737667)

Container
=========

[](#container)

The Container adds handy methods to most common Pimple functions and then adds automatic injection of dependencies from container to class constructor.

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

[](#installation)

```
composer require webiik/container
```

Example
-------

[](#example)

```
$container = new \Webiik\Container\Container();
$container->addService('\Webiik\Arr\Arr', function () {
    return new \Webiik\Arr\Arr();
});
$array = $container->get('\Webiik\Arr\Arr');
```

Adding
------

[](#adding)

### addService

[](#addservice)

```
addService(string $name, callable $factory): void
```

**addService()** ads service factory to container. It returns always same instance of service.

```
$container->addService('\Webiik\Arr\Arr', function () {
    return new \Webiik\Arr\Arr();
});
```

If you need to access container inside **$factory**:

```
$container->addService('Service', function ($container) {
    // $container - Container
});
```

### addServiceFactory

[](#addservicefactory)

```
addServiceFactory(string $name, callable $factory): void
```

**addServiceFactory()** ads service factory to container. It returns always new instance of service.

```
$container->addService('\Webiik\Arr\Arr', function () {
    return new \Webiik\Arr\Arr();
});
```

### addParam

[](#addparam)

```
addParam(string $name, $val): void
```

**addParam()** ads parameter to container.

```
$container->addParam('foo', 'bar');
```

### addFunction

[](#addfunction)

```
addFunction(string $name, callable $function): void
```

**addFunction()** ads function to container.

```
$container->addFunction('myFn', function ($a, $b) {
    return $a * $b;
});
```

Check
-----

[](#check)

### isIn

[](#isin)

```
isIn(string $name): bool
```

**isIn()** checks if service, parameter or function is stored in container.

```
$container->isIn('\Webiik\Arr\Arr');
```

Getting
-------

[](#getting)

### get

[](#get)

```
get(string $name)
```

**get()** returns service, parameter or function from container.

```
$array = $container->get('\Webiik\Arr\Arr');
```

Dependency Injection
--------------------

[](#dependency-injection)

Container provides automatic dependency injection from Container to class controller using the method `injectTo(string $className): array`. However it requires to follow these naming conventions:

### Inject Service by Class Name

[](#inject-service-by-class-name)

1. Add service with same name as full name of underlying class: ```
    $container->addService('\Webiik\Arr\Arr', function () {
       return new \Webiik\Arr\Arr();
    });
    ```
2. Use full class name as type parameter in controller in your class: ```
    public function __construct(\Webiik\Arr\Arr $array)
    {
        $this->array = $array;
    }
    ```

    > Container will search for service with name `\Webiik\Arr\Arr`.
3. Inject dependencies to class: ```
    $myClass = new MyClass(...$container->injectTo('MyClass'));
    ```

### Inject Service by Service Name

[](#inject-service-by-service-name)

1. Add service with name matching the following regex `ws[A-Z]`: ```
    $container->addService('wsArray', function () {
       return new \Webiik\Arr\Arr();
    });
    ```
2. Add class name alias to your class: ```
    use Webiik\Arr\Arr as wsArray;
    ```
3. Add doc block with parameter type to controller of your class: ```
    /**
    * @param wsArray $array
    */
    public function __construct(wsArray $array)
    {
        $this->array = $array;
    }
    ```

    > Container will search for service with name `wsArray`.
4. Inject dependencies from container to your class: ```
    $myClass = new MyClass(...$container->injectTo('MyClass'));
    ```

### Inject Function or Parameter

[](#inject-function-or-parameter)

1. Add parameter with any name: ```
    $container->addFunction('myFnName', function() {
        echo 'Hello!';
    });
    ```
2. Use parameter name in constructor in your class: ```
    public function __construct($myFnName)
    {
        $myFnName(); // Hello
    }
    ```

    > Container will search for parameter with name `myParamName`.
3. Inject dependencies from container to your class: ```
    $myClass = new MyClass(...$container->injectTo('MyClass'));
    ```

### Inject Container Itself

[](#inject-container-itself)

1. Use full Container class name as type parameter in constructor in your class: ```
    public function __construct(\Webiik\Container\Container $container)
    {
        $this->container = $container;
    }
    ```
2. Inject dependencies from container to your class: ```
    $myClass = new MyClass(...$container->injectTo('MyClass'));
    ```

Resources
---------

[](#resources)

- [Webiik framework](https://github.com/webiik/webiik)
- [Report issue](https://github.com/webiik/components/issues)
- [Pimple](https://github.com/silexphp/Pimple)

###  Health Score

26

—

LowBetter than 43% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity9

Limited adoption so far

Community9

Small or concentrated contributor base

Maturity56

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

Total

2

Last Release

1780d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/1226362d003d186b45e7dfa44489c36af37196c6a1b476206700eaf4e9c96a5a?d=identicon)[Jiri Mihal](/maintainers/Jiri%20Mihal)

---

Top Contributors

[![Jiri-Mihal](https://avatars.githubusercontent.com/u/10408123?v=4)](https://github.com/Jiri-Mihal "Jiri-Mihal (127 commits)")

---

Tags

containerdependencyinjectiondi

### Embed Badge

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

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

###  Alternatives

[league/container

A fast and intuitive dependency injection container.

86387.8M343](/packages/league-container)[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)
