PHPackages                             phico/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. [Framework](/categories/framework)
4. /
5. phico/container

ActiveLibrary[Framework](/categories/framework)

phico/container
===============

Lightweight dependency injection container for Phico

037PHP

Since Sep 4Pushed 1y agoCompare

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

READMEChangelogDependenciesVersions (1)Used By (0)

Container
=========

[](#container)

Small and focussed Dependency Injection container for the `Phico` framework.

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

[](#installation)

Using composer

```
composer require phico/container
```

Reference
---------

[](#reference)

Set a definition describing how to create the class `set(string $classname, callable|string $defintion, array $args =[])`

Set a shortcut alias on a definition `alias(string $name)`

Set the share flag on a definition `share(bool $toggle)`

Returns an instatiated class `get(string $classname or $alias)`

Usage
-----

[](#usage)

```
// pass an optional array of parameters through the constructor
$c = new Phico\Container([
    'autowiring' => false, // default is true
    'sharing' => false, // default is true
]);

// use get() to fetch an instantiated class
$foo = $c->get(Foo::class);
// foo is now an instance of Foo
```

### Autowiring

[](#autowiring)

With autowiring enabled, Container will do it's best to find and construct the class without any explicit instructions.

When autowiring is disabled, Container will need definitions creating using `set()`

```
// set() accepts a string for simple cases
$c->set(Foo::class, Foo::class);

// or callables for more complex requirements
$c->set(Foo::class, function() {
    return new Foo::class
});

// shorter function syntax is fine too
$c->set(Foo::class, fn() => new Foo());
```

### Aliases

[](#aliases)

Sometimes you just want to avoid typing, you can add an alias using `alias()` after the call to `set()`;

```
// set an alias to Foo named Bar, now foo can be accessed by get(Bar)
$c->set(Foo::class, Foo::class)
    ->alias('Bar');
$bar = $c->get('Bar');
// bar is now an instance of Foo
```

### Sharing

[](#sharing)

Some classes are better when shared, the default is true to always share instances once they have been created, however sometimes you will need an unique instance on every call to get(), toggle this behaviour using the `share()`method, it accepts a boolean true or false and will only affect the current definition.

```
$c->set(Foo::class, Foo::class)
    ->share(false);
$a = $c->get(Foo::class);
$b = $c->get(Foo::class);

// $a is not equal to $b, they are different instances
```

Contributing
------------

[](#contributing)

Container is considered feature complete, however if you discover any bugs or issues in it's behaviour or performance please create an issue, and if you are able a pull request with a fix.

Please make sure to update tests as appropriate.

For major changes, please open an issue first to discuss what you would like to change.

License
-------

[](#license)

[BSD-3-Clause](https://choosealicense.com/licenses/bsd-3-clause/)

###  Health Score

15

—

LowBetter than 3% of packages

Maintenance28

Infrequent updates — may be unmaintained

Popularity7

Limited adoption so far

Community6

Small or concentrated contributor base

Maturity18

Early-stage or recently created project

 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://avatars.githubusercontent.com/u/65541311?v=4)[indgy](/maintainers/indgy)[@indgy](https://github.com/indgy)

---

Top Contributors

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

### Embed Badge

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

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

###  Alternatives

[laravel/dusk

Laravel Dusk provides simple end-to-end testing and browser automation.

1.9k39.6M299](/packages/laravel-dusk)[nineinchnick/edatatables

Grid widget for the Yii Framework, wrapper for the DataTables jQuery plugin

173.2k](/packages/nineinchnick-edatatables)[link-cloud/fast-hyperf

LinkCloud Fast Hyperf

241.2k1](/packages/link-cloud-fast-hyperf)

PHPackages © 2026

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