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

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

ifcanduela/container
====================

Simple key/value container

1.0.1(4y ago)0791MITPHPPHP ^7.4|^8.0

Since Oct 11Pushed 4y ago1 watchersCompare

[ Source](https://github.com/ifcanduela/container)[ Packagist](https://packagist.org/packages/ifcanduela/container)[ RSS](/packages/ifcanduela-container/feed)WikiDiscussions master Synced today

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

Container
=========

[](#container)

Extremely simple key/value container inspired by Pimple.

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

[](#installation)

Use [Composer](https://getcomposer.org):

```
composer require ifcanduela/container
```

Usage
-----

[](#usage)

Create an `ifcanduela\container\Container` instance to get started. Passing values in an associative array is optional, and can be done later using `merge()`:

```
$container = new ifcanduela\container\Container([
    "alpha" => "a",
    "beta" => "b",
]);

$container->merge([
    "gamma" => "g",
    "delta" => "d",
]);
```

### Simple values

[](#simple-values)

Register values using `set()` and retrieve them using `get()`:

```
$container->set("db_username", "root@localhost");

echo $container->get("db_username");
```

The Container class implements `ArrayAccess` so setting and getting values can be done using index notation:

```
$container["db_username"] = "root@localhost";

echo $container["db_username"];
```

### Closures

[](#closures)

Closures can be added in two ways: if your intention is to access the closure itself, use the `raw()` method, o wrap it in a call to the `raw()` function:

```
use function ifcanduela\container\raw;

$container->raw("rand", function (int $max) {
    return random_int(0, $max);
});

// using the helper
$container->set("rand", raw(function (...) {...}));

// using array index notation
$container["rand"] = raw(function (...) {...});

$rand = $container->get("rand");

echo $rand(100);
```

If you want to use the closure to build a value, simply use `set()`. These closures will only run when `get()` is used, will receive the container itself, and will only be executed once (the same result is returned on every call to `get()`).

```
$container->set("logger", function (Container $c) {
    return new Logger($c->get("log_path"));
});

// using array index notation
$container["logger"] = function (...) {...};

$logger = $container->get("logger");

$logger->log(Logger::INFO, "I'm the logger");
```

### Factories

[](#factories)

If the closure must be called every time the value is read, for example to build multiple instances of an object, define it using `factory()` or wrap it with the `factory()` function:

```
use function ifcanduela\container\factory;

$container->factory("rand", function (Container $c) {
    return random_int(0, $c->get("max_random_number"));
});

// using the helper
$container->set("rand", factory(function (...) {...}));

// using array index notation
$container["rand"] = factory(function (...) {...});

echo $container->get("rand"); // => 24
echo $container->get("rand"); // => 71
echo $container->get("rand"); // => 13
```

### Checking if a value is defined

[](#checking-if-a-value-is-defined)

Use the `has()` method, or `isset()` when using array index notation:

```
$container = new \ifcanduela\container\Container([
    "a" => 1,
    "b" => 2,
    "c" => 3,
    "e" => 5,
]);

var_dump($container->has("a")); // => true
var_dump($container->has("d")); // => false
var_dump(isset($container["d"])); // => false
```

License
-------

[](#license)

[MIT](LICENSE).

###  Health Score

26

—

LowBetter than 41% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity10

Limited adoption so far

Community9

Small or concentrated contributor base

Maturity57

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

Total

2

Last Release

1606d ago

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/1359230?v=4)[Igor Fernández Canduela](/maintainers/ifcanduela)[@ifcanduela](https://github.com/ifcanduela)

---

Top Contributors

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

###  Code Quality

TestsPHPUnit

Static AnalysisPsalm

Type Coverage Yes

### Embed Badge

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

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

###  Alternatives

[imi/magento2-store-switch-all-store-views

This module makes all store views available in the store switcher, regardless of their store or website.

1826.0k](/packages/imi-magento2-store-switch-all-store-views)[aschmelyun/size

Simple PHP helper to convert bytes to different sizes

471.2k](/packages/aschmelyun-size)

PHPackages © 2026

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