Sunday, January 6, 2013

PHP: declarative property validation through document

Here is an attempt to define validation rules in document metadata and read it through reflection to validate the property against metadata. The metadata should be a valid json (verify using jsonlint.org).

Keeping it in metadata has the following benefits:

1. keeps it close to the property
2. easier to manage and read ( otherwise a complex structure if specified in another attribute )
3. is cool to do

Having type to php violates the dynamically typed nature of it. This is only in case you need it.

No comments: