As you all know, Joomla! 1.7 brought a major change in the direction of the project. The self-developed libraries upon which the Joomla! CMS is built on are now spun-off as a separate project, called Joomla! Platform. The goal of this split is to allow developers to built applications on the Joomla! Platform without having to install the Joomla! CMS and all the unnecessary cruft this brings with it. The vision is to have a standalone framework, much like Zend Framework, CakePHP, CodeIgniter or Symphony, with a twist. It will be equally easy to create a component for the Joomla! CMS, a standalone web application or a CLI (command-line) application without much changes in the source code or, at least, reusing big portions of it. A mighty, noble goal. Is it possible? Are we there yet? Is it worth it?

Update, September 29th 2011: It is outright awesome that just two weeks after this blog post the Joomla! Platform included full support for easy creation of web applications without going through the pains described below. Kudos to Louis Landry for making it happen. It's all documented in the wiki, too! Moreover, there is a lot of brainstorming going on on the framework list –and I bet off-list, too– about decoupling Joomla!'s MVC implementation from the CMS. Needless to say, I might have to adjust my predictions of a truly usable platform by 6-12 months, placing it somewhere between mid-2012 and early 2013. Boy, Joomla! rocks!

Special thanks

Determined to answer all those hard questions myself, I began writing an example application. Before I begin detailing what I found, I’d like to thank two key people to this effort. Major kudos to Ryan Ozimek, OSM’s president, for getting me in the right mood to do it during Joomla! Day Chicago 2011. Some major kudos also go to Louis Landry whose coaching during the Joomla! Platform session at Joomla! Day Chicago 2011 made possible to get my first Joomla! Platform application work. Without their help I wouldn’t have made the first few baby steps and I wouldn’t be writing this blog post :)

Mind the sharks

In my example application –which is available for forking on GitHub– I made some choices, or you could say I placed some objectives. First, I wanted to use MVC. After all, that’s Joomla! Platform’s major strength and what separates Joomla! to other popular PHP-based CMS. Next, I wanted to make something which could run as a CLI application and as a web application. I wanted to keep my code as DRY as possible, that is reuse instead of copy and paste. Finally, I wanted the whole thing to run outside of Joomla!. Mission impossible? Well, yeah, but that’s my favorite kind of challenge!

The first thing I observed is that the MVC classes are tightly coupled to the assumption that everything runs on the web and that there is a database available. I had to provide class overrides to work around the latter and pass a fake object to overcome the latter. It’s not very pretty, but it works. I expect that as work on JInput progresses and the MVC classes are slowly starting to become HMVC capable this will be a thing of the past. But, right now, you have to bear with that if you want to use MVC in your CLI application.

When you try to build a web application, things are even worse. The whole web application idea is tightly coupled to the Joomla! CMS. It supposes that there are only three possible applications (front-end, back-end, installation) and expects certain files to be in certain paths. The whole templating logic is hard-coded inside the application classes. This makes it impossible to use MVC in a web application. At least not without having to copy a gazillion lines of cryptic code, full of cruft dating from the Mambo era, carefully edited to hard-code your one and only template. Moreover, you can’t even get away without having a templates folder with a system folder inside it, otherwise your error messages will result in cryptic “infinite loop” errors.

Now that I mentioned that, when you try to create a web application you will be disappointed at first, as you’ll be getting “infinite loop” errors. You will need a small workaround. See my code for details. Then, all error messages appear as untranslated strings. So you have to copy files from the language directory of Joomla! CMS and, in fact, keep the directory structure as the Joomla! CMS has it. Huh!

There are a lot of sharks in the journey of building a web application with the Joomla! Platform. You have to keep a keen eye or they’ll bite you to tiny pieces!

So, is it worth it?

Building a web application with the Joomla! Platform, without using the full Joomla! CMS is –at this point in time– tragically lacking. On the developers’ defense, they have never gotten to build a proper JWeb class for web applications, so we do have to use everything which was build exclusively for use of the Joomla! CMS. Therefore, the tight coupling to the Joomla! CMS is to be expected.

Building a CLI application is smooth as silk. Well, OK, the MVC classes are not readily usable by a CLI application but, then again, they were designed for web applications. Even the MVC model being used does not represent what you’d ideally need in an interactive application which runs in a continuous loop. The very fact that I had to make two or three minor changes means nothing bad. I expected things to be worse.

Overall, the feeling I get from the Joomla! Platform is that it is a very promising project but it’s not ready for mass use from developers yet. It’s a very young project, split off from a CMS with nearly a decade of history behind it. I wouldn’t expect anything stable and particularly usable before mid-2013 at the earliest. That said, it is a very stable platform to create CLI applications which can be used to automate all the administrative drudgery on your Joomla! sites and even do data processing and automation tasks on your own computer. If I had to sum it all up in a small sentence I’d say this: “There’s a lot of potential to the Joomla! Platform, but it’s not ‘there’ yet”.

No comments