Alright guys, I can’t contain myself any longer. I have found an incredible framework called Propel (
http://propel.phpdb.org), based on the Apache Turbine project, which is a complete system for generating an object model from a database, which can then be used with any supported database platform. They currently support the following DB’s:
- MySQL
- PostgreSQL
- SQLite
- MS SQL Server
And they are currently completing development of Oracle support.
It has PHP 4 and PHP 5 runtimes and can generate the object model for either target runtime, so we’d have to have separate packages for PHP 4 and PHP 5, but it does support both.
In addition, I spent the weekend setting up Propel and two related projects which I will be talking more about in the upcoming weeks, Phing, a build tool based on the industry-standard Java build tool Ant, and Creole which provides Propel with with many cool features, including automatic DB->XML schema generation, XML->SQL, and many other useful data transformation tools. Phing would be perfect for preparing automated builds that take care of everything from running unit tests, to generating/transferring bootstrap installer files, to transferring the builds to proper download areas. And it’s as easy as writing XML (or you can extend Phing with PHP classes, known as Tasks). Creole will be handy for doing things like automatically generating create and upgrade scripts for the DB, and for each platform.
I’m customizing the Propel runtime and some of the generated classes to take advantage of some MODx infrastructure, working on loading classes on demand for performance sake, and testing the in’s and out’s of the framework. I’ve already completed a proof of concept; here’s what I’ve done:
* reverse engineered the current 0.9.1 DB using Creole, generating an XML schema of the structure
* used Propel to generate a complete PHP 5 object model for our core persistent objects
* modified the PHP 5 runtime and generated classes to respect our include_path restrictions (e.g. prefixed paths with the base_path setting)
* introduced new functions in DocumentParser to initialize the Propel engine and load classes from the model on demand, just before using them (so the whole object model does not have to be loaded on every request)
* replaced all the DB calls in the DocumentParser class with the appropriate object API calls and have it working with the default site content with the PHP 5 runtime, at roughly the exact same performance as 0.9.1
Here’s what I have planned next:
* refactor the XML schema to provide proper foreign key relationships, cascading delete flags, and indexes, then regenerate the MODx object model so the proper class relationships are generated by Propel
* refactor the entire core, moving API method implementations to the appropriate classes, and turning the core API calls into wrappers for those implementations for backwards compatability
* repeat everything for the Propel PHP 4 runtime
* create a Phing build process to prepare the PHP 4 and PHP 5 packages of MODx for distribution
* create a Phing build task to generate the appropriate SQL files for database creation AND upgrades, for every supported Propel platform
And more. Victor and I have been talking about how this system will allow us to incorporate (automated) unit testing, and additional automation for the bootstrap installer system. I haven’t been this excited about something in quite a while; complete DB abstraction, an OO framework in seconds, and build automation all in one fell swoop.
Thoughts, comments, gasps, or whatever are appreciated.