Clay’s controller has been in a state of transition lately. A few weeks ago I got rid of the static methods and made the controller a single large object. It worked OK, but after some experimenting I realized I had killed some of the flexibility the static methods had allowed. So, I went back to the drawing board. I then split the controller, which makes up the Sculpt library, into Application, Theme, Template, Sculpt, and Controller classes. Each class extended the one before it, which left room for someone to reuse the library under a different name and just swap the classes they didn’t want. It worked OK, but it was hard to read the code and know where a method or property was coming from. So, I went back to the drawing board.
The latest controller seems to be a better fit for Clay. I’ve basically combined the previous implementations, while focusing on readability and efficiency. The Controller class is a static class used for setting and returning named objects. The Theme, Application, and Template classes are mostly unchanged, other than a few optimizations. The Controller itself only manages the objects of other controllers. For instance, we load up the Theme controller by calling the method:
\clay\controller::object(‘theme’, new \sculpt\theme);
Now the Theme object can be used in any scope by calling:
\clay\controller::object(‘theme’);
Such as setting the page title from an application:
\clay\controller::object(‘theme’)->setPageTitle(‘Welcome to Hello World’);
One of the other changes in the latest implementation of the controller is I’ve moved the initialization of the Application and Template controllers out of the \clay\init function. This change is a little more efficient and allows custom configurations to be implemented a little more easily. The Application class initializes just before the Theme class begins loading it’s Page template. The Page template initializes the Template class, which leaves room for Smarty or another template engine to take over. The Sculpt class has been removed altogether, which makes it a little less confusing as far as browsing the files in the library.
My main goals with the Controller is to leave room for custom controllers, encourage optimized object models, and be as fast as plausible. I think we’re slowly moving in that direction. These changes have been pushed to the GitHub repo. There is still work to be done in Sculpt, most notably in the CSS and Javascript handlers, but also a few new features such as image handling and short urls. Please check it out and let me know what you think.

Recent Comments