Wednesday, March 7, 2007

Sypheon 2: Object-oriented

I once wrote a piece of software called Sypheon, which I used to manage the websites I created. Sypheon is a powerful XML content system that is based on an XML format that describes a page as a set of "blocks" which are arbitrarily placed into an XHTML "template".

When I originally wrote it, PHP's object oriented features were premature and limited, so I wrote it as a procedural application, making little use of modern OO structures. I decided to rewrite it recently as an object-oriented PHP application, which would also let me clean up the architecture a bit (procedural PHP is *really* hard to keep clean and tidy).

Another thing I wanted to address was the frequent use of "dynamic tags" in the older version. "Dynamic tags" are a way to allow both data blocks from pages and templates to insert dynamic information. This was the main way to express to Sypheon that a certain block should be inserted at a certain point in a template. The syntax, however, was extremely limited. Also, due to the way the files were processed, normal PHP tags (IE, < ?php someFunc(); ?>) could not be used. Instead, there was a 'php' dynamic tag which would be used like this:





Special tricks were employed to allow the : character to be used in the PHP code, which was reserved as the argument delimiter for dynamic tags.

In the new Sypheon, everything is based on PHP itself, so instead of using dynamic tags one would use just the < ?php ?> stuff. A special class is exported (called XCS) before the preprocessing of pages and templates which interfaces with Sypheon to output certain information. So the call in the template to show the "title" block at a certain point would be:





Much cleaner. Well, today Sypheon2 generated the first correct page, which is a Hello World of sorts, and the code is furiously smaller than the first incarnation. Next up is implementing the editing and page caching features of the old version. This time it will be easy. And elegant.

Signing off!