Code Generation Templates HowTo?

Hi there!

I’d like to create my own code generation templates for PHP but I can’t find any documentation about that feature, neither by googling nor in the VP help.

Is there any documentation around? What language is it anyway?

Is it possible to modify operation.t_getDocumentation()? Unfortunately, the default documentation it spits out is not the way PHP programmers commonly do it.

Thanks in advance!

Trying to build my own PHPDoc block generator I found out that VP eats away the parameter types ($parameter.t_getTypeName() returns nothing) in case it is {String, Boolean, Integer, Float}. In case it’s Array, it gets lowercased.

Since I’m trying to build my own kind of doc blocks (is there another way of doing this?) I’d like to find out those types. I’d also like the Array type not to be lowercased by default, but rather left the way it was.

I’d suggest to add a special method that returns the type for the type hinting in the signature (where the previously named types should be omitted) and another one that always returns the correct parameter’s type.

Edit: Another issue is that the special PHP types ‘Resource’ and ‘Mixed’ should also be omitted as type hints in a function signature. Example:

 +test(a : Mixed, b : Resource) 

turns into

 public function test(Mixed $a, Resource $b) 

which is not correct because PHP doesn’t allow Mixed/Resource as type hint. Instead, PHP thinks they’re class names. They’re not, it’s just the PHP documentation way of saying that $a can be any type and $b should be a resource.

I’d suggest to add those two to the list of types to omit.

More on PHP types:

Hello Maarten,

Thanks for your post. We will check the problem and come back to you as soon as possible.

Best regards,

Hello Maarten,

Both the comment related to getting document and handling “Mixed” and “Resource” ‘keyword’ are implemented. Same as the other issue you reported, please download the patch that include the fix. Please read this for detail:

With the fix, you can modify the templates (.vm files) to make it generate the code you want. Two new methods are introduced:

$utilities.getOriginalName(THE_OBJECT, $args.get(“property”)) // Return original name
$utilities.getOriginalDocumentation(THE_OBJECT, $args.get(“property”)) // Return original documentation

You can define your own way of printing the documentation by combining your text withe the original documentation.

Below are some other methods are might be useful to you:

=== To get the type’s name (within .vm files) ===

=== To get the type/return type’s original name (within .vm files) ===
$utilities.getOriginalName($attribute.getType(), $args.get(“property”))
$utilities.getOriginalName($parameter.getType(), $args.get(“property”))
$utilities.getOriginalName($operation.getReturnType(), $args.get(“property”))

=== To get the original documentation (within .vm files) ===
$utilities.getOriginalDocumentation($attribute, $args.get(“property”))
$utilities.getOriginalDocumentation($parameter, $args.get(“property”))
$utilities.getOriginalDocumentation($operation, $args.get(“property”))

I understand this may not be that easy. But I do not want to make you confuse by writing so much. Could you try it take a look at the vm file, try it out, and let me know if you have any questions about the newly introduced method call? We will be happy to help you.

Best regards,

Thank you very much for your exceptional user support!

I will try to puzzle the documentation together with these methods. I guess there is no official documentation for templates then, is that correct?

Hello Maarten,

You are correct. Currently we do not have any documentation for template. I will let our team know about your need. Thank you once again!

Have a nice weekend!

Best regards,

Hello Maarten,

We now have a page that teaches user how to customize the code generation outcome. Please read:

We also setup a forum about customizing code generation:

I hope that you can find enough help. If not, feel free to contact me.

Best regards,