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

feat: add support for Enum casts, Attribute-based accessors, Output Modifiers #14

Draft
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

superbiche
Copy link

@superbiche superbiche commented Mar 28, 2022

This is an early PR to open a discussion on the following improvements (see #3):

  • Generate types for Eloquent Model "enum" casts
  • Generate TS enums for these Enums so we can use those during runtime (Enum must implement a new ModelEnum interface to be picked)
  • Generate properties for the new Attribute-based accessors
  • Introduce the concept of OutputModifiers to create a pipeline of modifiers that will change the generated content before its written to a file
  • Add strict types declaration

What must be done before merging it:

  • Write tests
  • Update README
  • ?

What would be nice to have, but can totally be done later:

  • Reduce code duplication (phpClasses() / phpEnums)
  • Maybe refactor AbstractGenerator so it's less coupled to classes and also allows enums
  • Don't hardcode the Enum suffix, make it configurable
  • Don't hardcode the EnumArray suffix, make it configurable

This is a "quick and dirty" implementation that was written on the go for a project I'm working on, but it works quite well - right now we can use the generated typings as-is without modifying those manually.

It does need some polishing before merging it.

Also I've copied the files from what I've written by hand so there may be a few typos, missing use statements...
I just wanted to publish it as soon as possible to collect feedback, and take some time the next weekend to polish it accordingly.

Thanks in advance for your feedback :)

@superbiche superbiche force-pushed the feat/enum-attributes-codegen branch from 0e8e870 to c4bb775 Compare March 28, 2022 21:36
@superbiche superbiche mentioned this pull request Mar 28, 2022
@lepikhinb
Copy link
Owner

Thanks for the PR! I’m going to review it and give a more detailed answer once I’m at the workplace.

@superbiche superbiche force-pushed the feat/enum-attributes-codegen branch from c4bb775 to 5ed0fdc Compare March 28, 2022 21:39
@tcampbPPU
Copy link

Very interesting approach! @superbiche I was working on similar functionality over at https://github.com/fumeapp/modeltyper
What all is difference between ReflectionEnumBackedCase instead of using something like:

$enum = (new ReflectionEnum($enumClass));
$enum->getConstants()

I am still trying myself to figure out all the new reflection stuff for enums

@rollsover
Copy link

@superbiche Why was PR abandoned? There is information?

@superbiche
Copy link
Author

@rollsover nope, it's waiting for a review by the maintainer

@rollsover
Copy link

@lepikhinb need review

@rollsover
Copy link

@superbiche can you remove the "draft" mark and put a reviewer?

@superbiche superbiche marked this pull request as ready for review October 9, 2023 16:44
@superbiche superbiche marked this pull request as draft October 9, 2023 16:44
@superbiche
Copy link
Author

@rollsover nope, I can't add a reviewer and there's still some work left like writing tests & docs. I'd like to get a review first before spending time on tests and documentation. But feel free to review it too!

@Healyhatman
Copy link

+1

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.

5 participants