What is Willowgarden? Day -2: Data
We’re halfway through the business week here, and Arbor Day is coming up fast! What’s so special about Arbor Day, you ask? Well, it’s a great opportunity to celebrate the beauty and wonder and incredible usefulness of trees — in particular by planting some. It’s also a day when the Willowgarden project will be officially launched. We’ve already talked about how Willowgarden helps with PHP application security and access control as well as customization and extensibility via events and the Observer pattern. Now let’s talk about data.
Data is all around us. It’s moving through your house or office walls, and it’s flying through the air even as we speak. In fact, there’s data going through your body right now. (Can’t escape those radio waves!) There is not one single PHP application ever written, not one single Web site on this planet, that is not dealing with data.
The question is, how are you going to deal with it? How do you load and save data? How do you format it? What kind of content does it contain? What sort of structural integrity does it have that needs protecting?
We can boil this down to two points: what software storage medium holds your data, and what format the data’s content uses. As most PHP developers know, the question of what storage medium to use is easy: use a dedicated database such as MySQL. And the format is typically just rows of fields of text and numbers (and occasionally binary data) in a database table. However, that’s where the easy part stops. Translating data to and from a database via SQL queries can be complicated, and the complication grows as the application moves to an object-oriented paradigm using concrete data objects. The translation of data between objects and a database, often called object-relational mapping, or ORM, is an incredibly complex subject dominated by computer science wizards and Ph.D.’s.
Then there’s the fact that some data objects are going to represent not just rows of database fields, but are going to represent file formats such as XML. And those files themselves may be stored in a database, or some other advanced storage medium, or maybe even plain old files on a server. There must be a better way to mange all this data than writing new classes from scratch every time there’s a new data format or storage medium to deal with, and if there is a better way, it has to be simple enough to use in a manner suitable for production use as well as rapid prototyping.
And what about data validation? How do you know the data coming in from an input source matches what the format expects? What about semantic integrity? Most bugs in PHP applications are related to low-level problems with data handling. What about language support, which requires support for Unicode/UTF-8? This is, after all, the Internet! Why is this all harder that it should be?
Willowgarden aims to solve these problems by providing an abstracted data mapping layer that allows data objects to load and save field data from multiple formats and multiple storage mediums. When support for a new format or storage medium is required, you can just write a new data mapper rather than rewrite a bunch of data object classes. In addition, core support for extensible data validation, security, international languages, and output escaping for XHTML means that you can spend less time making data work and more time making that data work for you.

Del.icio.us
Cosmos
Digg