calgamo/registry

This package is abandoned and no longer maintained. No replacement package was suggested.

Dpendency injection container wrapper interface library

This package has no released version yet, and little information is available.


README

Latest Version on Packagist Software License Build Status Coverage Status Code Climate Total Downloads

Description

Calgamo/Registry is a dependency injection(DI) container facade library

Feature

Demo

Exsample 1: Simple usage of registry

use Calgamo\Di\Container;
use Calgamo\Registry\Adapter\CalgamoDiAdapter;
use Calgamo\Registry\Registry;
use Calgamo\Registry\Sample\Human;

try{
    $registry = new Registry('', new CalgamoDiAdapter(new Container));

    $david = new Human('David');
    $registry->set(Human::class, $david);

    $david = $registry->get(Human::class);
    echo 'My name: ' . $david->name . PHP_EOL;
}
catch(\Throwable $e)
{
    die($e->getTraceAsString());
}

Output:

My name: David

Exsample 2: Simple usage of regisrtry registry

use Calgamo\Registry\RegistryRegistry;

try{
    $registry_registry = new RegistryRegistry('registry.registry', new CalgamoDiAdapter(new Container));
    $registry = new Registry('human.namespace', new CalgamoDiAdapter(new Container));

    $david = new Human('David');
    $registry->set(Human::class, $david);

    $registry_registry->setRegistry('human.registry', $registry);

    call_user_func(
        function(RegistryRegistry $registry_registry)
        {
            // You can get registry via registry registry.
            $r = $registry_registry->getRegistry('human.registry');

            // You can get object via registry.
            $david = $r->get(Human::class);
            echo 'My name: ' . $david->name . PHP_EOL;
        }
        , $registry_registry);
}
catch(\Throwable $e)
{
    die($e->getTraceAsString());
}

Output:

Human registry is registered: 1
My name: David

Exsample 3: Lazy instantiation

try{
    $registry = new Registry('human.registry', new CalgamoDiAdapter(new Container));

    $registry->set(Human::class, function(){
        return new Human('David');
    });

    $david = $registry->get(Human::class);
    echo 'My name: ' . $david->name . PHP_EOL;
}
catch(\Throwable $e)
{
    die($e->getTraceAsString());
}

Output:

My name: David

Usage

Requirement

PHP 7.0 or later

Installing Calgamo/Registry

The recommended way to install Calgamo/Registry is through Composer.

composer require calgamo/registry

After installing, you need to require Composer's autoloader:

require 'vendor/autoload.php';

License

MIT

Author

stk2k

Disclaimer

This software is no warranty.

We are not responsible for any results caused by the use of this software.

Please use the responsibility of the your self.