-
-
Notifications
You must be signed in to change notification settings - Fork 508
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
Add CustomType class to let use convertToPHPValue method instead of closureToPHP #1510
Add CustomType class to let use convertToPHPValue method instead of closureToPHP #1510
Conversation
// Note: this code ends up in the generated hydrator class (via HydratorFactory) | ||
public function closureToPHP() | ||
{ | ||
return '$return = array_map(function($v) { if ($v instanceof \MongoDate) { $date = new \DateTime(); $date->setTimestamp($v->sec); return $date; } else { return new \DateTime($v); } }, $value);'; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just extracted the code from quotes and put it inside convertToPHPValue
while keeping the test green.
|
||
return sprintf(' | ||
$reflection = new \ReflectionClass("%s"); | ||
$type = $reflection->newInstanceWithoutConstructor(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think that instead of using reflection we could add a method that would get Type
instance by its FQCN
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If I am not missing anything, in order to get the instance of Type
I can do it by:
- constructor: which is defined as
final private
in the base class. - factory method: current factory methods instantiate
Type
from the custom type identifier (key in$typesMap
array fromType
class). I don't see a way to get the custom type identifier so I can make use of any factory method.
Am I right?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I have pushed PR #1513 avoiding reflection to instantiate Type
, let me know your thoughts.
Closing in favour of #1513 |
Issue #1509