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

Object translator No.2 #432

Merged
merged 3 commits into from
Feb 2, 2023
Merged

Object translator No.2 #432

merged 3 commits into from
Feb 2, 2023

Conversation

milo
Copy link
Collaborator

@milo milo commented Jan 2, 2023

Another approach of #429

API is:

Connection::setObjectTranslator(string $class, callable $translator): void

# e.g.
$connection->setObjectTranslator(Email::class, fn($email) => new Expression('?', $email->address));

If you consider it useful, last commit changes API and the target class is detected from $translator parameter typehint:

Connection::setObjectTranslator(callable $translator): void

# e.g.
$connection->setObjectTranslator(fn(Email $email) => new Expression('?', $email->address));

The Translator is now capable to translate objects into Expression via object translators registered by the Connection.
@dg
Copy link
Owner

dg commented Feb 2, 2023

Thanks!

@dg dg merged commit 19e349e into dg:master Feb 2, 2023
@milo
Copy link
Collaborator Author

milo commented Feb 4, 2023

Thank you! This helps me a lot!

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

Successfully merging this pull request may close these issues.

2 participants