Configuration Factory and Template Lite refactoring

Refactoring Back Story

After trying to rewrite Template Lite and messing around with the configuration class, I kept asking myself why couldn’t I use XML instead and use the PHP 5 XML classes. The reason is that I have to maintain some compatiablity between Template Lite, Smarty, and my changes. I came to the conclusion that if I’m going to need to use XML and the configuration of Template Lite and Smarty, then I should instead update my configuration class and use it instead.

Configuration Support

  1. SQLite

MySQL won’t ever be supported because it would be impossible to store mysql database connection information in the mysql database.

SQLite was the first configuration type and I love working with it. I started with the code base from the www.php.net comments for the type and I have been extending it ever since. It has since grown to be more than a single class and allow for a lot more than regular name, value pair.

I’m going to be adding:

  • Restrictions
  • Unlimited Subsections
  • Support for nonunique names to be collected in an array, removing the restriction that names be unique in the given section and subsections (currently uses unique name, value pair).

Which may not seem like much but it will require a great deal of rewriting of the code to support those two features. Even adding Sections was a lot of work and the ability of subsections will allow restrictions to be created.

I already have the syntax and how it will work figured out. I just have to finish coding it. I’ll probably code it first since I can test it out using my same code and I don’t think it will all that difficult to do.

  1. XML

It will work a lot like the SQLite database configuration, including the following features.

  • Section and Unlimited Subsection Support
  • Restrictions
  • Single and support for multiple names (just like in SQLite configuration support)

It will closely resemble the SQLite configuration feature set and should be simple to implement compared to SQLite. Access will be the same as for SQLite also, so the difference will be only in the file type and conversion between the two will be easy.

I’ll probably work on this next as I want to test the creation and the ability to get XML DOM classes to work the way I want it to add and get the name value pairs. Testing will have to be in depth to get this fully working without any major bugs. It would be really neat feature to have, extra bonus if it functions like SQLite.

  1. Plain Text

Also known as INI settings, but it will work with the configuration of Smarty and Template Lite, so it would be possible to replace the Template configuration class with my own. The only issue is that I’m going to have to parse it using my own method instead of ripping off either Template Lite or Smarty. I’m certain I can get the parsing done correctly.

Support is only for sections and name, value pairs. Restrictions and subsections won’t be supported. I’m sure I could find some way to implement them, but I don’t see the point of trying as they still would not work with the configuration of Smarty or Template Lite.

Conversions between SQLite and XML would most likely drop the restrictions and flatten the sections and subsections, so that all of the subsections would become plain sections.

Other Configuration Features

There will be an file creation methods for creating the ini and xml files. It will also test for proper file permissions and change them if they aren’t given. It would also correct file permissions to keep the files from viewed in the browser but still be viewed by the configuration factory. This security measure would keep prying eyes out of the sensitive Database settings, at least for *nix systems. Windows users would have to locate the file outside of the web directory.

Template Factory

I’m going to be building a Template Factory that implements three template features.

  1. Quick Template for using php tags as well as php variables and assigning them values.
  2. XML/XSL Template for transforming XML tags and assigning them values. Would use more of XML techniques than XSL.
  3. Back Support for Smarty and Template Lite. The Template Lite classes would be updated to work with PHP 5 native class features and other PHP 5 features.

Overall giving the developer the ability to choose would increase the options and difficultly, but offer the choice of the best template to the developer to work with. At the very least, the Quick Template should be used since it ties in to what most people do now anyway.

How Much Time?

The template work is taking a great deal of time and I’m working and testing it between working on the Security features, database features, and Configuration features. I’m tweaking here and there finding a feel for how it works completely, so that I can better update it for PHP 5.

Possibly Related Posts:


Comments are closed.