Validate namespace definition

1

PHP variables, if necessary, can be validated with the following Regular Expression:

[a-zA-Z_\x7f-\xff][a-zA-Z0-9_\x7f-\xff]*

But what about namespaces ?

I have a certain string, coming from a form, which will serve as the name of a directory which will contain classes with namespaces .

Let's take this fully functional Application that I use as the playground of tests, whose part of the structure from the root directory, is:

|-\application
| \-\application\dovahkiin
|   |-\application\dovahkiin\application.php

The expression to be validated in this case would be the word dovahkiin .

And how do I keep the autoloading process simple, that is, just replacing the T_NS_SEPARATOR () with the DIRECTORY_SEPARATOR of the operating system, and finally concatenating the file extension (assim ), I need this string to be valid as part of a namespace .

I already know that non-alphanumeric characters, such as periods and spaces, are invalid, but I'm not sure if the same Regular Expression used for variables would be valid for namespaces as well.

    
asked by anonymous 04.12.2014 / 14:20

0 answers