Created by: hinrik
Resolves issue #4328 and allows full use of referenced enums for PHP. This change might also make it easier to address the issue discussed in #3186.
Without this change, referenced enums are not fully usable in PHP (and possibly other languages which don't have native enums). This is because the setter for such a property would expect an instance of the external enum class as the value, and that class has no state (and was therefore a meaningless value) (see #4328).
On properties which reference enum schemas, CodegenProperty
has a new
field (referencedEnumType
) which contains the enum value data type of a
referenced schema. This allows generators for languages that don't have native
enums to easily work with the primitive type instead.
I adjusted the PHP model template to make use of this new variable, so that it now generates very similar code for referenced enum properties as it does for inline ones: the setter accepts a primitive type and validates the value. The only difference is that the allowed values are stored on the external enum class rather than inline on the model.
There was also some syntactically invalid PHP code being generated for
referenced enums containing purely numeric values. To account for the
differences in code generation between inline and referenced enums, the
toEnumVarName()
method now receives an extra parameter indicating
whether the enum is on its own model class. In the case of PHP this allows
selectively prefixing the name with an underscore (while avoiding a
superfluous underscore on inline enums, which already have a prefix).