New Clay Controller

I pushed Clay Framework to Github (http://github.com/clay/clay) almost 2 weeks ago. Well, I’ve been digging through the code a lot since then and came to a few conclusions. 1) I don’t really like some of my implementations. 2) I do love the basic ideas behind Clay in general. 3) I don’t really like some of my implementations. So, I picked up my digital sledge hammer and starting hacking.

First of all, I don’t think my implementations were bad, per se, they just looked 2 years old (most almost are). Almost everything has been procedural, mostly using static class methods and variables. It has been really fast, performance-wise, but I think I can make it fast object-oriented as well. Ok, now on to the good part:

I took my App and Tpl classes, which were completely static, and merged them into a single Controller class. The reason I hadn’t done this before was because I had a misconception about the way objects work in PHP 5. I thought if I assign an object to two different variables then I’d have two copies of that object. I was wrong. I merely have two more ways to interact with the same object! So, instead of having to call static class methods all over the place, such as in an application function, I pass $this from the Controller to the application function. Whatever that function does to the object the next function can see and use as well. By using a single Controller class to control applications and templates, I’ve essentially created a singleton pattern, without having to ever store the object in a static method. I had been using a static Data class to store/transfer data between functions and classes. It was my singleton class, but now I may not need that class at all.

I had been wanting to move toward an object-oriented model, but was afraid of a decrease in performance. I had envisioned doing it using a singleton pattern and passing the objects around, but thought the objects would be individuals (clones essentially), rather than the same objects. I haven’t pushed the new controller yet. I want to do some more testing and cleaning. I’m thinking I will probably get rid of the Data class, but it may be necessary to keep on for Clay APIs to utilize. I’m almost tempted to do away with the Clay class as well, but I don’t think I’ll do that just yet. There’s still lots of testing to do, but I guess I won’t be worrying if I should have made it object-oriented anymore.

I’ll probably push the new controller in a few days. Then, maybe, I’ll begin pushing the Installer.

Tags:

Leave a Comment