Is there a way to use toString template in phpStorm like in InteliJ?
In my classes I need to implenet `jsonSerialize` method. I'm aware that I can't add my own code generator, but I thought that I can change velocity templates for similar method like `toString`. Both methods get class properties and build some custom output. However in phpStorm there is no such method in code templates. I found a nice plugin https://plugins.jetbrains.com/plugin/10098-code-generator but it is dedicated only for InteliJ.
Is there a way to overwrite some template, which has got access to class properties or create own code generator other then writing own plugin?
Please sign in to leave a comment.
I was thinking about following entry: https://www.jetbrains.com/help/idea/generating-code.html and "Generate toString()" section. In Java it will generate following method:
What I need in php is almost the same implementation as toString for JAVA but for JSON representation when encoded with json_encode -> https://php.net/manual/en/jsonserializable.jsonserialize.php
Live Template and File Template can't do it. I need to read class properties (like generate getters and setters is doing) and then generate one method with all properties. Something like that:
Hi there,
Please clarify what exactly do you mean by "toString template"? How do you generate it?
P.S. Maybe you can just use what's already available and then use custom Live Template to quickly insert your own code..? https://confluence.jetbrains.com/display/PhpStorm/Live+Templates+%28Snippets%29+in+PhpStorm
+1
Hi, I also looking for a way to generate the __toString() php method with my serialized object.
Exactly what IntelliJ does with a Java object.
If there is a feature to vote or a dedicated plugin, thanks to share.
Thanks for creating a feature request. If anyone is interested here's a link to it: https://youtrack.jetbrains.com/issue/WI-46446
+1 jsonSerialize generator will totally be helpful!