2020use ReflectionParameter ;
2121use Throwable ;
2222
23+ use function is_array ;
24+
2325class Builder extends Engine
2426{
2527 /**
@@ -30,8 +32,11 @@ class Builder extends Engine
3032 * @return T
3133 * @throws AdapterException
3234 */
33- public function build (string $ class , Set $ set = new Set ([]) , array $ path = []): mixed
35+ public function build (string $ class , array | Set $ set = [] , array $ path = []): mixed
3436 {
37+ if (is_array ($ set )) {
38+ $ set = Set::createFrom ($ set );
39+ }
3540 try {
3641 return $ this ->make ($ class , $ set , $ path );
3742 } catch (AdapterException $ error ) {
@@ -56,7 +61,8 @@ protected function make(string $class, Set $set, array $path = []): mixed
5661 $ parameters = $ target ->getReflectionParameters ();
5762 if (empty ($ parameters )) {
5863 /* @phpstan-ignore return.type */
59- return $ target ->getReflectionClass ()->newInstance ();
64+ return $ target ->getReflectionClass ()
65+ ->newInstance ();
6066 }
6167
6268 $ resolution = new Resolution ();
@@ -65,7 +71,8 @@ protected function make(string $class, Set $set, array $path = []): mixed
6571
6672 if (empty ($ resolution ->errors ())) {
6773 /* @phpstan-ignore return.type */
68- return $ target ->getReflectionClass ()->newInstanceArgs ($ resolution ->args ());
74+ return $ target ->getReflectionClass ()
75+ ->newInstanceArgs ($ resolution ->args ());
6976 }
7077 throw new AdapterException ($ set , $ resolution ->errors ());
7178 }
@@ -77,7 +84,10 @@ protected function make(string $class, Set $set, array $path = []): mixed
7784 private function resolveParameters (Resolution $ resolution , array $ parameters , Set $ set , array $ path ): void
7885 {
7986 foreach ($ parameters as $ parameter ) {
80- $ nestedPath = [...$ path , $ parameter ->getName ()];
87+ $ nestedPath = [
88+ ...$ path ,
89+ $ parameter ->getName (),
90+ ];
8191 $ resolved = (new ValidateValue (notation: $ this ->notation , path: $ nestedPath ))
8292 ->then (new DependencyValue (notation: $ this ->notation , path: $ nestedPath ))
8393 ->then (new BackedEnumValue (notation: $ this ->notation , path: $ nestedPath ))
0 commit comments