Skip to content

Object translator No.2#432

Merged
dg merged 3 commits intodg:masterfrom
milo:pull-serialize-object3
Feb 2, 2023
Merged

Object translator No.2#432
dg merged 3 commits intodg:masterfrom
milo:pull-serialize-object3

Conversation

@milo
Copy link
Copy Markdown
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));

milo added 3 commits November 22, 2022 10:46
The Translator is now capable to translate objects into Expression via object translators registered by the Connection.
@milo milo force-pushed the pull-serialize-object3 branch from 2fafcc9 to 3037a8d Compare January 2, 2023 16:36
@dg
Copy link
Copy Markdown
Owner

dg commented Feb 2, 2023

Thanks!

@dg dg merged commit 19e349e into dg:master Feb 2, 2023
@milo
Copy link
Copy Markdown
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