The new development version will not be compatible with the previous ones when it comes to the programming interface. To implement the output cache system, I had to rebuild almost all of the output system. In the 1.x.x series, the concept of the output system did not exist. Either the result will be seen on the screen or put into a variable, it depended on the right method choice. There were some tricky connections which redirected everything to the right place, however it was not well designed and a bit messy. Well, such things simply must happen, if we start with keeping the similarities to Smarty, and I have to remind that in the very early times, it was one of the OPT goals. In OPTv2, there is a well-declared ioptOutput interface allowing the programmer to code the output processing on his own. It is also used in the implementation of output cache system. How - it is explained below.

So far, there have been two output systems: optNetOutput sending everything on the screen and checking, how many templates we are going to send in the XML mode. The second one was optReturnOutput, which returned the result. I added a possibility to decorate them with something else and I created optCachedOutput. Its only goal is to process the cache. The features are the same as in the previous versions, but the usage is a bit different and unfortunately, the initialization is more complicated:

$cache = new optCachedOutput('./cache/'); // this is the cache, here we configure it
$tpl -> register(OPT_OUTPUT, 'my_cache', $cache);
$tpl -> decorate(OPT_OUT_SCREEN, 'my_cache');
$tpl -> decorate(OPT_OUT_RETURN, 'my_cache');

if(!$cache -> isCached('template.tpl', 'some_id'))
{
  // data generation
}

$cache -> setCache(5, 'some_id'); // turn the cache on for 5 seconds
$tpl -> parse('template.tpl', 'my_cache');

I'll try to shorten it and make simpler the first lines of the code, because I don't like them, too. Moreover, I must check if I've made the decoration in the right way (according to the logic).

The support for plugins is not fully completed yet. The only ready part is placed in opt.class.php file. The rest is moved somewhere else, which should improve the performance. Like in OPT 1.1.3, there will be a possibility to set many plugin directories, but the parser will not require them to be writeable. There were thrown some files describing the content and allowing to include everything without scanning all the directory. As we know, the more includes, the less performance and some people can produce more plugins than all the files in my framework :). The new OPT will try to link all these files into one, mega-file containing everything we need. By the way, I'll have also a new algorithm for the OPT Toolset sequel, which will be used now for all the libraries, not only OPT.

The last issue concerns the available function set for the templates. Stormfly has recently written on his blog that OPT 1.1.x it was quite senseless and in fact, he was right. I took a look, what Smarty offers and it turned out that it has some nice and useful functions. The first list looks like that:

  1. spacify - puts a string between every two neighbour characters in the text.
  2. indent - makes an indentation in the text.
  3. truncate - reduces the text to the specified length (allowing not to splitting the words)
  4. strip - reduces all the white character groups to a single character
  5. capitalize - equivalent to ucfirst()
  6. upper - equivalent to strtoupper()
  7. lower - equivalent to strtolower()
  8. countWords - equivalent to str_word_count()
  9. countChars - equivalent to strlen()
  10. money - equivalent to money_format(), but the settings can be written in the OPT configuration.
  11. number - equivalent to number_format(), but the settings can be written in the OPT configuration.
  12. wordWrap - equivalent to word_wrap()
  13. replace - equivalent to str_replace()
  14. regexReplace - equivalent to preg_replace(), but the parameter order is changed.
  15. date - equivalent to date() :)
  16. firstof - returns the first non-empty element from the specified ones.
  17. nl2br - equivalent to nl2br() :)
  18. array - creating arrays on the template side
  19. build - it was called "apply()" in the previous versions, but I still don't know, whether I keep this name or not.

The set contains no escaping functions, because the compiler is able to put them on his own in most of the places. There will be a possibility to escape something manually, but it won't be done through functions. Anyway, the point is the compiler must know, what is escaped. Otherwise it may add additional function call and this would produce a complete mess on the screen.

To sum up, I've written so much functionality that I haven't tested all of them yet. I don't know if something works, however I don't expect any revelations. Many of the algorithms are reimplementations of the same code from OPT 1.1.x. The next dev version will be available in the nearest days.

Some statistics for the end:

- opt.class.php - 24 KB and still growing. In OPT 1.1.x, this file was 8 KB bigger, but offered less functionality.
- opt.compiler.php - 65 KB and still growing.
- opt.instructions.php - 25 KB and still growing.