Skip to content

Override all object properties type to string #4216

Answered by ondrejmirtes
mvorisek asked this question in Support
Discussion options

You must be logged in to vote

So:

  1. Make MagicModelField generic, it will carry the class it's describing (User in your example).
  2. Create a dynamic return type extension (https://phpstan.org/developing-extensions/dynamic-return-type-extensions) that describes Model::fieldName().
  3. This extension needs to return new GenericObjectType(MagicModelField::Class, [new ObjectType('X')]) when X::fieldName() is called.
  4. Write PropertiesClassReflectionExtension (https://phpstan.org/developing-extensions/class-reflection-extensions#properties-class-reflection-extensions) for MagicModelField. In the hasProperty method, you'll inspect the incoming ClassReflection (it should be for MagicModelField), and you'll ask about ClassReflection::…

Replies: 3 comments 7 replies

Comment options

You must be logged in to vote
1 reply
@mvorisek
Comment options

Comment options

You must be logged in to vote
6 replies
@ondrejmirtes
Comment options

@ondrejmirtes
Comment options

@mvorisek
Comment options

@mvorisek
Comment options

@ondrejmirtes
Comment options

Answer selected by mvorisek
Comment options

You must be logged in to vote
0 replies
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Support
Labels
None yet
2 participants