kba-team/memory-container

PSR-11 container storing its values in memory and offering a singleton access.

v2.0.0 2023-10-19 15:00 UTC

This package is auto-updated.

Last update: 2024-12-19 17:41:50 UTC


README

License: MIT PHP Version Maintainability Test Coverage

PSR-11 container storing its values in memory and offering a singleton access.

Usage

A simple example:

<?php
namespace vendor\product;

class Greeter
{
    public function __construct(\Closure $logic) {
        printf('%s%s', $logic('world'), PHP_EOL);
    }
}
<?php

use kbATeam\MemoryContainer\Container;
use vendor\product\Greeter;

Container::singleton()->add('hello', function ($what) {
    return sprintf('Hello %s!', $what);
});
// ...
$example = new Greeter(Container::singleton()->get('hello'));

Testing

Get composer, and install the dependencies.

composer install

Call phpunit to run the tests available.

vendor/bin/phpunit