Skip to content

Commit 35418ce

Browse files
committed
feat: add interface wiring
1 parent 437bdde commit 35418ce

File tree

2 files changed

+400
-381
lines changed

2 files changed

+400
-381
lines changed

src/Autowire.php

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,4 +74,25 @@ public function run(): mixed
7474
}
7575
return $this->class;
7676
}
77+
78+
/**
79+
* Will wire the interface to the expected instance
80+
*
81+
* @param array $bindings
82+
* @return void
83+
*/
84+
public static function interfaceWiring(array $bindings): void
85+
{
86+
Reflection::interfaceFactory(function (string $className) use ($bindings) {
87+
$instance = $bindings[$className] ?? null;
88+
if (is_callable($instance)) {
89+
$instance = $instance();
90+
}
91+
if(is_string($instance)) {
92+
$di = new self($instance);
93+
$instance = $di->run();
94+
}
95+
return $instance;
96+
});
97+
}
7798
}

0 commit comments

Comments
 (0)