conia / wire

自动装配对象创建器和可调用参数解析器

0.3.0 2024-01-18 18:49 UTC

This package is auto-updated.

Last update: 2024-09-21 14:32:00 UTC


README

Software License Codacy Badge Codacy Badge Psalm level Psalm coverage

Wire 提供了一个自动装配对象创建器,它利用 PHP 的反射功能递归地自动解析构造函数参数。它还包含帮助解析函数、方法、闭包或类构造函数等可调用参数的类。它可以与 PSR-11 依赖注入容器结合使用。

文档可以在网站上找到: conia.dev/wire

安装

composer require conia/wire

基本用法

use Conia\Wire\Wire;

class Value
{
    public function get(): string
    {
        return 'Autowired Value';
    }
}

class Model
{
    public function __construct(protected Value $value) {}

    public function value(): string
    {
        return $this->value->get();
    }
}

$creator = Wire::creator();
$model = $creator->create(Model::class);

assert($model instanceof Model);
assert($model->value() === 'Autowired Value');

许可

Conia Wire 在 MIT 许可 下发布。

版权所有 © 2023-2024 ebene fünf GmbH。保留所有权利。