ZF2-326: Zend\Code\Generator allows invalid class/method/property names

Description

[ Cloned from ZF-7645 ]

Zend_CodeGenerator does not prevent invalid PHP class/method/property names. For example, it allows names with spaces, names beginning with numbers, and names containing non-alphanumeric characters. The Zend_CodeGenerator component should not create invalid code...it should either filter the names into usable values or throw an exception. Preferrably it filters the names (and any other invalid code) into valid, usable values.

An excellent example is having spaces in class (or method, or property) names...a simple solution would be to setup an inflection filter on the class name to convert spaces to camelcase or underscore...and this could perhaps be configurable.

On names beginning with numbers, we could either remove the number automatically, or prepend the name with an underscore (less desired though...underscore indicates a protected method/property).

Non-alphanumeric characters could be easily stripped with an Alnum filter.

This does nothing to address actual code validation inside methods...such as correct syntax. This would ideally be validated as well, but that is probably a separate issue in itself. A Zend_Validate class would need to be written for PHP code, and then used inside Zend_CodeGenerator. Probably have to throw an exception on invalid code...could be difficult and unreliable to attempt to correct it (but who knows, maybe someone out there can pull it off). The class/method/property names would be pretty easy to auto correct, but it might turn out that the best solution is exceptions also.

Comments

This issue has been closed on Jira and moved to GitHub for issue tracking. To continue following the resolution of this issues, please visit: https://github.com/zendframework/zf2/issues/2485