PHPackages                             exts/canister - 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. exts/canister

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

exts/canister
=============

PHP 7 dependency autowiring psr-11 container

1.0.0-beta8(8y ago)2421PHPPHP ^7.1

Since May 14Pushed 8y ago1 watchersCompare

[ Source](https://github.com/exts/Canister)[ Packagist](https://packagist.org/packages/exts/canister)[ RSS](/packages/exts-canister/feed)WikiDiscussions master Synced 2mo ago

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

Canister
========

[](#canister)

Canister is a psr-11 auto-wiring container for PHP 7. Will add examples later.

#### Notes

[](#notes)

- All classes that aren't in the container are automatically resolved if they exist
- All resolved classes are shared by default
- Reflector uses a simple array cache by default, but can be overridden by using a PSR-16 simple cache interface when passed to the constructor of a new reflector instance
- Container is an implementation of `ArrayAccess` so you can do pretty much what you would normally do using `ArrayAccess`
- You can define/override default values for class instances when the code tries to resolve it from the container.
- The get method checks in this order when calling the `get` method from the container: container, factory callables, shared callables, then attempts to resolve any classes if they exists and attempt to grab them from the reflector's cache first then resolve it automatically. If all else fails it'll return `NULL`

Examples
========

[](#examples)

Below are simple examples of it's usage.

##### Basic instantiation

[](#basic-instantiation)

```
use Canister;

$container = new Canister;
```

##### Storing basic data into the container

[](#storing-basic-data-into-the-container)

```
$container['my-key-value'] = 'accessed anywhere';

echo $container->get('my-key-value'); // or $container['my-key-value'];
```

##### Auto-Resolving a class

[](#auto-resolving-a-class)

```
class Example
{
    public function foo() {
        return 'bar';
    }
}

$example = $container->get(Example::class);
echo $example->foo(); // -> 'bar'
```

##### Creating an alias to a class

[](#creating-an-alias-to-a-class)

```
$container->alias(ExampleInterface::class, Example::class);

$example = $container->get(ExampleInterface::class);
echo $example->foo(); // -> 'bar'
```

This also works for automatically passing dependencies to classes

```
class Test implements TestInterface {
    public function example() {
        return 'example';
    }
}

class TestExample {
    public function __construct(TestInterface $test) {
        $this->test = $test;
    }
    public function testing() {
        return $this->test->example();
    }
}

$container->alias(TestInterface::class, Test::class);
$test_example = $container->get(TestExample::class);
echo $test_example->testing(); // -> 'example'
```

##### Define class as a factory

[](#define-class-as-a-factory)

Everytime you call `FactoryClass` it'll be a new instance instead of being shared by default.

```
$container->factory(FactoryClass::class);
```

##### Define factory callable

[](#define-factory-callable)

Dependencies to callables are also auto resolved by default, so you can access the container directly because it's automatically passed to the container by default.

```
$container->factory(FactoryClass::class, function() {
    //...
});
```

##### Define shared callable

[](#define-shared-callable)

Want to do the same thing instead store the value instead of creating new instances every call? Well replace `factory` with `shared` and you get the same functionality.

*(Note: since auto resolution is shared by default, you cannot pass a class name by itself like you can with the `factory` method)*

##### Defining default parameters for callables &amp; classes

[](#defining-default-parameters-for-callables--classes)

For callables it's as simple as

```
$container->share('example', function($foo, $bar) {
    return $foo + $bar;
});

$container->define('example', [
    'foo' => val(5),
    'bar' => val(21)
]);

echo $container->get('example');
```

The first parameter is the class name or callable name that we're trying to define parameters for. The second parameter is an array used to match the parameters we want to define.

You don't have to order them in any order, just need to know the variable name and make that as the key.

**Global Definition functions**

There's two global definition functions inside the `Canister` namespace called `val` (or `Canister\val()`) and `bag` or (`Canister\bag()`).

The `val` function is used to tell the resolution method that we're using a raw value.

The `bag` function is used to tell the resolution method that we should check the container for this value.

### Other Notes

[](#other-notes)

- You can resolve php classes as well as define their value too.

```
$container = new Canister;
$container->define(\PDO::class, [
    'dsn' => val('sqlite::memory:'),
]);

$pdo = $container->get(\PDO::class);

echo is_a($pdo, \PDO::class) ? 'true' : 'false'; // -> true
```

###  Health Score

24

—

LowBetter than 32% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity11

Limited adoption so far

Community9

Small or concentrated contributor base

Maturity49

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

Total

8

Last Release

3278d ago

PHP version history (2 changes)1.0.0-beta1PHP ^7.0

1.0.0-beta3PHP ^7.1

### Community

Maintainers

![](https://www.gravatar.com/avatar/0d11ac939290fe178f8787292ce605375859d8c035fbd14c859bf827f069738b?d=identicon)[exts](/maintainers/exts)

---

Top Contributors

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

---

Tags

autowiringcontainer-interopdependency-injectionphpphp7psr-11psr-16

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/exts-canister/health.svg)

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

###  Alternatives

[pimple/pimple

Pimple, a simple Dependency Injection Container

2.7k130.5M1.4k](/packages/pimple-pimple)[league/container

A fast and intuitive dependency injection container.

86387.8M343](/packages/league-container)[phpwatch/simple-container

A fast and minimal PSR-11 compatible Dependency Injection Container with array-syntax and without auto-wiring

1810.1k2](/packages/phpwatch-simple-container)

PHPackages © 2026

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