Skip to content

Conversation

Robertbaelde
Copy link
Contributor

This is a breaking change, since the interface of the caster changes. So probably need to be queued for a major release.

In my casters I sometimes need the expected type. Eg: when casting a EventSauce Id It is cumbersome to pass the expected ID class to the caster when it is already typehinted in the constructor

final readonly class SomeCommand
{
    public function __construct(
        #[IdCaster(AuthorId::class)]
        public AuthorId $authorId,
    ) {}
}

The expected type is already known in the hydrator, so with this PR we can change the caster to:

final readonly class SomeCommand
{
    public function __construct(
        #[IdCaster]
        public AuthorId $authorId,
    ) {}
}

Or even register it is default caster, so we don't have to annotate our ID's anymore.

This is a breaking change, since the interface of the caster changes

@axlon
Copy link
Contributor

axlon commented Jul 5, 2024

@Robertbaelde I am looking for similar functionality, wouldn't it be possible to do this without a breaking change if we created 2 new interfaces and deprecated the older ones (whilst still supporting them)?

@cooperaj
Copy link
Contributor

cooperaj commented Jun 6, 2025

I quite like the potential solution outlined in #68. Rather than just giving the type as a string passing in the full context of the definition could allow all sorts of fun things.

public function cast(
    mixed $value, 
    ObjectMapper $hydrator, 
    ?PropertyHydrationDefinition $context = null,
): mixed

Would be nice to get some sort of solution in for value objects though. Whatever route is taken.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

3 participants