fiveorbs/wire

Autowiring object creator and callable argument resolver

dev-main 2024-11-17 17:20 UTC

This package is auto-updated.

Last update: 2024-11-17 17:20:15 UTC


README

Software License Codacy Badge Codacy Badge Psalm level Psalm coverage

Warning

This library is under active development, so some of the features listed and parts of the documentation may be still experimental, subject to change, or missing.

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.

Wire is a PHP dependency injection tool that automatically constructs objects by resolving their dependencies. Using PHP's reflection API, Wire recursively analyzes and fulfills constructor arguments without manual configuration. It additionally includes utilities for resolving dependencies in various callable types—including functions, methods, closures, and class constructors. *Wire seamlessly integrates with PSR-11 compliant dependency injection containers.

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

Installation

composer require fiveorbs/wire

Basic usage

use FiveOrbs\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

FiveOrbs Wire is released under the MIT license.

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