Number 41

Posted: January 19, 2007 by Ted Kulp

Ok, so I keep spouting off about the goals of CMSMS 2.0. At this point, there are like 40 goals and all are equally important. You've heard it all before... Oh well, I'm bringing up #41 #41: Serious, concise, functional and documented API. What does this mean? CMSMS 1.x has an API of sorts. The module creation parts of the API are probably the most organized of the bunch. Most other parts of the CMSMS code are scattered through out smarty plugins, global functions, poorly named classes that should be called staticly, etc. One of the things I took on early in the 2.0 development cycle was the formulation of a consistent API to work from. And honestly, the lib/classes directory was on the right track. It just wasn't implemented as well as it could. Live and learn... 1.0.x has too many global functions for doing random things. I wanted to cut all this out. Also, there are too many $gCms->GetSomethingOperations() methods. This is stuff that can all be moved to static methods in classes. index.php and include.php were both WAY too messy. I wanted to offload a lot of that stuff into clearly marked methods, using as much DRY (don't repeat yourself) development as I could. And, I wanted to "namespace" all of the CMSMS classes so that they don't get in the way of other classes that might be used for modules, addons, etc to the system. Since PHP doesn't use real namespacing, every class starts with Cms (CmsTemplate, CmsApplication, etc). Because of this consolidation, I could take advantage of the autoloading feature in php5. So I get two benefits with this... no require(_once) statements littering the code, and no files loaded into memory that aren't needed. So, at this point, 90% of the CMSMS code has been converted to this API setup. index.php and include.php are readable, and memory usage is way down. In fact, I've segmented it in such a way that it could almost be used as an API for other php applications. As an example, the new installer is a totally separate application. It doesn't use anything really CMSMS specific, instead it just includes the bare minimum and pulls out what methods it needs for the database, smarty, etc. I've also documented the code as I'm going. There is still a lot more to go, but it's coming along. We'll be dumping doxygen docs nightly so that people will have quick access to the classes and methods. I've already been dumping docs of the svn builds out, though it's not guaranteed to not change drasticly before 2.0 is released. Maybe someday we can break out the API and have a framework for other apps to use. That would be pretty slick. Ted

Our Partners: