celema / wire
Autowiring object creator and argument resolver
Requires
- php: ^8.5
- psr/container: ^2.0
Requires (Dev)
- carthage-software/mago: 1.50.0
- ernst/coverlyzer: ^0.3
- infection/infection: 0.35.6
- phpunit/phpunit: ^13.0
- vimeo/psalm: 6.19.0
Suggests
None
Provides
None
Conflicts
None
Replaces
None
README
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: celema.dev/wire
Installation
composer require celema/wire
Basic usage
use Celema\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');
Scoped container usage
When you pass a scoped container to Creator, callable resolvers and Inject entry lookups resolve against that current scope first.
This allows parent-owned definitions (for example root shared services) and scope-local overrides (for example request-local values) to work together safely.
Creator::resolve() returns a registered entry from the container, so its lifetime applies. Creator::create() bypasses that lookup and invokes the class constructor or a specified factory method, using the container only for its parameters. A constructor produces a new instance; a factory method controls whether its result is new or reused.
Mutation testing
Mutation testing with Infection is not part of composer ci, but the CI workflow runs it after the coverage step and enforces the minimum mutation score from infection.json5.dist. Pushes only mutate the changed lines; a weekly scheduled run covers the whole codebase. Run it locally with:
composer mutation
Reports are written to .infection/.
License
This project is licensed under the MIT license.