mirror of
https://github.com/doctrine/orm.git
synced 2026-03-24 06:52:09 +01:00
[Question] Is there a way to infer custom parameter type automatically? #5581
Reference in New Issue
Block a user
Delete Branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Originally created by @aledelgo on GitHub (Jun 20, 2017).
Originally assigned to: @Ocramius on GitHub.
Scraping the code i've noticed that it is about impossible to change the implementation of
ParameterTypeInfererwith own custom code.It seems to me impossible also to change the
setParameterfunction of class Query because it is declared final.The problem is i want to automatically infer my custom type when the value of a parameter is an instance of a certain class.
To be precise, i'm in Laravel and i'm using extensions to use the Carbon type.
I've a custom Carbon type that take in consideration the timezone of the date value and convert it to UTC (or the default timezone set in the config) in the
convertToDatabaseValuefunction.If in the queries i don't set the parameter type, the value (a Carbon instance) will be detected as a Datetime instance and my custom 'toUTC' conversion will never happen (convertToDatabaseValue never called). If i explicitly set the type of parameter with "CustomCarbonDatetimeType", my
convertToDatabaseValueis called and the conversion to UTC works fine!Now, as my entire system works with datetime only in UTC and (as many systems do) , don't store the timezone information in the DB considering all values to be in the same (UTC) timezone, i would like that wherever i use a Carbon instance as parameter value, the inferred parameter type should be "CustomCarbonDatetimeType".
Is there an elegant, not too much disrupting, way to do this?
Thanks
@Ocramius commented on GitHub (Jun 20, 2017):
No, it's not designed to support that.
Pass in the type explicitly.
@Ocramius commented on GitHub (Jun 20, 2017):
See also https://github.com/doctrine/doctrine2/issues/6443
@aledelgo commented on GitHub (Jun 20, 2017):
ok, thanks!