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

Generating the Normalizer / Denormalizer Class #42

Closed
joelwurtz opened this issue Jan 21, 2016 · 14 comments
Closed

Generating the Normalizer / Denormalizer Class #42

joelwurtz opened this issue Jan 21, 2016 · 14 comments

Comments

@joelwurtz
Copy link

@joelwurtz joelwurtz commented Jan 21, 2016

Since we have all informations about a class and its properties, it should be easy to generate normalizer and a denormalizer compatible with the symfony interface.

I believe the performance of such generated normalizer would be better than using PropertyAccess (as it would plain php object only using simple methods).

However using templates for such generation is really a pain and it would be better to generate an AST which will then be transformed into PHP code.

I have done this in this library (for json schema) https://github.com/jolicode/jane and maybe we can collaborate to use this principle for schema.org model, WDYT ?

@dunglas

This comment has been minimized.

Copy link
Member

@dunglas dunglas commented Jan 21, 2016

Using an AST would be indeed better on every aspects. 👍 to use it for this generator.

Btw, Jane is amazing, I've started to work on the reverse side: generating a JSON Schema from a PHP entity - https://github.com/dunglas/php-to-json-schema

@dunglas

This comment has been minimized.

Copy link
Member

@dunglas dunglas commented Jan 21, 2016

Generating a normalizer can be interesting but we are working on some improvements on the PropertyAccess component ant the Serializer Component that will drastically improve serialization performance after the first run (basically: cache everything in APC).

I'm not sure that generating a specific normalizer for every generated class is so interesting: you'll need to update the normalizer every time you manually edit the generated entity and it will not work for custom entites - on the other hand, the "standard" ObjectNormalizer always works.

@joelwurtz

This comment has been minimized.

Copy link
Author

@joelwurtz joelwurtz commented Jan 21, 2016

I'm not sure that generating a specific normalizer for every generated class is so interesting: you'll need to update the normalizer every time you manually edit the generated entity and it will not work for custom entites - on the other hand, the "standard" ObjectNormalizer always works.

But you can use the generated normalizer as the cache ? And since you will certainly have a opcode cache it would be faster than caching metadata and operation on the PropertyAccess ?

However yes the generated normalizer is only for generated class from schema.org and not custom entities.

But i also think we can generate normalizer in the same style for custom one:

Jane library is based on a guesser principle, if you can guess the class, its properties and types then the generation library can generate a normalizer.

I'm already working on guessing this 3 informations from the JmsSerializer library and also from doctrine metadata (only for the normalizer part).

@dunglas

This comment has been minimized.

Copy link
Member

@dunglas dunglas commented Jan 21, 2016

You can probably use the Symfony PropertyInfo Component to do that: http://symfony.com/blog/new-in-symfony-2-8-propertyinfo-component

It already supports Doctrine metadata, reflection, Symfony serializer...

How can we collaborate on this topic? Can you open a PR on this repo?

@joelwurtz

This comment has been minimized.

Copy link
Author

@joelwurtz joelwurtz commented Jan 21, 2016

Oh, didn't see this new component, very very interesting, i was actually thinking on something like that.

So basically what would be nice is to have a generation library based on the PropertyInfo Component which can generate Normalizer / Validator and other stuffs for POPO (plain old php object).

Then jane library would just have to transform json schema into property info object, and this one transform schema.org model into property info object, and both can then used the first library for generation.

Are you interested in something like that ?

@dunglas

This comment has been minimized.

Copy link
Member

@dunglas dunglas commented Jan 22, 2016

Yes it's a very interesting idea. Maybe can this POPO and normalizer generator can be a new Symfony Component. What do you think @fabpot?

@fabpot

This comment has been minimized.

Copy link

@fabpot fabpot commented Jan 22, 2016

Just read the whole thread. I must say that it makes me very excited! I can see all the awesomeness that this new component could provide to the Symfony ecosystem. Go for it! @joelwurtz If you want to collaborate on that, we (the Symfony core team) are eager to on-board some more core developers, such a project could be a good occasion for that :)

@joelwurtz

This comment has been minimized.

Copy link
Author

@joelwurtz joelwurtz commented Jan 22, 2016

Ok, then i will try to give a shot at a first implementation in the next days.

@joelwurtz

This comment has been minimized.

Copy link
Author

@joelwurtz joelwurtz commented Jan 22, 2016

Was planning to use https://github.com/nikic/PHP-Parser as a dependency for this component, but i'm wondering about the licence if it will be a problem for symfony ? (BSD-3 LICENCE)

@dunglas

This comment has been minimized.

Copy link
Member

@dunglas dunglas commented Jan 22, 2016

I'm not a license expert but the PropertyInfo Component already has a "suggest" entry for the phpDocumentator parser and it itself depends of Nikic's PHP Parser.

@joelwurtz

This comment has been minimized.

Copy link
Author

@joelwurtz joelwurtz commented Jan 22, 2016

Yes but in this case it will be a mandatory dependency, as AFAIK there is no other library that have a complete support for AST

@joelwurtz

This comment has been minimized.

Copy link
Author

@joelwurtz joelwurtz commented Jan 22, 2016

Also begin the work here : https://github.com/joelwurtz/symfony/tree/feature/AstGeneratorComponent, will do a PR once it have some concrete implementations

@fabpot

This comment has been minimized.

Copy link

@fabpot fabpot commented Jan 23, 2016

MIT/BSD are compatible, so no issues here.

@joelwurtz

This comment has been minimized.

Copy link
Author

@joelwurtz joelwurtz commented Jan 25, 2016

FYI , the PR is here : symfony/symfony#17516

@joelwurtz joelwurtz closed this Feb 4, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
3 participants
You can’t perform that action at this time.