The di plus component for Hyperf.

v3.1.41 2024-09-25 00:28 UTC

README

Latest Stable Version Total Downloads GitHub license

The di plus component for Hyperf.

Installation

composer require friendsofhyperf/di-plus

Usage

<?php
// config/autoload/dependencies.php
return [
    'App\Bar@App\Foo1' => App\BarAtFoo1Factory::class,
    'App\Bar@App\Foo2' => App\BarAtFoo2Factory::class,
];
<?php
namespace App;

class Foo1
{
    public function __construct(public Bar $bar)
    {
    }
}

class Foo2
{
    public function __construct(public Bar $bar)
    {
    }
}

支持注解的方式

<?php
namespace App;

use Hyperf\Di\Annotation\Inject;

class Foo1
{
    #[Inject]
    public Bar $bar;
}

class Foo2
{
    #[Inject]
    public Bar $bar;
}

Contact

License

MIT