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

Add CustomType class to let use convertToPHPValue method instead of closureToPHP #1510

Conversation

mgonzalezbaile
Copy link
Contributor

Issue #1509

@mgonzalezbaile mgonzalezbaile changed the title Add CustomType class to let use convertToPHPValue instead of closureToPHP Add CustomType class to let use convertToPHPValue method instead of closureToPHP Oct 12, 2016
// 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);';
Copy link
Contributor Author

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();
Copy link
Member

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

Copy link
Contributor Author

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 from Type 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?

Copy link
Contributor Author

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.

@malarzm
Copy link
Member

malarzm commented Oct 18, 2016

Closing in favour of #1513

@malarzm malarzm closed this Oct 18, 2016
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