Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cast using expected type #65

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

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)?

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.

2 participants