conia/wire

Autowiring object creator and callable argument resolver

0.3.0 2024-01-18 18:49 UTC

This package is auto-updated.

Last update: 2024-12-21 14:58:27 UTC


README

Software License Codacy Badge Codacy Badge Psalm level Psalm coverage

Wire provides an autowiring object creator that utilizes PHP's reflection capabilities to automatically resolve constructor arguments recursively. It additionally comes with classes that assist in resolving arguments of callables such as functions, methods, closures or class constructors. It can be combined with a PSR-11 dependency injection container.

Documentation can be found on the website: conia.dev/wire

Installation

composer require conia/wire

Basic usage

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');

License

Conia Wire is released under the MIT license.

Copyright © 2023-2024 ebene fünf GmbH. All rights reserved.