ellipse/resolvable-class

Resolvable class factory allowing to instantiate classes using a Psr-11 container

1.0.7 2018-02-23 10:01 UTC

This package is auto-updated.

Last update: 2020-11-25 15:32:33 UTC


README

This package provides a resolvable class factory allowing to instantiate classes using a Psr-11 container.

Require php >= 7.0

Installation composer require ellipse/resolvable-class

Run tests ./vendor/bin/kahlan

Resolve a class

This package provides a factory producing instances of Ellipse\Resolvable\ResolvableClass from class names. Those resolvable class instances can then be produced by calling the ->value() method with a Psr-11 container and an array of placeholder values.

<?php

namespace App;

class SomeClass
{
    public function __construct(SomeOtherClass $p1, int $p2 = 0, int $p3, string $p4 = 'p4')
    {
        // $p1 is the instance returned by $container->get(SomeOtherClass::class);
        // $p2 value is 2
        // $p3 value is 3
        // $p3 value is 'p4'
    }
}
<?php

namespace App;

use Some\Psr11Container;

use Ellipse\Resolvable\DefaultResolvableClassFactory;

// Some Psr-11 container.
$container = new Psr11Container;

// Resolve SomeClass. $resolved value is an instance of SomeClass.
$factory = new DefaultResolvableClassFactory;

$resolved = $factory(SomeClass::class)->value($container, [2, 3]);