How to create template of PHP class with dynamic number of members?

In my project, I will need to create many classes with similar structure, but with different number of member variables and member functions. I read about Live Templates, but could not find a way how to repeat code based on based on the list of members. How can I force template to read a list from the file, or request it as a parameter from me, and iterate through it to generate code ?


1 comment
Comment actions Permalink

Hi there,

Live Templates is not right tool for this .. as it basically a code snippets with some basic operations on variables/placeholders -- it cannot itterate etc.

You may look at File Templates [ 1 ], [ 2 ] which is powered by Velocity Template Language and can do iterations and other transformations (be it built-in functions or actual standard Java functions). You will need to learn more about Velocity in order to make such dynamic generation -- you will not achieve it in "few click only" fashion.

If question is about generating getters/setters .. then just use standard approach -- create class and add all fields in "normal way" (typing them) and then use "Code | Generate...".


Please sign in to leave a comment.