jelix/jelix — pull request #92 by brice-t (2012-10-14 21:08:29+00:00)
Title: Solving a bug with metas for cached zones

This is related to Trac bug #1197.

This patch introduces unit test for zone cache. Among those tests, 2 of them did not pass without the bugfixe also included :
* jzone.cache.html.php -> UTjzonecache -> testCacheMetaParam -> Second cached zone get - meta
* jzone.cache.html.php -> UTjzonecache -> testCacheMetaDeep -> Second cached zone get - "deep" meta

The first one tests the use of a variable used in a template for a meta while this template is a zone template and the variable is defined in the zone code. When cache is used, the value was not given to the response (and we had a warning - may be a notice, don't remember).

The second tests a string value of the meta, but now we have (zA & zB are zones, tB a template) :
zA (cached) calls zB (not cached, but not relevant) calling tB which has a meta
The meta is not given to the response when cache is used (i.e. at least on second shot).

To solve this bug, the method I used heavily uses PHP magic methods. I added a class (jMethodSniffer) which acts as a messager for method calls while "logging" those calls. It can then output a string which will repeat those method calls when executed.
So this string is cached and its content is executed when cache is used.

So in this case, the method is used as a messager for the response.
This is a little hacky, but ends with almost no change in the APIs and meta handling (just the title meta handling is changed, because jMethodSniffer can only log methods, not changes on an attribute).