Skip to content

Commit

Permalink
Don't resolve injector if constructor arguments are passed
Browse files Browse the repository at this point in the history
  • Loading branch information
roxblnfk committed Jan 2, 2024
1 parent 2a0f48e commit b80910f
Showing 1 changed file with 9 additions and 9 deletions.
18 changes: 9 additions & 9 deletions src/Core/src/Internal/Factory.php
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@ private function resolveInjector(Injectable $binding, Ctx $ctx, array $arguments

return $instance;
} finally {
$this->state->bindings[$reflection->getName()] ??= $binding;
$this->state->bindings[$ctx->class] ??= $binding;
}
}

Expand Down Expand Up @@ -385,7 +385,7 @@ private function validateNewInstance(
* @template TObject of object
*
* @param Ctx<TObject> $ctx
* @param array $parameters Constructor parameters.
* @param array $arguments Constructor arguments.
*
* @return TObject
*
Expand All @@ -394,7 +394,7 @@ private function validateNewInstance(
*/
private function createInstance(
Ctx $ctx,
array $parameters,
array $arguments,
): object {
$class = $ctx->class;
try {
Expand All @@ -409,9 +409,9 @@ private function createInstance(
throw new BadScopeException($scope, $class);
}

//We have to construct class using external injector when we know exact context
if ($this->binder->hasInjector($class)) {
return $this->resolveInjector($this->state->bindings[$ctx->class], $ctx, $parameters);
// We have to construct class using external injector when we know the exact context
if ($arguments === [] && $this->binder->hasInjector($class)) {
return $this->resolveInjector($this->state->bindings[$ctx->class], $ctx, $arguments);
}

if (!$reflection->isInstantiable()) {
Expand All @@ -431,7 +431,7 @@ private function createInstance(
try {
$this->tracer->push(false, action: 'resolve arguments', signature: $constructor);
$this->tracer->push(true);
$arguments = $this->resolver->resolveArguments($constructor, $parameters);
$args = $this->resolver->resolveArguments($constructor, $arguments);
} catch (ValidationException $e) {
throw new ContainerException(
$this->tracer->combineTraceMessage(
Expand All @@ -448,9 +448,9 @@ private function createInstance(
}
try {
// Using constructor with resolved arguments
$this->tracer->push(false, call: "$class::__construct", arguments: $arguments);
$this->tracer->push(false, call: "$class::__construct", arguments: $args);
$this->tracer->push(true);
$instance = new $class(...$arguments);
$instance = new $class(...$args);
} catch (\TypeError $e) {
throw new WrongTypeException($constructor, $e);
} finally {
Expand Down

0 comments on commit b80910f

Please sign in to comment.