Skip to content

Add type mapping support for container ID override #35

Description

@henriquemoody

The Resolver resolves parameters by looking up types directly in the container using ->get(). This doesn't work when:

  1. Multiple implementations of an interface exist in the container, and you need to specify which one
  2. Services are registered with string aliases (e.g., 'my.favorite.animal') instead of class names

Currently there's no way to tell the Resolver "when this callable needs an Animal, look up 'my.favorite.goat' from the container."

Introduce a new interface ParameterResolverWithTypeMap extending ParameterResolver with an additional method:

interface ParameterResolverWithTypeMap extends ParameterResolver
{
    public function resolveWithTypeMap(
        ReflectionFunctionAbstract ,
        array ,
        array<string, string> 
    ): array;
}

Usage:

$args = $resolver->resolveWithTypeMap(
    $reflection,
    $arguments,
    [Animal::class => 'my.favorite.goat']
);

The Resolver class would implement both interfaces, maintaining backward compatibility.

Additional context

This approach preserves backward compatibility - existing code using ParameterResolver continues to work unchanged. Clients can build the type map externally based on their needs and pass it at call time.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions